MindFusion.Scheduling for Silverlight Programmer's Guide
Tutorial 3: Adding Resources

This tutorial shows how to create resources and associate them to activities with MindFusion.DataViews for Silverlight.

1. Create a Silverlight application and create a view with activities and dependencies

Follow steps 1 and 2 from Tutorial 2.

2. Create resources and allocate them to activities

To create the resources you could use the built-in Resource class. To allocated them to resources you can use the built-in ResourceAllocation class. Create a collection that will hold the Resource objects and a collection that will hold the ResourceAllocation objects:

C#  Copy Code

ObservableCollection<Resource> resources = new ObservableCollection<Resource>();
ObservableCollection<ResourceAllocation> allocations = new ObservableCollection<ResourceAllocation>();

Visual Basic  Copy Code

Dim resources As New ObservableCollection(Of Resource)()
Dim allocations As New ObservableCollection(Of ResourceAllocation)()

Next, create three Resource objects and then allocate these resources to some of the already created Activity objects through four ResourceAllocation objects. For example:

C#  Copy Code

Resource r1 = new Resource()
{
    Title = "Location 1",
    Description = "This is location 1",
};
resources.Add(r1);

ResourceAllocation ra1 = new ResourceAllocation() 
{
    Activity = a1,
    Resource = r1,
    StartTime = a1.StartTime,
    EndTime = a1.EndTime,
    Progress = a1.Progress
};
allocations.Add(ra1);

Visual Basic  Copy Code

Dim r1 As New Resource() With { _
 .Title = "Location 1", _
 .Description = "This is location 1"}
resources.Add(r1)

Dim ra1 As New ResourceAllocation() With { _
 .Activity = a1, _
 .Resource = r1, _
 .StartTime = a1.StartTime, _
 .EndTime = a1.EndTime, _
 .Progress = a1.Progress}
allocations.Add(ra1)

 Note

Please note that you are not limited to the built-in classes for activities, dependencies, resources and allocations. You can use your own custom objects as you will find out in Tutorial 5.

3. Create the project and associate it with the view

Modify the project initialization from the previous tutorial to include the newly created resources like this:

C#  Copy Code

IProjectViewModel project = activityView.CreateViewModel(activities, dependencies, resources, allocations, typeof(Activity), typeof(Dependency), typeof(Resource), typeof(ResourceAllocation));

Visual Basic  Copy Code

Dim project As IProjectViewModel = activityView.CreateViewModel(activities, dependencies, resources, allocations, GetType(Activity), GetType(Dependency), GetType(Resource), GetType(ResourceAllocation))

4. Build and run

Compile and run the application. The result will be similar to the image below:

 Note

You can find the complete source code of this tutorial in the product installation folder, under the folder for the appropriate .NET version and language.