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