How can i set custom values to TimephasedData in Aspose.Tasks 8.9.0.0

Hi,


The sample code to set custom values to TimephasedData in the thread: How can i set custom values to TimephasedData? is outdated.

Can you please provide an updated version for the sample code below, which is working with aspose.tasks for .net 8.9??

static public void Task_T2()
{
Project project = new Project();
project.StartDate = new DateTime(2014, 9, 24);
Resource person1 = project.AddResource(“Person 1”);
Aspose.Tasks.Task task1 = new Aspose.Tasks.Task(“Task 1”);
task1.Type = TaskType.FixedDuration;
task1.DurationFormat = TimeUnitType.Day;
ResourceAssignment assn1 = new ResourceAssignment(task1, person1);
assn1.WorkContour = WorkContourType.Contoured;
assn1.TimephasedData = new List();
TimephasedData td = new TimephasedData();
td.Start = new DateTime(2014, 9, 24, 8, 0, 0);
td.Finish = td.Start.AddDays(1);
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0));
assn1.TimephasedData.Add(td);

td = new TimephasedData();
td.Start = new DateTime(2014, 9, 25, 8, 0, 0);
td.Finish = td.Start.AddDays(1);
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
td.Value = TimeSpanToTDString(TimeSpan.FromHours(7));
assn1.TimephasedData.Add(td);

td = new TimephasedData();
td.Start = new DateTime(2014, 9, 26, 8, 0, 0);
td.Finish = td.Start.AddDays(1);
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
td.Value = TimeSpanToTDString(TimeSpan.FromHours(4));

assn1.TimephasedData.Add(td);

td = new TimephasedData();
td.Start = new DateTime(2014, 9, 29, 8, 0, 0);
td.Finish = td.Start.AddDays(1);
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0));
assn1.TimephasedData.Add(td);

td = new TimephasedData();
td.Start = new DateTime(2014, 9, 30, 8, 0, 0);
td.Finish = td.Start.AddHours(9);
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
td.Value = TimeSpanToTDString(TimeSpan.FromHours(6));
assn1.TimephasedData.Add(td);

td = new TimephasedData();
td.Start = new DateTime(2014, 10, 1, 8, 0, 0);
td.Finish = td.Start.AddHours(9);
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0));
assn1.TimephasedData.Add(td);

assn1.Work = new TimeSpan(17, 0, 0);
task1.Start = project.StartDate;
task1.Finish = td.Finish;
task1.Duration = project.Calendar.GetWorkingHours(task1.Start, task1.Finish).WorkingHours;

project.RootTask.Children.Add(task1);
project.ResourceAssignments.Add(assn1);

project.CalcResourceAssignmentIds();
project.CalcResourceAssignmentUids();
project.CalcTaskIds();
project.CalcTaskUids();
project.UpdateReferences();

project.Save(“saved.xml”, SaveFileFormat.XML);
}
static private string TimeSpanToTDString(TimeSpan timeSpan)
{
return string.Format(“PT{0}H{1}M{2}S)”, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
}

Hi Craig,


Please have a look at the following code sample that can be used with the new version of the API. In case of any difficulty, please feel free to write us back.

Code:



static public void Task_T2()

{

Project project = new Project();

project.Set(Prj.StartDate ,new DateTime(2014, 9, 24));

Resource person1 = project.Resources.Add(“Person 1”);

Aspose.Tasks.Task task1 = project.RootTask.Children.Add(“Task 1”);

task1.Set(Tsk.Type, TaskType.FixedDuration);

task1.Set(Tsk.DurationFormat, TimeUnitType.Day);

ResourceAssignment assn1 = project.ResourceAssignments.Add(task1, person1);

assn1.Set(Asn.WorkContour, WorkContourType.Contoured);


TimephasedData td = new TimephasedData();

td.Start = new DateTime(2014, 9, 24, 8, 0, 0);

td.Finish = td.Start.AddDays(1);

td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;

td.Value = TimeSpanToTDString(TimeSpan.FromHours(0));

assn1.TimephasedData.Add(td);


td = new TimephasedData();

td.Start = new DateTime(2014, 9, 25, 8, 0, 0);

td.Finish = td.Start.AddDays(1);

td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;

td.Value = TimeSpanToTDString(TimeSpan.FromHours(7));

assn1.TimephasedData.Add(td);


td = new TimephasedData();

td.Start = new DateTime(2014, 9, 26, 8, 0, 0);

td.Finish = td.Start.AddDays(1);

td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;

td.Value = TimeSpanToTDString(TimeSpan.FromHours(4));


assn1.TimephasedData.Add(td);


td = new TimephasedData();

td.Start = new DateTime(2014, 9, 29, 8, 0, 0);

td.Finish = td.Start.AddDays(1);

td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;

td.Value = TimeSpanToTDString(TimeSpan.FromHours(0));

assn1.TimephasedData.Add(td);


td = new TimephasedData();

td.Start = new DateTime(2014, 9, 30, 8, 0, 0);

td.Finish = td.Start.AddHours(9);

td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;

td.Value = TimeSpanToTDString(TimeSpan.FromHours(6));

assn1.TimephasedData.Add(td);


td = new TimephasedData();

td.Start = new DateTime(2014, 10, 1, 8, 0, 0);

td.Finish = td.Start.AddHours(9);

td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;

td.Value = TimeSpanToTDString(TimeSpan.FromHours(0));

assn1.TimephasedData.Add(td);


assn1.Set(Asn.Work , project.GetDuration(17, TimeUnitType.Hour));

task1.Set(Tsk.Start ,project.Get(Prj.StartDate));

task1.Set(Tsk.Finish ,td.Finish);

double hours = project.Get(Prj.Calendar).GetWorkingHours(task1.Get(Tsk.Start), task1.Get(Tsk.Finish)).WorkingHours.TotalHours;

task1.Set(Tsk.Duration , project.GetDuration(hours, TimeUnitType.Hour));

task1.Set(Tsk.Duration, project.GetDuration(project.Get(Prj.Calendar).GetWorkingHours(task1.Get(Tsk.Start), task1.Get(Tsk.Finish)).WorkingHours.Duration().Hours, TimeUnitType.Hour));


project.Save(“saved.xml”, SaveFileFormat.XML);

}

static private string TimeSpanToTDString(TimeSpan timeSpan)

{

return string.Format(“PT{0}H{1}M{2}S)”, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);

}

Hi Muhammad,

Thank you for your quick response.

We tried your code, but the exported xml does not contain any timephaseddata.

Attached is the result saved.xml

Are we missing something? Please have a look.

Regards,
Craig

Hi Craig,


Here the modified code is attached, which adds timephased data. If we set the task data like “Start Date” and “Finish Date” after adding timephased data, then it may reset the timephased data. Please give a try to the attached code and let us know the feedback.

Hi,

We tried your new code and would like to save it into mpp format, but the outcome losing the timephase data again.

Attached zip contains the blank mpp file we are using, can you please tell us what is going wrong?

Regards,
Craig

Hi Craig,


We were able to reproduce this issue at our end and have logged it as TASKS-34311 in our issue tracking system for further investigation by our Product team. We shall update you here once there is some information available about this problem.

Hi there, is there any update on our ticket TASKS-34311 please? This fix is holding up an entire software release for our product and is business critical to have resolved. Are you able to provide an ETA for an update or fix please?


I have tried to contact your offices and left voicemails, and waited on LiveChat for over 30 mins without a response so not sure how best to contact your Support Team. Is there a direct number we should call instead?

Thanks
Kathleen

Hi Kathleen,


We are sorry for the inconvenience caused to you.

The issue has been investigated in detail by our Product team and could not be fixed due to insufficient MPP file format specifications availability. We have marked it as a known issue and won’t be able to fix it in near future until the complete specifications are available to us.