Good morning. I've been working with Aspose.Task for .Net.
I'm pulling information from a database and creating a project based on that information.
The information is three levels deep. Project, Task, and subtask. I populate the Project with info, fill out it's children (Task), and then fill out it's children, children. I run into a weird issue. Once I input the information, after I calculate TaskID, TaskUID, ResourceID, ResourceUID; it seems when subtask are populated with a resource, the duration goes to 0. Conversely, if I leave resources empty for subtask, the duration populates just fine. Attached is a coding sample.
try
{
oProject = new Aspose.Tasks.Project();
oProject.DurationFormat = TimeUnitType.Day;
oProject.MinutesPerDay = 480;
int wbsIndex = 0;
int taskIndex = 0;
Task root = new Task();
oProject.RootTask = root;
foreach (TaskLTO t in this.TaskCollection)
{//collection is already in order, just build
Aspose.Tasks.Task newTask = new Aspose.Tasks.Task();
++taskCount;
newTask.Uid = t.Index;
newTask.Id = taskCount;
newTask.Name = t.Task;
newTask.ActualStart = t.Start;
newTask.Duration = new TimeSpan(Int32.Parse(t.Finish.Subtract(t.Start).Days.ToString()) * 8,0,0);
newTask.DurationFormat = TimeUnitType.Day;
newTask.OutlineLevel = (int)t.TaskType;
//build outline of task
switch (t.TaskType)
{
case TaskTypes.PM_WBS:
{
root.Children.Add(newTask);
break;
}
case TaskTypes.Task:
{
wbsIndex = root.Children.Count - 1;
((Task)root.Children[wbsIndex]).Children.Add(newTask);
break;
}
case TaskTypes.SubTask:
{
taskIndex = ((Task)root.Children[wbsIndex]).Children.Count - 1;
((Task)((Task)root.Children[wbsIndex]).Children[taskIndex]).Children.Add(newTask);
break;
}
}
//determine if this resource is unique...if so, add them to the resource list, otherwise keep it moving
if (t.Resources != "")
{//adds resource to the projec
AddResource(ref oProject, t.Resources);
}
}
oProject.CalcTaskIds();
oProject.CalcTaskUids();
//run through again to make task links...predecessors
//foreach (TaskLTO taskLTO in this.TaskCollection)
// {
// if (taskLTO.Predecessors > 0)
// {//create link
// Task task1 = oProject.GetTaskById(taskLTO.Index);
// Task task2 = oProject.GetTaskById(this.GetTaskLTOByTypeAndID(taskLTO.Predecessors, taskLTO.TaskType).Index);
// oProject.TaskLinks.Add( new TaskLink(task1, task2, TaskLinkType.StartToFinish));
// }
// }
//I initially used recursion here to create the appropriate relationships between task and resources...this however screwed up the duration; everything being set to 0
foreach (Task wbs in oProject.RootTask.Children)
{
foreach (Resource res in oProject.Resources)
{
if ((this.TaskCollection.Count >= wbs.Id - 1) && (this.TaskCollection[wbs.Id - 1].Task != "") && (res.Name == this.TaskCollection[wbs.Id - 1].Resources))
{
//this.AddResourceAssignment(ref oProject, wbs, res);
oProject.ResourceAssignments.Add(new ResourceAssignment(wbs,res));
}
}
foreach (Task task in wbs.Children)
{
foreach (Resource res in oProject.Resources)
{
if ((this.TaskCollection.Count >= task.Id - 1) && (this.TaskCollection[task.Id - 1].Task != "") && (res.Name == this.TaskCollection[task.Id - 1].Resources))
{
//this.AddResourceAssignment(ref oProject, wbs, res);
oProject.ResourceAssignments.Add(new ResourceAssignment(task,res));
}
}
}
}
//create relationships between resources and tasks...resource assignments.
oProject.CalcResourceAssignmentUids();
oProject.CalcResourceAssignmentIds();
// oProject.CalcResourceFields();
// oProject.CalcResourceStartFinish();
//the world is good and just...generate document
return GenerateFile(ref oProject);
When i refrain from Calculating Resources and Task, the duration doesn't get set but the Resources are preserved.