프로젝트의 Extended Attributes 작업하기
Microsoft Project는 확장 가능한 XML 데이터 스키마 이는 응용 프로그램 간의 원활한 데이터 교환을 가능하게 하고 프로젝트 정보를 사용자 지정할 수 있는 강력한 옵션을 제공합니다. 그중 가장 유연한 기능 중 하나는 Extended Attributes으로, 사용자가 작업, 자원 및 할당에 사용자 지정 필드를 추가할 수 있게 합니다. 이러한 사용자 지정 필드는 비용 코드, 위험 범주, 승인 상태 또는 조직에서 필요로 하는 기타 분류와 같은 비즈니스별 메타데이터를 저장하는 데 자주 사용됩니다. 이를 통해 Aspose.Tasks for .NET, 개발자는 프로그래밍 방식으로 Extended Attributes을 생성, 읽고, 업데이트하고 저장할 수 있습니다 Microsoft Project를 설치할 필요 없이 사용할 수 있습니다. 이를 통해 작업 흐름을 자동화하고 프로젝트 데이터를 사용자 지정 정보로 보강하며 Microsoft Project 파일을 기업 시스템에 통합할 수 있습니다.
Microsoft Project에서 Custom Fields 사용하기
이 예제에서는 프로젝트의 Text1 extended attribute 를 Task와 정보를 연관시키기 위해 사용하는 방법을 보여줍니다.
- MSP에서 Project → Custom Fields.
- 여기에서 Task.
- 선택합니다 Text 을 형식 콤보 상자에서 Custom Field Type으로 선택합니다.
- 선택합니다 Text1 를 작업하려는 사용자 지정 필드로 선택합니다.
- 필요하면 Rename 버튼을 사용하여 필드의 별칭을 변경하고, 그런 다음 OK.
- 새 작업을 추가하고 해당 작업 행에 사용자 지정 필드를 포함하는 새 열을 삽입합니다.
Aspose.Tasks for .NET을 사용하여 Custom Fields/Extended Attributes 작업하기
Aspose.Tasks for .NET API는 문서에 이미 존재하는 Extended Attributes를 처리하는 것뿐만 아니라 새로운 Extended Attributes를 생성할 수 있는 기능을 제공합니다. 사용자 지정 필드 또는 Extended Attributes는 Aspose.Tasks의 프로젝트에 있는 ExtendedAttributes 컬렉션으로 표현됩니다. 이 컬렉션은 프로젝트 문서의 모든 Extended Attributes 정의를 포함합니다. MSP Custom Field 정의의 일부 매핑은 아래 이미지와 같이 표시됩니다.
새 Extended Attribute 생성 및 Task에 추가하기
작업 또는 자원에 대한 새 Extended Attribute를 추가하려면 먼저 ExtendedAttributes 컬렉션에 Extended Attribute 정의를 생성하고 추가해야 합니다. ExtendedAttributeDefinition 클래스는 프로젝트에서 새로운 ExtendedAttribute를 정의하는 데 사용됩니다. Extended attribute를 올바르게 정의하려면 FieldId를 설정해야 하며, 이는 ExtendedAttributeTask (Task의 경우) 또는 ExtendedAttributeResource (Resource의 경우). 다음 샘플 코드는 프로젝트의 Text1 필드에 대한 새로운 Extended Attribute를 정의하는 방법을 보여줍니다. Extended Attribute 정의가 완료되면 해당 정의로부터 새로운 Extended Attribute를 생성하여 작업에 할당할 수 있습니다.
1Project project = new Project("New Project.mpp");
2
3ExtendedAttributeDefinition myTextAttributeDefinition = project.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Text1);
4
5// If the Custom field doesn't exist in Project, create it
6if (myTextAttributeDefinition == null)
7{
8 myTextAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My text field");
9 project.ExtendedAttributes.Add(myTextAttributeDefinition);
10}
11
12// Generate Extended Attribute from definition
13ExtendedAttribute text1TaskAttribute = myTextAttributeDefinition.CreateExtendedAttribute();
14
15text1TaskAttribute.TextValue = "Text attribute value";
16
17// Add extended attribute to task
18Task task = project.RootTask.Children.Add("Task 1");
19task.ExtendedAttributes.Add(text1TaskAttribute);
20
21project.Save("CreateExtendedAttributes_out.mpp", SaveFileFormat.MPP);
업데이트된 Extended Attribute 정의 및 값을 MPP에 쓰기
Aspose.Tasks for .NET은 Microsoft Project MPP 파일의 extended attribute 데이터를 업데이트하고 다시 저장하는 것을 지원합니다.
아래 예제 코드는 소스 MPP 파일에 다음 유형의 새 extended attributes를 추가합니다: Resource 및 Task 유형을 소스 MPP 파일에 추가합니다. 이 작업에 포함된 단계는 다음과 같습니다:
- 다음 인스턴스를 생성합니다: Project Reader.
- 소스 MPP 파일을 로드합니다.
- 새 extended attribute를 정의하고 그 값을 업데이트합니다.
- 프로젝트를 다음을 사용하여 저장합니다: Project Writer.
다음 예제는 자원의 extended attributes 설정 방법을 보여줍니다.
1Project project = new Project("New Project.mpp");
2
3// Add new text3 extended attribute with lookup and one lookup value
4ExtendedAttributeDefinition taskTextAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Text3, "New text3 attribute");
5taskTextAttributeDefinition.ElementType = ElementType.Task;
6project.ExtendedAttributes.Add(taskTextAttributeDefinition);
7
8Value textVal = new Value();
9textVal.Id = 1;
10textVal.Description = "Text value descr";
11textVal.Val = "Text value1";
12
13taskTextAttributeDefinition.AddLookupValue(textVal);
14
15// Add new cost1 extended attribute with lookup and two cost values
16ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Cost1, "New cost1 attribute");
17project.ExtendedAttributes.Add(taskCostAttributeDefinition);
18
19Value costVal1 = new Value();
20costVal1.Id = 2;
21costVal1.Description = "Cost value 1 descr";
22costVal1.Val = "99900";
23
24Value costVal2 = new Value();
25costVal2.Id = 3;
26costVal2.Description = "Cost value 2 descr";
27costVal2.Val = "11100";
28
29taskCostAttributeDefinition.AddLookupValue(costVal1);
30taskCostAttributeDefinition.AddLookupValue(costVal2);
31
32// Add new task and assign attribute lookup value.
33Task task = project.RootTask.Children.Add("New task");
34
35ExtendedAttribute taskAttr = taskCostAttributeDefinition.CreateExtendedAttribute(costVal1);
36task.ExtendedAttributes.Add(taskAttr);
37
38ExtendedAttributeDefinition taskStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Start7, "New start 7 attribute");
39
40Value startVal = new Value();
41startVal.Id = 4;
42startVal.DateTimeValue = DateTime.Now;
43startVal.Description = "Start 7 value description";
44
45taskStartAttributeDefinition.AddLookupValue(startVal);
46
47project.ExtendedAttributes.Add(taskStartAttributeDefinition);
48
49ExtendedAttributeDefinition taskFinishAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Finish4, "New finish 4 attribute");
50
51Value finishVal = new Value();
52finishVal.Id = 5;
53finishVal.DateTimeValue = DateTime.Now;
54finishVal.Description = "Finish 4 value description";
55
56taskFinishAttributeDefinition.ValueList.Add(finishVal);
57
58project.ExtendedAttributes.Add(taskFinishAttributeDefinition);
59
60ExtendedAttributeDefinition numberAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Number20, "New number attribute");
61
62Value val1 = new Value();
63val1.Id = 6;
64val1.Val = "1";
65val1.Description = "Number 1 value";
66Value val2 = new Value();
67val2.Id = 7;
68val2.Val = "2";
69val2.Description = "Number 2 value";
70Value val3 = new Value();
71val2.Id = 8;
72val3.Val = "3";
73val3.Description = "Number 3 value";
74
75numberAttributeDefinition.AddLookupValue(val1);
76numberAttributeDefinition.AddLookupValue(val2);
77numberAttributeDefinition.AddLookupValue(val3);
78
79project.ExtendedAttributes.Add(numberAttributeDefinition);
80
81ExtendedAttributeDefinition resourceStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupResourceDefinition(ExtendedAttributeResource.Start5, "New start5 attribute");
82
83Value startVal2 = new Value();
84startVal2.Id = 9;
85startVal2.DateTimeValue = DateTime.Now;
86startVal2.Description = "this is start5 value descr";
87
88resourceStartAttributeDefinition.AddLookupValue(startVal2);
89
90project.ExtendedAttributes.Add(resourceStartAttributeDefinition);
91
92// Define a duration attribute without lookup.
93ExtendedAttributeDefinition taskDurationAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "New Duration");
94project.ExtendedAttributes.Add(taskDurationAttributeDefinition);
95
96// Add new task and assign duration value to the previously defined duration attribute.
97Task timeTask = project.RootTask.Children.Add("New task");
98
99ExtendedAttribute durationExtendedAttribute = taskDurationAttributeDefinition.CreateExtendedAttribute();
100
101durationExtendedAttribute.DurationValue = project.GetDuration(3.0, TimeUnitType.Hour);
102timeTask.ExtendedAttributes.Add(durationExtendedAttribute);
103
104MPPSaveOptions mppSaveOptions = new MPPSaveOptions();
105mppSaveOptions.WriteViewData = true;
106
107project.Save("WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);
Extended Attributes는 맞춤형 프로젝트 메타데이터 을(를) 필요로 하는 조직에 있어 중요한 기능입니다. 이들은 Microsoft Project의 기본 필드를 넘어 특정 비즈니스 요구에 맞게 프로젝트 파일을 조정할 수 있는 유연성을 제공합니다 — 재무 식별자 추적부터 작업 흐름 승인 캡처에 이르기까지. 또한 Aspose.Tasks for .NET, 개발자는 extended attributes의 생성 및 관리를 완전히 자동화할 수 있습니다, 조직 전반의 시스템에서 일관되고 신뢰할 수 있으며 표준을 준수하는 데이터 처리를 보장합니다. 이 기능은 팀이 Microsoft Project 데이터를 수동 개입 없이 보고 파이프라인, ERP 시스템 및 기타 애플리케이션에 통합하는 데 도움을 줍니다.