Thursday, January 12, 2012

Aspose.Tasks and Task Types


Task dates may be automatically calculated by the MSP's scheduling engine which may cause a task's start and finish dates to shift depending on the task type setting.


Task task = new Task("Name");
task.Type = TaskType.FixedUnits ;

The following is a very useful post by Chris Woodill explaining each of the TaskTypes:
http://chriswoodill.blogspot.com/2009/03/how-to-use-microsoft-project-task-type.html

Aspose.Tasks in MS Project Resource Uids


When using Aspose.Tasks to generate an XML file for Microsoft Project, if one of the resource’s uid is set to 0 and it has been used on an assignment, the assignment will not be shown once the xml file is opened in Microsoft Project. To prevent this, always set the resource.uid to a positive non zero integer value.
Aspose.Tasks.Resource resource = new Aspose.Tasks.Resource("Name");      
resource.Uid = resourceIDCounter++;

Note that a function call to CalcResourceUids of the Aspose.Tasks.Project will reset the Uid value.
_project.CalcResourceUids();

Booking individual periods in TimePhaseData in MS Project using Aspose.Tasks


The following code will allow booking of individual periods in the TimePhaseDetail of MSP.
I've used the following tools/languages for this demo.
  • Aspose.Tasks version: 4.0.0.0
  • Microsoft Visual Studio 2010 C#
  • Microsoft Project 2007
The _tasks and _resources is just a collection of Tasks and Resources respectively.
In the example below, all resources are being assigned to each task and are given a 1 or 2 value depending on the flag variable.

foreach (Task task in _tasks.Values) {
   foreach (Aspose.Tasks.Resource resource in _resources.Values) {

      ResourceAssignment resourceAssignment = new
      ResourceAssignment();
      resourceAssignment.Task = task;
      resourceAssignment.Resource = resource;

      resourceAssignment.Start = task.ActualStart;
      resourceAssignment.Finish = task.ActualFinish;
      resourceAssignment.Units = 1;
      resourceAssignment.HasFixedRateUnits = true;
      resourceAssignment.LevelingDelayFormat = TimeUnitType.ElapsedHour;
      resourceAssignment.Uid = _project.NextResourceAssignmentUid;
      resourceAssignment.WorkContour = WorkContourType.Contoured;
     
      DateTime date = task.ActualStart;
      bool flag = true;
      while (date < task.ActualFinish) {

         TimephasedData timephaseData = new TimephasedData();
         timephaseData.Start = date;
         timephaseData.Unit = TimeUnitType.Hour;
         date = date.AddDays(1);
         timephaseData.Finish = date;
         timephaseData.Uid = _project.ResourceAssignments.Count ;

         timephaseData.TimephasedDataType = TimephasedDataType.AssignmentActualWork ;

         if (flag) timephaseData.Value = "PT1H0M0S";

         else timephaseData.Value = "PT2H0M0S";
         flag = !flag;
         resourceAssignment.TimephasedData.Add(timephaseData);
      }
      _project.ResourceAssignments.Add(resourceAssignment);
   }
}


This is the resource usage view in MSP 2007. Notice that the resource Alien 1 is assigned to all projects with an alternating value.




I needed this requirement in the task I was working on and found that there were no existing examples on how to do it yet so this is just from my research.