We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Automatic tasks and constraints

Hi.

I have problem with creating automatic tasks. when i write blow code:

mspTask.Set(Tsk.Uid, task.Id);
mspTask.Set(Tsk.Name, task.Name);
mspTask.Set(Tsk.Start, start);

ATasks.Calendar cal = project.Get(Prj.Calendar);
double totalHours = cal.GetWorkingHours(start, end).WorkingHours.TotalHours + 8;
mspTask.Set(Tsk.Duration, project.GetDuration(totalHours, ATasks.TimeUnitType.Hour));
mspTask.Set(Tsk.IsManual, false);

in output ms project file, task have “start not earlier than” constraint, but I need it in default “as soon as possible” constraint . even when i set in blow code:

mspTask.Set(Tsk.ConstraintType, ConstraintType.AsSoonAsPossible);

every start date of tasks become same as first task and is wrong.
pleas help me in solution
thanks.


Hi Hamid,


Thank you for writing to Aspose support team.

I have tried following sample code using Aspose.Tasks for .NET 16.11.0 and opened the output file in MSP 2010. It is observed that task’s default constraint type is As Soon As Possible. Could you please give a try to the sample code using attached template file and share the feedback?

Project project = new Project(@“Blank2010.mpp”);<o:p></o:p>

Task mspTask = project.RootTask.Children.Add("Task 1");

mspTask.Set(Tsk.Uid, 1);

mspTask.Set(Tsk.Name, "task.Name");

mspTask.Set(Tsk.Start, new DateTime(2016, 12, 5, 8, 0, 0));

ATasks.Calendar cal = project.Get(Prj.Calendar);

double totalHours = cal.GetWorkingHours(new DateTime(2016, 12, 5, 8, 0, 0), new DateTime(2016, 12, 5, 17, 0, 0)).WorkingHours.TotalHours + 8;

mspTask.Set(Tsk.Duration, project.GetDuration(totalHours, ATasks.TimeUnitType.Hour));

mspTask.Set(Tsk.IsManual, false);

mspTask.Set(Tsk.ConstraintType, ConstraintType.AsSoonAsPossible);

project.Save("outputWithBlank2010.mpp", SaveFileFormat.MPP);

Hi Kashif,

I have to say my code is in a loop for adding multiple tasks to the project. like this:

foreach (var task in MspTasks) {
//Code for adding tasks
}

the result for first task is ok ,but for next other tasks, start date become same as first start date.

Hi Hamid,


Could you please share complete sample code for reproducing the same at our end? Please also attach any sample file as well for the issue you are facing for further investigation at our end.

Hi

my code :

Project project = new Project(path);
//project.CalculationMode = CalculationMode.Manual;

ATasks.Task mspTask;
ATasks.Resource mspResource;
ATasks.Util.ChildTasksCollector collector = new ATasks.Util.ChildTasksCollector();
ATasks.Util.TaskUtils.Apply(project.RootTask, collector, 0);

//Fill Tasks
foreach (var task in MspTasks)
{
if (task.ParentId.HasValue)
{
Task tsk = collector.Tasks.Find(o => o.Get(Tsk.Uid) == task.ParentId.Value);
mspTask = tsk.Children.Add();
}
else
{
mspTask = project.RootTask.Children.Add(task.Name);
}
DateTime start = task.Start ?? DateTime.Now;
DateTime end = task.Finish ?? DateTime.Now;

mspTask.Set(Tsk.Uid, task.Id);
mspTask.Set(Tsk.Name, task.Name);
mspTask.Set(Tsk.Start, start);

ATasks.Calendar cal = project.Get(Prj.Calendar);
double totalHours = cal.GetWorkingHours(start, end).WorkingHours.TotalHours + 8;
mspTask.Set(Tsk.Duration, project.GetDuration(totalHours, ATasks.TimeUnitType.Hour));

mspTask.Set(Tsk.IsManual, false);
mspTask.Set(Tsk.ConstraintType, ConstraintType.AsSoonAsPossible);

ATasks.Util.TaskUtils.Apply(project.RootTask, collector, 0);
}

MemoryStream fs = new MemoryStream();
project.Save(fs, (ATasks.Saving.SaveFileFormat)setting.SaveFileFormat);

Hi Hamid,


Thank you for sending us the sample code but I am afraid that it is not compilable and also no source file referred in “path” is provided. Could you please send us the compilable code along with the template project file? This will help us to re-produce the scenario and provide assistance accordingly.