프로젝트의 확장 된 속성
Microsoft Project에는 광범위한 XML 데이터 교환 스키마가있어 응용 프로그램과 프로젝트 파일을 사용한 프로그래밍간에 정보를 교환 할 수 있습니다. 스키마를 사용하면 작업, 리소스 및 할당에 확장 된 속성을 추가 할 수 있습니다. 이 기사는 Aspose.Tasks 를 사용하여 확장 된 속성으로 작업하는 방법을 보여줍니다.
Microsoft Project를 사용하여 사용자 정의 필드 작업
이 예에서는 정보를 작업과 연결하기위한 프로젝트의 Text1 확장 속성으로 작업하는 방법을 보여줍니다.
- MSP에서는 프로젝트-> 사용자 정의 필드로 이동하십시오.
- 여기에서 작업을 선택하십시오.
- 유형 콤보 상자에서 사용자 정의 필드 유형으로 텍스트를 선택하십시오.
- 작업하려는 사용자 정의 필드로 Text1을 선택하십시오.
- “이름 바꾸기"버튼을 사용하여 필드의 별칭 이름을 원하는 경우 필드의 이름을 바꾸고 확인 버튼을 누릅니다.
- 새 작업을 추가하고 위의 단계에서 사용한 사용자 지정 필드로 작업 행에 새 열을 삽입하십시오.
C ++ API를위한 Aspose.Tasks 를 사용하여 사용자 정의 필드/확장 된 속성 작업
ASPOSE.TASK 용 C ++ API는 새로운 확장 된 속성을 생성 할 수있을뿐만 아니라 문서에 이미 존재하는 확장 된 속성으로 작업 할 수있는 기능을 제공합니다. 사용자 정의 필드 또는 확장 된 속성은 Aspose.Tasks 의 프로젝트의 확장 Attibutes 컬렉션으로 표시됩니다. 프로젝트 문서의 모든 확장 된 속성 정의가 포함되어 있습니다. MSP 사용자 정의 필드 정의의 일부 매핑은 아래 이미지에 표시된 것과 같습니다.
새로운 확장 된 속성 생성 및 작업에 추가
작업 또는 리소스에 대한 새 확장 된 속성을 추가하려면 먼저 확장 Attributes 컬렉션에 확장 속성 정의를 정의하고 추가해야합니다. ExtendedAttributedEfinition 클래스는 프로젝트에서 새로운 확장 정보를 정의하는 데 사용됩니다. FieldID는 ExtendedTattributeTask (작업의 경우) 또는 ExtendedAttributerSource (리소스의 경우)에 연결된 확장 된 속성을 올바르게 정의하도록 설정해야합니다. 다음 샘플 코드는 Text1 Project 필드에 대한 새로운 확장 속성을 정의하는 방법을 보여줍니다. 확장 속성 정의가 완료되면 이제 새 확장 속성을 만들어 작업에 할당 할 수 있습니다.
1System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Blank2010.mpp");
2
3System::SharedPtr<ExtendedAttributeDefinition> myTextAttributeDefinition = project1->get_ExtendedAttributes()->GetById((int32_t)Aspose::Tasks::ExtendedAttributeTask::Text1);
4
5// If the Custom field doesn't exist in Project, create it
6if (myTextAttributeDefinition == nullptr)
7{
8 myTextAttributeDefinition = ExtendedAttributeDefinition::CreateTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Text1, u"My text field");
9 project1->get_ExtendedAttributes()->Add(myTextAttributeDefinition);
10}
11
12// Generate Extended Attribute from definition
13System::SharedPtr<ExtendedAttribute> text1TaskAttribute = myTextAttributeDefinition->CreateExtendedAttribute();
14
15text1TaskAttribute->set_TextValue(u"Text attribute value");
16
17// Add extended attribute to task
18System::SharedPtr<Task> tsk = project1->get_RootTask()->get_Children()->Add(u"Task 1");
19tsk->get_ExtendedAttributes()->Add(text1TaskAttribute);
20
21project1->Save(dataDir + u"CreateExtendedAttributes_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Writing Updated Extended Attribute Definitions and Values to MPP
Aspose.Tasks for C++ API supports updating extended attribute data in a Microsoft Project MPP file and save it back.
The code example given below demonstrates how to add new extended attributes of the Resource and Task types to the source MPP file. The steps involved in this activity are:
- Create an instance of Project Reader.
- Read the source MPP file.
- Define a new extended attribute and update its values.
- Save the project using the Project Writer.
The following example shows setting the extended attributes of a resource.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"WriteUpdatedExtendedAttributeDefinitions.mpp");
2
3
4// C# preprocessor directive: #region task attributes
5
6
7// Add new text3 extended attribute with lookup and one lookup value
8System::SharedPtr<ExtendedAttributeDefinition> taskTextAttributeDefinition = ExtendedAttributeDefinition::CreateLookupTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Text3, u"New text3 attribute");
9taskTextAttributeDefinition->set_ElementType(Aspose::Tasks::ElementType::Task);
10project->get_ExtendedAttributes()->Add(taskTextAttributeDefinition);
11
12System::SharedPtr<Value> textVal = System::MakeObject<Value>();
13textVal->set_Id(1);
14textVal->set_Description(u"Text value descr");
15textVal->set_Val(u"Text value1");
16
17taskTextAttributeDefinition->AddLookupValue(textVal);
18
19// Add new cost1 extended attribute with lookup and two cost values
20System::SharedPtr<ExtendedAttributeDefinition> taskCostAttributeDefinition = ExtendedAttributeDefinition::CreateLookupTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Cost1, u"New cost1 attribute");
21project->get_ExtendedAttributes()->Add(taskCostAttributeDefinition);
22
23System::SharedPtr<Value> costVal1 = System::MakeObject<Value>();
24costVal1->set_Id(2);
25costVal1->set_Description(u"Cost value 1 descr");
26costVal1->set_Val(u"99900");
27
28System::SharedPtr<Value> costVal2 = System::MakeObject<Value>();
29costVal2->set_Id(3);
30costVal2->set_Description(u"Cost value 2 descr");
31costVal2->set_Val(u"11100");
32
33taskCostAttributeDefinition->AddLookupValue(costVal1);
34taskCostAttributeDefinition->AddLookupValue(costVal2);
35
36// Add new task and assign attribute lookup value.
37System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"New task");
38
39System::SharedPtr<ExtendedAttribute> taskAttr = taskCostAttributeDefinition->CreateExtendedAttribute(costVal1);
40task->get_ExtendedAttributes()->Add(taskAttr);
41
42System::SharedPtr<ExtendedAttributeDefinition> taskStartAttributeDefinition = ExtendedAttributeDefinition::CreateLookupTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Start7, u"New start 7 attribute");
43
44System::SharedPtr<Value> startVal = System::MakeObject<Value>();
45startVal->set_Id(4);
46startVal->set_DateTimeValue(System::DateTime::get_Now());
47startVal->set_Description(u"Start 7 value description");
48
49taskStartAttributeDefinition->AddLookupValue(startVal);
50
51project->get_ExtendedAttributes()->Add(taskStartAttributeDefinition);
52
53System::SharedPtr<ExtendedAttributeDefinition> taskFinishAttributeDefinition = ExtendedAttributeDefinition::CreateLookupTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Finish4, u"New finish 4 attribute");
54
55System::SharedPtr<Value> finishVal = System::MakeObject<Value>();
56finishVal->set_Id(5);
57finishVal->set_DateTimeValue(System::DateTime::get_Now());
58finishVal->set_Description(u"Finish 4 value description");
59
60taskFinishAttributeDefinition->get_ValueList()->Add(finishVal);
61
62project->get_ExtendedAttributes()->Add(taskFinishAttributeDefinition);
63
64System::SharedPtr<ExtendedAttributeDefinition> numberAttributeDefinition = ExtendedAttributeDefinition::CreateLookupTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Number20, u"New number attribute");
65
66System::SharedPtr<Value> val1 = System::MakeObject<Value>();
67val1->set_Id(6);
68val1->set_Val(u"1");
69val1->set_Description(u"Number 1 value");
70System::SharedPtr<Value> val2 = System::MakeObject<Value>();
71val2->set_Id(7);
72val2->set_Val(u"2");
73val2->set_Description(u"Number 2 value");
74System::SharedPtr<Value> val3 = System::MakeObject<Value>();
75val2->set_Id(8);
76val3->set_Val(u"3");
77val3->set_Description(u"Number 3 value");
78
79numberAttributeDefinition->AddLookupValue(val1);
80numberAttributeDefinition->AddLookupValue(val2);
81numberAttributeDefinition->AddLookupValue(val3);
82
83project->get_ExtendedAttributes()->Add(numberAttributeDefinition);
84
85
86// C# preprocessor directive: #endregion
87
88
89System::SharedPtr<ExtendedAttributeDefinition> rscStartAttributeDefinition = ExtendedAttributeDefinition::CreateLookupResourceDefinition(Aspose::Tasks::ExtendedAttributeResource::Start5, u"New start5 attribute");
90
91System::SharedPtr<Value> startVal2 = System::MakeObject<Value>();
92startVal2->set_Id(9);
93startVal2->set_DateTimeValue(System::DateTime::get_Now());
94startVal2->set_Description(u"this is start5 value descr");
95
96rscStartAttributeDefinition->AddLookupValue(startVal2);
97
98project->get_ExtendedAttributes()->Add(rscStartAttributeDefinition);
99
100// Define a duration attribute without lookup.
101System::SharedPtr<ExtendedAttributeDefinition> taskDurationAttributeDefinition = ExtendedAttributeDefinition::CreateTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Duration1, u"New Duration");
102project->get_ExtendedAttributes()->Add(taskDurationAttributeDefinition);
103
104// Add new task and assign duration value to the previously defined duration attribute.
105System::SharedPtr<Task> timeTask = project->get_RootTask()->get_Children()->Add(u"New task");
106
107System::SharedPtr<ExtendedAttribute> durationExtendedAttribute = taskDurationAttributeDefinition->CreateExtendedAttribute();
108
109durationExtendedAttribute->set_DurationValue(project->GetDuration(3.0, Aspose::Tasks::TimeUnitType::Hour));
110timeTask->get_ExtendedAttributes()->Add(durationExtendedAttribute);
111
112System::SharedPtr<MPPSaveOptions> mppSaveOptions = System::MakeObject<MPPSaveOptions>();
113mppSaveOptions->set_WriteViewData(true);
114
115// Save the project as MPP project file
116project->Save(dataDir + u"WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);