Free Support Forum - aspose.com

ResourceAssignment: Start, Finish and Duration


#21

Hi,

Any news?


#22

@FabioMartins

Thank you for writing back to us.

This issue has been resolved and will be a part of our next API release i.e. Aspose.Tasks for .NET 19.1 and it shall probably be available at the end of next week.


#23

Hello @MuzammilKhan,

I tested on 19.1 and the same problem occurs.

Please, could you help me?

How do I implement my code to generate the scenario described?

  • Task with two resource assignment, when finish first assignment, should start the next one.
  • Task 1 - Start - 2018/01/01 - Finish - 2018/03/23 - Duration - 60 days
  • Resource assignment 1 - Start - 2018/01/01 - Finish 2018/01/31
  • Resource assignment 2 - Start - 2018/02/01 - Finish 2018/03/23

#24

@FabioMartins

We are sorry for inconvenience.

Please give us some time to investigate this issue and we will update you soon.


#25

@FabioMartins

Please follow the code sample given below to get the desired result:

private void Test()
{
    Project project = new Project("template.mpp") { CalculationMode = CalculationMode.None };
    project.Set(Prj.StartDate, new DateTime(2018, 1, 1));

    if (project.Calendars.GetByName("Padrão") == null)
    {
            this.CreateCalendar(project);
    }

    Resource rsc1 = project.Resources.Add("Resource 1 (Work)");
    rsc1.Set(Rsc.Type, ResourceType.Work);
    rsc1.Set(Rsc.StandardRate, 1m);
    rsc1.Set(Rsc.Code, "2158");

    Resource rsc2 = project.Resources.Add("Resource 2 (Work)");
    rsc2.Set(Rsc.Type, ResourceType.Work);
    rsc2.Set(Rsc.StandardRate, 1m);
    rsc2.Set(Rsc.Code, "2159");

    Task tsk1 = project.RootTask.Children.Add("Task - 01");
    Task tsk2 = tsk1.Children.Add("Task - 01.01");
    Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
    tsk3.Set(Tsk.IsManual, false);
    tsk3.Set(Tsk.Start, new DateTime(2018, 1, 1, 9, 0, 0));
    tsk3.Set(Tsk.Duration, project.GetDuration(60, TimeUnitType.Day));
    tsk3.Set(Tsk.Type, TaskType.FixedDuration);
    tsk3.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
    tsk3.Set(Tsk.ConstraintDate, new DateTime(2018, 1, 1, 9, 0, 0));

    ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk3, rsc1);
    assignment1.Set(Asn.Start, new DateTime(2018, 1, 1, 9, 0, 0));
    assignment1.Set(Asn.Finish, new DateTime(2018, 1, 31, 18, 0, 0));
    assignment1.Set(Asn.Work, project.GetDuration(23, TimeUnitType.Day));

    ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk3, rsc2);
    assignment2.Set(Asn.Start, new DateTime(2018, 2, 1, 9, 0, 0));
    assignment2.Set(Asn.Finish, new DateTime(2018, 3, 23, 18, 0, 0));
    assignment2.Set(Asn.Work, project.GetDuration(37, TimeUnitType.Day));
    assignment2.Set(Asn.Delay, project.GetDuration(23, TimeUnitType.Day));

    project.Recalculate();
    project.RecalculateResourceFields();
    project.RecalculateResourceStartFinish();
}

private void CreateCalendar(Project project)
{
    var calendar = project.Calendars.Add("Padrão", project.Calendars.GetByName("Standard"));
    var workingTimes = new System.Collections.Generic.List<WorkingTime>
                           {
                               new WorkingTime { FromTime = new DateTime(1, 1, 1, 9, 0, 0), ToTime = new DateTime(1, 1, 1, 12, 0, 0) },
                               new WorkingTime { FromTime = new DateTime(1, 1, 1, 13, 0, 0), ToTime = new DateTime(1, 1, 1, 18, 0, 0) }
                           };
    calendar.WeekDays.Add(new WeekDay(DayType.Monday, workingTimes));
    calendar.WeekDays.Add(new WeekDay(DayType.Tuesday, workingTimes));
    calendar.WeekDays.Add(new WeekDay(DayType.Wednesday, workingTimes));
    calendar.WeekDays.Add(new WeekDay(DayType.Thursday, workingTimes));
    calendar.WeekDays.Add(new WeekDay(DayType.Friday, workingTimes));
    calendar.WeekDays.Add(new WeekDay(DayType.Saturday));
    calendar.WeekDays.Add(new WeekDay(DayType.Sunday));

    project.Set(Prj.Calendar, calendar);
}

Moreover, please share your feedback and feel free to write back to us if you need additional information.