리소스 할당에 확장 속성 추가 방법

작업과 자원처럼 확장 속성은 리소스 할당에도 추가할 수 있습니다. Aspose.Tasks for .NET API는 일반 확장 속성과 조회 확장 속성을 리소스 할당에 첨부하여 프로젝트 데이터를 확장할 수 있게 해줍니다. 이를 통해 추가 메타데이터를 저장하고 프로젝트 보고를 보다 유연하게 만들 수 있습니다.

리소스 할당에 확장 속성 추가

이 예제에서는 확장 속성을 생성하여 리소스 할당에 직접 할당하는 방법을 보여줍니다. 이 방법은 표준 Microsoft Project 필드에 포함되지 않는 사용자 지정 데이터를 추적해야 할 때 유용합니다.

 1// Create new project
 2Project project = new Project("New Project.mpp");
 3
 4// Add new task and resource
 5Task task = project.RootTask.Children.Add("Task");
 6Resource resource = project.Resources.Add("Rsc");
 7
 8// Assign the resource to the desired task
 9ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);
10
11// Custom attributes which is visible in "Resource Usage" view can be created with ExtendedAttributeDefinition.CreateResourceDefinition method.
12{
13    ExtendedAttributeDefinition resCostAttributeDefinition = ExtendedAttributeDefinition.CreateResourceDefinition(
14        CustomFieldType.Cost,
15        ExtendedAttributeResource.Cost5,
16        "My cost");
17
18    project.ExtendedAttributes.Add(resCostAttributeDefinition);
19
20    var value = resCostAttributeDefinition.CreateExtendedAttribute();
21
22    // The type of the attribute is "Cost", so we need to use "NumericValue" property.
23    value.NumericValue = 1500;
24
25    assignment.ExtendedAttributes.Add(value);
26}
27
28// Custom attributes which is visible in "Task Usage" view can be created with ExtendedAttributeDefinition.CreateTaskDefinition method
29{
30    ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(
31        CustomFieldType.Cost,
32        ExtendedAttributeTask.Cost5,
33        "My cost for task");
34
35    project.ExtendedAttributes.Add(taskCostAttributeDefinition);
36
37    var value = taskCostAttributeDefinition.CreateExtendedAttribute();
38
39    // The type of the attribute is "Cost", so we need to use "NumericValue" property.
40    value.NumericValue = 2300;
41
42    assignment.ExtendedAttributes.Add(value);
43}
44
45project.Save("AddExtendedAttributesToResourceAssignment_out.mpp", SaveFileFormat.MPP);

리소스 할당에 조회 확장 속성 추가

다음 코드는 확장 속성에 조회 값을 사용하는 방법을 보여줍니다. 조회 확장 속성을 사용하면 리소스 할당 데이터가 미리 정의된 목록에 맞도록 하여 인적 오류를 줄이고 프로젝트 정보를 일관되게 유지할 수 있습니다.

 1// Create new project
 2Project project = new Project("New Project.mpp");
 3
 4// Assign resource "1 TRG: Trade Group" to the "TASK 1" by creating a ResourceAssignment object.
 5Resource resource = project.Resources.GetById(1);
 6Task task = project.RootTask.Children.GetById(1);
 7
 8ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);
 9
10// Create custom attribute definition with lookup.
11ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.CreateLookupResourceDefinition(
12    CustomFieldType.Cost,
13    ExtendedAttributeResource.Cost5,
14    "My lookup resource cost");
15project.ExtendedAttributes.Add(resCostAttr);
16
17var value1 = new Value { NumberValue = 1500, Description = "Val 1", Id = 1, Val = "1500" };
18
19resCostAttr.AddLookupValue(value1);
20
21resCostAttr.AddLookupValue(new Value { NumberValue = 2500, Description = "Val 2", Id = 2 });
22
23// This value can be seen in "Resource usage" view of MS Project.
24var attributeValue = resCostAttr.CreateExtendedAttribute(value1);
25assignment.ExtendedAttributes.Add(attributeValue);
26
27// Create custom attribute definition with lookup.
28ExtendedAttributeDefinition taskCostAttr = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
29    ExtendedAttributeTask.Cost4,
30    "My lookup task cost");
31
32project.ExtendedAttributes.Add(taskCostAttr);
33
34var taskLookupValue1 = new Value { NumberValue = 18, Description = "Task val 1", Id = 3, Val = "18" };
35taskCostAttr.AddLookupValue(taskLookupValue1);
36
37resCostAttr.AddLookupValue(new Value { NumberValue = 30, Description = "Task val 2", Id = 4 });
38
39// This value can be seen in "Task usage" view of MS Project.
40assignment.ExtendedAttributes.Add(taskCostAttr.CreateExtendedAttribute(taskLookupValue1));
41
42project.Save("AddExtendedAttributesToRAWithLookUp_out.mpp", SaveFileFormat.MPP);

자주 묻는 질문

질문: 확장 속성을 사용하려면 Microsoft Project가 설치되어 있어야 하나요?

질문: 동일한 프로젝트에서 일반 확장 속성과 조회 확장 속성을 모두 정의할 수 있나요?

질문: Aspose.Tasks를 통해 추가한 확장 속성이 Microsoft Project에서 파일을 열 때 표시되나요?

결론

Aspose.Tasks for .NET에서 리소스 할당에 확장 속성을 추가하면 추가 프로젝트 데이터를 관리하는 유연성이 제공됩니다. 일반 확장 속성이든 조회 확장 속성이든 사용자 지정 필드로 프로젝트 파일을 확장하고 데이터 무결성을 보장하며 보고 기능을 강화할 수 있습니다. 이 모든 것은 Microsoft Project를 설치할 필요 없이 가능하며, 이러한 기능 때문에 Aspose.Tasks는 C# 환경에서 전문적인 프로젝트 관리 자동화에 신뢰할 수 있는 선택이 됩니다.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.