Free Support Forum - aspose.com

How to use Task TimephasedData (C# .NET)

Hello, could you help me?

How to distribute the usage time (TimephasedData) of a task? (without resource)

I’ve tried this:

     static void Main(string[] args)
        {
            License license = new License();
            license.SetLicense("Aspose.Tasks.lic");

        Project project = new Project("Template.mpp");

        project.RootTask.Set(Tsk.IsCritical, false);

        //project.CalculationMode = CalculationMode.None;

        /*Begin Tasks*/
        Task tsk1 = project.RootTask.Children.Add("Task 1");
        tsk1.Set(Tsk.IsManual, true);
        tsk1.Set(Tsk.IsCritical, false );
        tsk1.Set(Tsk.ConstraintType, ConstraintType.AsSoonAsPossible );
        tsk1.Set(Tsk.Type, TaskType.FixedUnits);
        tsk1.Set(Tsk.Start, DateTime.ParseExact("2018-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk1.Set(Tsk.Duration, project.GetDuration(10, TimeUnitType.Day));
        tsk1.Set(Tsk.Work, tsk1.Get(Tsk.Duration));
        /*End Tasks*/

        ClearTimephasedData(tsk1);

        Calendar cal = project.Get(Prj.Calendar);

        var td = new TimephasedData();
        td.Start = new DateTime(2018, 1, 1, 9, 0, 0);
        td.Finish = cal.GetFinishDateByStartAndWork(td.Start, project.GetDuration(10, TimeUnitType.Hour));
        td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
        td.Value = TimeSpanToTDString(TimeSpan.FromHours(10));
        tsk1.TimephasedData.Add(td);

        td = new TimephasedData();
        td.Start = new DateTime(2018, 1, 2, 9, 0, 0);
        td.Finish = cal.GetFinishDateByStartAndWork(td.Start, project.GetDuration(6, TimeUnitType.Hour));
        td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
        td.Value = TimeSpanToTDString(TimeSpan.FromHours(6));
        tsk1.TimephasedData.Add(td);

        td = new TimephasedData();
        td.Start = new DateTime(2018, 1, 3, 9, 0, 0);
        td.Finish = cal.GetFinishDateByStartAndWork(td.Start, project.GetDuration(8, TimeUnitType.Hour));
        td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
        td.Value = TimeSpanToTDString(TimeSpan.FromHours(8));
        tsk1.TimephasedData.Add(td);

        td = new TimephasedData();
        td.Start = new DateTime(2018, 1, 4, 9, 0, 0);
        td.Finish = cal.GetFinishDateByStartAndWork(td.Start, project.GetDuration(8, TimeUnitType.Hour));
        td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
        td.Value = TimeSpanToTDString(TimeSpan.FromHours(8));
        tsk1.TimephasedData.Add(td);

        td = new TimephasedData();
        td.Start = new DateTime(2018, 1, 5, 9, 0, 0);
        td.Finish = cal.GetFinishDateByStartAndWork(td.Start, project.GetDuration(8, TimeUnitType.Hour));
        td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
        td.Value = TimeSpanToTDString(TimeSpan.FromHours(8));
        tsk1.TimephasedData.Add(td);

        project.CalcResourceFields();
        project.CalcResourceStartFinish();
        project.Recalculate();

        project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
        project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
    }
    static private string TimeSpanToTDString(TimeSpan timeSpan)
    {
        return string.Format("PT{0}D{1}H{2}M{3}S", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
    }

    static private void ClearTimephasedData(ResourceAssignment assignment)
    {
        foreach (TimephasedData tph in assignment.TimephasedData.ToList())
            assignment.TimephasedData.Remove(tph);
    }

    static private void ClearTimephasedData(Task task)
    {
        foreach (TimephasedData tph in task.TimephasedData.ToList())
            task.TimephasedData.Remove(tph);
    }

This was the expected result:
Correct1.png (121.4 KB)
Correct2.png (83.6 KB)

This was the return generated:
output1.png (85.2 KB)
output2.png (83.8 KB)

Attached the MPP and XML files:
Files_MPP_XML.zip (54.0 KB)

Tks,

@FabioMartins,

We are looking into this and will get back to you soon with our findings.

@FabioMartins,

We have observed the issue and logged under Id:TASKSNET-2587 in our issue tacking system for detailed analysis later. We will write back here as soon as some feedback is ready to share.

Hi any news?

@FabioMartins,

I regret to share that the issue is still unresolved. I request for your patience till the time the issue gets resolved. We request for your patience till the time the issue gets resolved.

The issues you have found earlier (filed as TASKSNET-2587) have been fixed in this update.