Read Task Timephased Data

Contents
[ Hide Show ]

In Microsoft Project, timephased data is displayed on the right side of the Task Usage and Resource Usage views. You can write this data manually and programmatically it can be written with Aspose.Tasks for C++ API or get it from a project into your application.

Working with Timephased Data

Aspose.Tasks for C++ API supports reading a task’s time-phased data from Microsoft Project (MPP) files. The time-phased data is retrieved using the Task object’s GetTimephasedData method.

The following piece of code shows how to read a task’s timephased data.

 1// Create project instance
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"ReadWriteTimephasedData.mpp");
 4    
 5// Set project properties
 6project1->Set(Prj::StartDate(), System::DateTime(2013, 10, 30, 9, 0, 0));
 7project1->Set<NullableBool>(Prj::NewTasksAreManual(), NullableBool::to_NullableBool(false));
 8    
 9// Add task and resources
10System::SharedPtr<Task> task = project1->get_RootTask()->get_Children()->Add(u"Task");
11System::SharedPtr<Resource> rsc = project1->get_Resources()->Add(u"Rsc");
12    
13// Set resource rates and task duration
14rsc->Set<System::Decimal>(Rsc::StandardRate(), static_cast<System::Decimal>(10));
15rsc->Set<System::Decimal>(Rsc::OvertimeRate(), static_cast<System::Decimal>(15));
16task->Set<Duration>(Tsk::Duration(), project1->GetDuration(6));
17    
18// Create resource assignment
19System::SharedPtr<ResourceAssignment> assn = project1->get_ResourceAssignments()->Add(task, rsc);
20assn->Set(Asn::Stop(), System::DateTime::MinValue);
21assn->Set(Asn::Resume(), System::DateTime::MinValue);
22    
23// Set Backloaded contour, it increases task duration from 6 to 10 days
24assn->Set<WorkContourType>(Asn::WorkContour(), Aspose::Tasks::WorkContourType::BackLoaded);
25    
26project1->SetBaseline(Aspose::Tasks::BaselineType::Baseline);
27task->Set<int32_t>(Tsk::PercentComplete(), 50);
28    
29// Read timephased data
30System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<TimephasedData>>> td = assn->GetTimephasedData(assn->Get<System::DateTime>(Asn::Start()), assn->Get<System::DateTime>(Asn::Finish()), Aspose::Tasks::TimephasedDataType::AssignmentRemainingWork)->ToList();
31System::Console::WriteLine(td->get_Count());
32    
33{
34    auto timePhasedValue_enumerator = (td)->GetEnumerator();
35    decltype(timePhasedValue_enumerator->get_Current()) timePhasedValue;
36    while (timePhasedValue_enumerator->MoveNext() && (timePhasedValue = timePhasedValue_enumerator->get_Current(), true))
37    {
38        System::Console::WriteLine(timePhasedValue->get_Value());
39    }
40}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.