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.


#26

Hi @alexanderefremov1, thanks for the feedback!

The code worked as intended !!!

But I had a new question, what should be done for material resources?

rsc2.Set(Rsc.Type, ResourceType.Material);

I got this result:result.png (13.7 KB)

using System;
using Aspose.Tasks;
using Aspose.Tasks.Saving;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
License license = new License();
license.SetLicense(“Aspose.Tasks.lic”);

        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)
        {
            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 (Material)");
        rsc2.Set(Rsc.Type, ResourceType.Material);
        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();

        project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
        project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
    }

    static 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);
    }
}

}

The above code is the same, however with the definition of the second resource as Material (rsc2.Set (Rsc.Type, ResourceType.Material)).


#27

@FabioMartins

We have logged this issue with ID “TASKSNET-2969” for further investigation. However, it is requested to kindly share desired output as well to get better idea.

Moreover, we will update you here once we have more information to share.


#28

It’s the same situation:
Task with two resource assignments, when you finish the first assignment, you must start the next assignment.

  • Task 1 - Start - 2018/01/01 - Conclusion - 2018/03/23 - Duration - 60 days
  • Allocation of resources 1 - Beginning - 2018/01/01 - Completion 2018/01/31
  • Allocation of resources 2 - Beginning - 2018/02/01 - Completion 2018/03/23

But the second resource is material.


#29

@FabioMartins

Thank you for your feedback. We have recorded the details and shall be considered for further investigation.


#30

Any news?

Tks,


#31

@FabioMartins

We are working on this issue and it is not resolved yet. We will update you here as soon as we have more information to share.


#32

Any news?

Tks,


#33

@FabioMartins

The issue under ID “TASKSNET-2969” is not resolved yet and we are working on this issue. We will update you as soon as it is resolved. We are hopeful that it will be resolved with upcoming release Aspose.Tasks for .NET 19.3.


#34

@FabioMartins Hello!

Please, try the next code to get the desired result (it works in Aspose.Tasks for .NET 19.2)

public void TASKSNET_2969()
{
    var lic = new License();
    lic.SetLicense("path_to_lic");
    Project project = new Project("template2016.mpp") { CalculationMode = CalculationMode.None };
    project.Set(Prj.StartDate, new DateTime(2018, 1, 1));

    if (project.Calendars.GetByName("Padrão") == null)
    {
        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 (Material)");
    rsc2.Set(Rsc.Type, ResourceType.Material);
    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));

    var 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(296, TimeUnitType.Hour));
    assignment2.Set(Asn.Units, 296); 
    assignment2.Set(Asn.Delay, project.GetDuration(23, TimeUnitType.Day));

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

    project.Save("TASKSNET_2969_out.mpp", SaveFileFormat.MPP);
}

The “template2016.mpp” is here template2016.zip (24.7 KB). It is the “template.mpp” but resaved in MSP 2016. The output generated by Aspose.Tasks is the same as generated by MS Project.