Resources are represented in the object model by the IResourceViewModel interface. The resources in the project can be obtained from the Resources property of the IProjectViewModel.
New resources can be created by calling the CreateResource method. This does not take arguments. Creating a new resource through the ViewModel is automatically reflected back to the Model if the Model implements the IList interface. The type of the newly created Model resource is specified by the ResourceType property of the project.
The following sample code creates and initializes a new resource in an existing project:
C# Copy Code |
---|
var resource = project.CreateResource(); |
Visual Basic Copy Code |
---|
Dim resource = project.CreateResource() |
Resources are deleted through the RemoveResource method. Resource deletion is automatically reflected back to the Model if the Model implements the IList interface.
Resources are allocated for activities in the project using a special mediator object - IResourceAllocationViewModel. To create new allocation object, call the CreateResourceAllocation method of the project. This method accepts two arguments identifying the resource and the related activity. Both arguments need to be specified.
The following example creates a new allocation of the resource created above for a specified activity:
C# Copy Code |
---|
project.CreateResourceAllocation(resource, targetActivity); |
Visual Basic Copy Code |
---|
project.CreateResourceAllocation(resource, targetActivity) |
To delete a resource allocation, call the RemoveResourceAllocation method.
To get the activities a resource is allocated for, use the Allocations property. Each allocation in this list exposes its related activity through the Activity property.
All of the above operations are undoable. Check Undo and Redo for additional information.