リソース割り当てに拡張属性を追加する方法

タスクやリソースと同様に、拡張属性はリソース割り当てにも追加できます。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);

よくある質問

Q: 拡張属性を操作するために Microsoft Project をインストールする必要がありますか?

Q: 同じプロジェクト内でプレーン拡張属性とルックアップ拡張属性の両方を定義できますか?

Q: 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.