Problem with TaskLinks and FixedWork Tasks

Hello,
I’m quite new with the use of Aspose.Tasks, and i’m trying to create a sample project, with 5 fixed work tasks, assigned to 5 different resources. Everything goes well, except when I try to create TaskLinks between my tasks. The defined amount of work changes, and the start date of tasks 4 and 5 are weird…

Here is the code of my sample.

Any help would be appreciate.

Thanks in advance.

Yann

Project prj = new Project();

prj.IsScheduleFromStart = true;

prj.StartDate = new DateTime(2014, 7, 1);

prj.Calendar = Calendar.MakeStandardCalendar();
prj.Calendar.Name = “My standard”;
prj.Calendars.Add(prj.Calendar);


prj.NewTaskStartDate = TaskStartDateType.ProjectStartDate;

//You have to set this to use durations in days, weeks or months.
prj.DaysPerMonth = 20;
prj.MinutesPerWeek = 35 * 60;

// Root task
Task tskRoot = new Task();
prj.RootTask = tskRoot;
tskRoot.Uid = prj.NextTaskUid;

// Root resource
Resource rootResource = new Resource();
rootResource.Uid = prj.NextResourceUid;
prj.Resources.Add(rootResource);

int vf_PreviousTaskUid = -1;

//Define Resources
ArrayList resources = new ArrayList();
for (int i = 1; i <= 5; i++)
{
Task vf_NewTask = new Task("Task " + i);
vf_NewTask.Uid = prj.NextTaskUid;

// Fixed Work
vf_NewTask.Type = TaskType.FixedWork;

if (vf_PreviousTaskUid != -1)
{
TaskLink tsklnk = new TaskLink(prj.GetTaskByUid(vf_PreviousTaskUid), vf_NewTask, TaskLinkType.FinishToStart);
prj.TaskLinks.Add(tsklnk);
vf_NewTask.ConstraintType = ConstraintType.AsSoonAsPossible;
}
else
{
vf_NewTask.ConstraintType = ConstraintType.AsSoonAsPossible;
vf_NewTask.Start = prj.StartDate;
}

vf_PreviousTaskUid = vf_NewTask.Uid;

vf_NewTask.Work = new TimeSpan(i, 0, 0);
vf_NewTask.Duration = new TimeSpan(i, 0, 0);

vf_NewTask.DurationFormat = TimeUnitType.Hour;
vf_NewTask.RemainingWork = new TimeSpan(i, 0, 0);

vf_NewTask.PercentComplete = 0;

prj.RootTask.Children.Add(vf_NewTask);


string devloper = “Developer0” + i;
//Create resource
Resource rec = new Resource(devloper);
rec.Uid = prj.NextResourceUid;
rec.Type = ResourceType.Work;

rec.MaxUnits = 1.0;

//Add resource to project
prj.Resources.Add(rec);

//define assignment
ResourceAssignment ra = new ResourceAssignment(vf_NewTask, rec);

ra.Units = 1.0;
ra.Work = new TimeSpan(i, 0, 0);
ra.ActualWork = new TimeSpan(0, 0, 0);
ra.RemainingWork = new TimeSpan(i, 0, 0);

prj.ResourceAssignments.Add(ra);
}


prj.CalcCalendarUids();
prj.CalcTaskIds();
prj.CalcResourceFields();
prj.CalcResourceAssignmentIds();
prj.CalcResourceAssignmentUids(1);
prj.UpdateReferences();
prj.Save(@“C:\Temp\ProjectBasique.xml”, Aspose.Tasks.Saving.SaveFileFormat.XML);

Hi Yann,


Thank you for contacting Aspose support team.

Aspose.Tasks has now simplified the process of generating new project and there is no more need to create Root task, resource etc. There are new functions like Project.AddTask, Project.AddResource which provide all the default settings. Could you please give try to the code here using latest assembly Aspose.Tasks for .NET 6.7.0 and let us know your feedback.