Características de utilidad en Aspose.Tasks para C ++
Calcule la ruta crítica
La ruta crítica son las tareas, o tareas, que finalmente determinan cuándo terminará su proyecto. Hacer un seguimiento de la ruta crítica y los recursos que se les asignaron ayuda a mantener el proyecto a tiempo. El Proyecto de Microsoft calcula la ruta crítica en función de las tareas que no tienen holgura, tienen restricciones de fecha específicas (debe comenzar, debe terminar, lo antes posible o lo más tarde posible) o tener la misma fecha, o posterior, la fecha de finalización como el proyecto. Aspose.Tasks le permite calcular la ruta crítica.
La clase de proyecto proporciona la propiedad CriticalPath que se utiliza para recuperar la recopilación de tareas que comprenden la ruta crítica del proyecto. La siguiente pieza de código calcula y muestra las tareas en la ruta crítica.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CalculateCriticalPath.mpp");
2project->set_CalculationMode(Aspose::Tasks::CalculationMode::Automatic);
3
4System::SharedPtr<Task> subtask1 = project->get_RootTask()->get_Children()->Add(u"1");
5System::SharedPtr<Task> subtask2 = project->get_RootTask()->get_Children()->Add(u"2");
6System::SharedPtr<Task> subtask3 = project->get_RootTask()->get_Children()->Add(u"3");
7project->get_TaskLinks()->Add(subtask1, subtask2, Aspose::Tasks::TaskLinkType::FinishToStart);
8
9// Display the critical path now
10
11{
12 auto task_enumerator = (project->get_CriticalPath())->GetEnumerator();
13 decltype(task_enumerator->get_Current()) task;
14 while (task_enumerator->MoveNext() && (task = task_enumerator->get_Current(), true))
15 {
16 System::Console::WriteLine(task->Get(Tsk::Name()));
17 }
18}
Printing the TaskWritingException
A project consists of a number of tasks and Aspose.Tasks for C++ API allows adding, removing and updating task information. If there’s a problem when writing tasks, use TasksWritingException to catch them.
Aspose.Tasks for C++ supports printing a message when there’s an exception in writing a task. This is done with TaskWritingException, in a similar way to how TaskReadingException is used.
The log message is contained in the public property TasksWritingException.LogText, as shown in the following code example.
1try
2{
3 System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"PrintTaskWritingException.mpp");
4 System::Console::Write(u"This example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
5 project->Save(dataDir + u"project_out.MPP", Aspose::Tasks::Saving::SaveFileFormat::MPP);
6}
7catch (TasksWritingException& ex)
8{
9 System::Console::WriteLine(ex->get_LogText());
10}
11catch (System::NotSupportedException& ex)
12{
13 System::Console::WriteLine(ex->get_Message() + u"\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
14}
15
Working with Filter Data from MPP Files
Aspose.Tasks allows developers to read information about filters applied to MPP file data. This article shows how to retrieve filter definition and filter criteria data from a Microsoft Project MPP file.
Reading Filter Definition Data
1// Instantiate project and access task filters
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReadFilterDefinitionData.mpp");
3System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Filter>>> taskFilters = project->get_TaskFilters()->ToList();
4System::Console::WriteLine(System::String(u"Task Filters Count: ") + taskFilters->get_Count());
5System::Console::WriteLine(System::String(u"All Tasks: ") + taskFilters->idx_get(0)->get_Name());
6System::Console::WriteLine(System::String(u"Task Item: ") + System::ObjectExt::ToString(taskFilters->idx_get(0)->get_FilterType()));
7System::Console::WriteLine(System::String(u"Task Filters Show In Menu: ") + taskFilters->idx_get(0)->get_ShowInMenu());
8System::Console::WriteLine(System::String(u"Task filter ShowRelatedSummaryRows: ") + taskFilters->idx_get(0)->get_ShowRelatedSummaryRows());
9
10// Access resource filters
11System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Filter>>> rscFilters = project->get_ResourceFilters()->ToList();
12System::Console::WriteLine(System::String(u"Project.ResourceFilters count: ") + rscFilters->get_Count());
13System::Console::WriteLine(System::String(u"Resource Filter Item Type: Item.ResourceType: ") + System::ObjectExt::ToString(rscFilters->idx_get(0)->get_FilterType()));
14System::Console::WriteLine(System::String(u"Resource filter ShowInMenu") + rscFilters->idx_get(0)->get_ShowInMenu());
15System::Console::WriteLine(System::String(u"Resource filter ShowRelatedSummaryRows: ") + rscFilters->idx_get(0)->get_ShowRelatedSummaryRows());
Reading Filter Criteria Data
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2003.mpp");
2
3System::SharedPtr<Filter> filter = project->get_TaskFilters()->ToList()->idx_get(1);
4System::Console::WriteLine(filter->get_Criteria()->get_CriteriaRows()->get_Count());
5System::Console::WriteLine(System::ObjectExt::ToString(filter->get_Criteria()->get_Operation()));
6
7System::SharedPtr<FilterCriteria> criteria1 = filter->get_Criteria()->get_CriteriaRows()->idx_get(0);
8System::Console::WriteLine(System::ObjectExt::ToString(criteria1->get_Test()));
9System::Console::WriteLine(System::ObjectExt::ToString(criteria1->get_Field()));
10System::Console::WriteLine(System::ObjectExt::ToString(criteria1->get_Values()[0]));
11
12System::SharedPtr<FilterCriteria> criteria2 = filter->get_Criteria()->get_CriteriaRows()->idx_get(1);
13System::Console::WriteLine(System::ObjectExt::ToString(criteria2->get_Operation()));
14System::Console::WriteLine(criteria2->get_CriteriaRows()->get_Count());
15
16System::SharedPtr<FilterCriteria> criteria21 = criteria2->get_CriteriaRows()->idx_get(0);
17System::Console::WriteLine(System::ObjectExt::ToString(criteria21->get_Test()));
18System::Console::WriteLine(System::ObjectExt::ToString(criteria21->get_Field()));
19System::Console::WriteLine(System::ObjectExt::ToString(criteria21->get_Values()[0]));
20
21System::SharedPtr<FilterCriteria> criteria22 = criteria2->get_CriteriaRows()->idx_get(1);
22System::Console::WriteLine(System::ObjectExt::ToString(criteria22->get_Test()));
23System::Console::WriteLine(System::ObjectExt::ToString(criteria22->get_Field()));
24System::Console::WriteLine(System::ObjectExt::ToString(criteria22->get_Values()[0]));
25System::Console::WriteLine(filter->get_Criteria());
Reading Group Definition Data
A Microsoft Project data file may contain data in groups. Aspose.Tasks provides the facility to read the group definition data as shown in the below example.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReadGroupDefinitionData.mpp");
2
3System::Console::WriteLine(System::String(u"Task Groups Count: ") + project->get_TaskGroups()->get_Count());
4System::SharedPtr<Group> taskGroup = project->get_TaskGroups()->ToList()->idx_get(1);
5System::Console::WriteLine(u"Group Name:", System::ObjectExt::Box<System::String>(taskGroup->get_Name()));
6System::Console::WriteLine(System::String(u"Group Criteria count: ") + taskGroup->get_GroupCriteria()->get_Count());
7System::Console::WriteLine(u"\n************* Retrieving Task Group's Criterion information *************");
8System::SharedPtr<GroupCriterion> criterion = taskGroup->get_GroupCriteria()->ToList()->idx_get(0);
9System::Console::WriteLine(System::String(u"Criterion Field: ") + System::ObjectExt::ToString(criterion->get_Field()));
10System::Console::WriteLine(System::String(u"Criterion GroupOn: ") + System::ObjectExt::ToString(criterion->get_GroupOn()));
11System::Console::WriteLine(System::String(u"Criterion Cell Color: ") + criterion->get_CellColor());
12System::Console::WriteLine(System::String(u"Criterion Pattern: ") + System::ObjectExt::ToString(criterion->get_Pattern()));
13
14if (taskGroup == criterion->get_ParentGroup())
15{
16 System::Console::WriteLine(u"Parent Group is equval to task Group.");
17}
18
19System::Console::WriteLine(u"\n*********** Retreivnig Criterion's Font Information ***********");
20System::Console::WriteLine(System::String(u"Font Name: ") + criterion->get_Font()->get_Name());
21System::Console::WriteLine(System::String(u"Font Size: ") + criterion->get_Font()->get_Size());
22System::Console::WriteLine(System::String(u"Font Style: ") + System::ObjectExt::ToString(criterion->get_Font()->get_Style()));
23System::Console::WriteLine(System::String(u"Ascending/Dscending: ") + criterion->get_Ascending());
Reading Table Data from MPP File
The Aspose.Tasks for C++ API supports reading table data from Microsoft Project data files. Project.Tables implements the ICollection interface to provide access to an MPP file’s table data. The feature is supported for all versions of Microsoft Project data files, including MPP 2003, 2007, 2010 and 2013.
The below example shows how to retrieve table data from a Microsoft Project MPP file. The values of table properties such as width, title, title alignment and data alignment are displayed here for demonstration.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReadTableData.mpp");
2
3// Access table
4System::SharedPtr<Table> task1 = project->get_Tables()->ToList()->idx_get(0);
5System::Console::WriteLine(System::String(u"Table Fields Count") + task1->get_TableFields()->get_Count());
6
7// Display all table fields information
8
9{
10 auto tableField_enumerator = (task1->get_TableFields())->GetEnumerator();
11 decltype(tableField_enumerator->get_Current()) tableField;
12 while (tableField_enumerator->MoveNext() && (tableField = tableField_enumerator->get_Current(), true))
13 {
14 System::Console::WriteLine(System::String(u"Field width: ") + tableField->get_Width());
15 System::Console::WriteLine(System::String(u"Field Title: ") + tableField->get_Title());
16 System::Console::WriteLine(System::String(u"Field Title Alignment: ") + System::ObjectExt::ToString(tableField->get_AlignTitle()));
17 System::Console::WriteLine(System::String(u"Field Align Data: ") + System::ObjectExt::ToString(tableField->get_AlignData()));
18 }
19}
Extracting Embedded Objects from Task or Review form
Microsoft Project data files (MPP/XML) may contain embedded objects such as documents, excel sheets, PDF, images etc. in Task or Resource views. Aspose.Tasks for C++ API provides the capability to extract these from a project’s Task or Resource view as shown in the below topics.
Extracting Embedded Objects
Embedded objects (those which were created from the file by selecting a file path) are packed into OLE Package inside MPP file. To extract the original file you can use Content and FullPath properties of an instance of the OleObject class.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ExtractEmbeddedObjects.mpp");
2System::SharedPtr<OleObject> ole = project->get_OleObjects()->ToList()->idx_get(0);
3
4// We have to check this property because it can be null if the embedded object was created inside the ms project application Or, alternatively, you can use this check: if (ole.FileFormat == "Package")
5if (!System::String::IsNullOrEmpty(ole->get_FullPath()))
6{
7 {
8 System::SharedPtr<System::IO::FileStream> fileStream = System::MakeObject<System::IO::FileStream>(dataDir, System::IO::FileMode::Create);
9 // Clearing resources under 'using' statement
10 System::Details::DisposeGuard<1> __dispose_guard_0({ fileStream});
11 // ------------------------------------------
12
13 try
14 {
15 fileStream->Write(ole->get_Content(), 0, ole->get_Content()->get_Length());
16 }
17 catch(...)
18 {
19 __dispose_guard_0.SetCurrentException(std::current_exception());
20 }
21 }
22}
Embedded objects which were created inside Microsoft Project application can be extracted this way:
1System::SharedPtr<System::Collections::Generic::IDictionary<System::String, System::String>> fileFormatExt = System::MakeObject<System::Collections::Generic::Dictionary<System::String, System::String>>();
2fileFormatExt->Add(u"RTF", u"_rtfFile_out.rtf");
3fileFormatExt->Add(u"MSWordDoc", u"_wordFile_out.docx");
4fileFormatExt->Add(u"ExcelML12", u"_excelFile_out.xlsx");
5
6System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Embedded.mpp");
7
8
9{
10 auto oleObject_enumerator = (project->get_OleObjects())->GetEnumerator();
11 decltype(oleObject_enumerator->get_Current()) oleObject;
12 while (oleObject_enumerator->MoveNext() && (oleObject = oleObject_enumerator->get_Current(), true))
13 {
14 if (!System::String::IsNullOrEmpty(oleObject->get_FileFormat()) && fileFormatExt->ContainsKey(oleObject->get_FileFormat()))
15 {
16 System::String path = dataDir + u"EmbeddedContent_" + fileFormatExt->idx_get(oleObject->get_FileFormat());
17 {
18 System::SharedPtr<System::IO::FileStream> fileStream = System::MakeObject<System::IO::FileStream>(path, System::IO::FileMode::Create);
19 // Clearing resources under 'using' statement
20 System::Details::DisposeGuard<1> __dispose_guard_0({ fileStream});
21 // ------------------------------------------
22
23 try
24 {
25 fileStream->Write(oleObject->get_Content(), 0, oleObject->get_Content()->get_Length());
26 }
27 catch(...)
28 {
29 __dispose_guard_0.SetCurrentException(std::current_exception());
30 }
31 }
32 }
33 }
34}