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,