CreateMPP.zip (27.9 KB)
Hi Team,
I am facing 2 issues with Create MPP.
Using the below code create MPP taking more than 5 minutes for 1000 tasks.
DateTime endTime = DateTime.Now.AddDays(2).AddHours(2).AddMinutes(30);
double totalMinutes = (endTime - task.Get(Tsk.Start)).TotalMinutes;
task.Set(Tsk.Duration, project.GetDuration(totalMinutes, Aspose.Tasks.TimeUnitType.Minute));
To avoid the longer time, Used the below code but it is updating only Days and not Hours and Minutes.
task.Set(Tsk.Finish, endTime);
Please refer the attachment for more details and reply back asap.
Regards,
Ravi
@ravikonnur ,
I have observed the issue shared by you and have created an issue with ID TASKSNET-3454 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.
@mudassir.fayyaz
This is used to work as expected in older Aspose.Tasks 18.7 version, but seen this issue in 19.8 version.
May I know what is the tentative time for fix availability for this issue?
mudassir.fayyaz:
TASKSNET-3454
Hello, @srinudhulipalla
Please, try to use the next code sample
static void Main(string[] args)
{
DateTime dtProjectStart = DateTime.Now;
DateTime dtProjectEnd = DateTime.Now;
string projectTemplate = @"C:\temp\Projections.mpp";
Aspose.Tasks.Project project = new Aspose.Tasks.Project(projectTemplate);
project.Set(Prj.StartDate, dtProjectStart);
project.Set(Prj.FinishDate, dtProjectEnd);
project.Set(Prj.DefaultStartTime, dtProjectStart);
project.Set(Prj.DefaultFinishTime, dtProjectEnd);
project.Set(Prj.TimescaleStart, dtProjectStart);
project.Set(Prj.TimescaleFinish, dtProjectEnd);
project.Set(Prj.CurrentDate, DateTime.Today);
project.CalculationMode = CalculationMode.None;
ChildTasksCollector collector = new ChildTasksCollector();
TaskUtils.Apply(project.RootTask, collector, 0);
System.IO.File.AppendAllText(@"C:\temp\time.txt", "Start: " + DateTime.Now.ToString() + Environment.NewLine);
for (int i = 0; i < 1000; i++)
{
var task = project.RootTask.Children.Add("task");
task.Set(Tsk.IsManual, new NullableBool(true));
DateTime startTime = DateTime.Now;
task.Set(Tsk.Start, startTime);
DateTime endTime = DateTime.Now.AddDays(2).AddHours(2).AddMinutes(30);
task.Set(Tsk.Finish, endTime);
double totalMinutes = (endTime - task.Get(Tsk.Start)).TotalMinutes;
task.Set(Tsk.Duration, project.GetDuration(totalMinutes, Aspose.Tasks.TimeUnitType.Minute));
string name = "Test " + i;
Resource resource = project.Resources.FirstOrDefault(j => j.Get(Rsc.Name) == name.Trim());
if (resource == null)
{
resource = project.Resources.Add(name.Trim());
}
project.ResourceAssignments.Add(task, resource);
}
project.Recalculate();
System.IO.File.AppendAllText(@"C:\temp\time.txt", "End: " + DateTime.Now.ToString() + Environment.NewLine);
project.Save(@"C:\temp\Output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
}
I tried with your sample code but still it is taking around 5 minutes to create MPP. I figured out that below line is taking more time to set duration. Any other ways to speedup the MPP creation.
task.Set(Tsk.Duration, project.GetDuration(totalMinutes, Aspose.Tasks.TimeUnitType.Minute));
alexanderefremov1:
static void Main(string[] args) { DateTime dtProjectStart = DateTime.Now; DateTime dtProjectEnd = DateTime.Now; string projectTemplate = @“C:\temp\Projections.mpp”; Aspose.Tasks.Project project = new Aspose.Tasks.Project(projectTemplate); project.Set(Prj.StartDate, dtProjectStart); project.Set(Prj.FinishDate, dtProjectEnd); project.Set(Prj.DefaultStartTime, dtProjectStart); project.Set(Prj.DefaultFinishTime, dtProjectEnd); project.Set(Prj.TimescaleStart, dtProjectStart); project.Set(Prj.TimescaleFinish, dtProjectEnd); project.Set(Prj.CurrentDate, DateTime.Today); project.CalculationMode = CalculationMode.None; ChildTasksCollector collector = new ChildTasksCollector(); TaskUtils.Apply(project.RootTask, collector, 0); System.IO.File.AppendAllText(@“C:\temp\time.txt”, "Start: " + DateTime.Now.ToString() + Environment.NewLine); for (int i = 0; i < 1000; i++) { var task = project.RootTask.Children.Add(“task”); task.Set(Tsk.IsManual, new NullableBool(true)); DateTime startTime = DateTime.Now; task.Set(Tsk.Start, startTime); DateTime endTime = DateTime.Now.AddDays(2).AddHours(2).AddMinutes(30); task.Set(Tsk.Finish, endTime); double totalMinutes = (endTime - task.Get(Tsk.Start)).TotalMinutes; task.Set(Tsk.Duration, project.GetDuration(totalMinutes, Aspose.Tasks.TimeUnitType.Minute)); string name = "Test " + i; Resource resource = project.Resources.FirstOrDefault(j => j.Get(Rsc.Name) == name.Trim()); if (resource == null) { resource = project.Resources.Add(name.Trim()); } project.ResourceAssignments.Add(task, resource); } project.Recalculate(); System.IO.File.AppendAllText(@“C:\temp\time.txt”, "End: " + DateTime.Now.ToString() + Environment.NewLine); project.Save(@“C:\temp\Output.mpp”, Aspose.Tasks.Saving.SaveFileFormat.MPP); }
Sorry, but the code sample I provided running for less 4 seconds on my machine.
Did you really set project.CalculationMode = CalcultionMode.None and called project.Recalculate() after the loop? You can find it in my code sample.
CreateMPP.zip (413.3 KB)
I tried with your sample code but OutlineLevel is not working after setting calculationmode.None
Please find the attachments for program and sample outputs for calculationmode.None and calculationmode.Manual
@alexanderefremov1
Any workarround for this problem without effecting OutlineLevel when using CalcultionMode.None?
@srinudhulipalla ,
This thread has been associated with the concerned issue in our issue tracking system. We will share updates with you and any possible workaround as soon as the issue will be addressed.
@mudassir.fayyaz
Sure, thank you. I will be waiting for the workarround for now. This created a major issue for us when we jump to latest Aspose.Tasks version. Hope I will listen from you very soon on this.
@srinudhulipalla ,
We will share good news with you as soon as issue will be addressed.
Hello.
@ravikonnur ,
@srinudhulipalla
The OutlineLevel is recalculated based on tasks’ hierarchy.
You could create the required tasks hierarchy by adding a new task to the required task.Children collection.
Thus you code snipped could look like:
DateTime dtProjectStart = DateTime.Now;
DateTime dtProjectEnd = DateTime.Now;
string projectTemplate = @"C:\temp\DefinitionProjections.mpp";
Aspose.Tasks.Project project = new Aspose.Tasks.Project(projectTemplate);
project.Set(Prj.StartDate, dtProjectStart);
project.Set(Prj.FinishDate, dtProjectEnd);
project.Set(Prj.DefaultStartTime, dtProjectStart);
project.Set(Prj.DefaultFinishTime, dtProjectEnd);
project.Set(Prj.TimescaleStart, dtProjectStart);
project.Set(Prj.TimescaleFinish, dtProjectEnd);
project.Set(Prj.CurrentDate, DateTime.Today);
project.CalculationMode = CalculationMode.None;
ChildTasksCollector collector = new ChildTasksCollector();
TaskUtils.Apply(project.RootTask, collector, 0);
System.IO.File.AppendAllText(@"C:\temp\time.txt", "Start: " + DateTime.Now.ToString() + > Environment.NewLine);
for (int i = 0; i < 1000; i++)
{
Task parentTask;
if (i >= 2)
{
parentTask = project.RootTask.Children[0].Children[0];
}
else if (i == 1)
{
parentTask = project.RootTask.Children[0];
}
else
{
parentTask = project.RootTask;
}
var task = parentTask.Children.Add("task");
task.Set(Tsk.IsManual, new NullableBool(true));
DateTime startTime = DateTime.Now;
task.Set(Tsk.Start, startTime);
DateTime endTime = DateTime.Now.AddDays(2).AddHours(2).AddMinutes(30);
task.Set(Tsk.Finish, endTime);
double totalMinutes = (endTime - task.Get(Tsk.Start)).TotalMinutes;
task.Set(Tsk.Duration, project.GetDuration(totalMinutes, Aspose.Tasks.TimeUnitType.Minute));
string name = "Test " + i;
Resource resource = project.Resources.FirstOrDefault(j => j.Get(Rsc.Name) == name.Trim());
if (resource == null)
{
resource = project.Resources.Add(name.Trim());
}
project.ResourceAssignments.Add(task, resource);
}
project.Recalculate();
System.IO.File.AppendAllText(@"C:\temp\time.txt", "End: " + DateTime.Now.ToString() + Environment.NewLine);
project.Save(@"C:\temp\Output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
MPPerror.png (17.9 KB)
I tried with your sample code but its giving an error.Please find the attachment for error message.
@ravikonnur ,
Can you please try using following alteration to avoid error.
if (i >= 2)
{
parentTask = project.RootTask.Children.ToList()[0].Children.ToList()[0];
}
else if (i == 1)
{
parentTask = project.RootTask.Children.ToList()[0];
}
@mudassir.fayyaz
The example which was given is just a sample to reproduce the problem from your side. Imagine a scenario (ofcourse, we have it now) where you have ‘N’ levels of tasks, the pain of mainging below line of code for ‘N’ level children.
project.RootTask.Children.ToList()[0].Children.ToList()[0]
For complex data at runtime, the property OutlineLevel does a great job. Is there any other ways OutlineLevel property make it work in latest Aspose.Tasks version without effecting performance?
@srinudhulipalla ,
The concerned issue is still open and we will share the good news when it will be fixed. However, we have shared the workaround with you previously that you may adopt on your end.
CreateMPP_Sep03.zip (28.5 KB)
We made the changes based on below line of code ,The tasks’ hierarchy is displaying fine but Start date is displaying default date (sat 01-01-1984 00:00) and End date is blank.
" project.RootTask.Children.ToList()[0] "
Please find the Test data and Sample code in attachment.
@ravikonnur ,
We have mentioned your issue in ticket and will share news with you after investigation.
@ravikonnur ,
Because tasks are created using “Manual” mode the Tsk.ManualStart and Tsk.ManualFinish properties should be also set:
{
string taskName = dr[“Plan/Step”].ToString();
task.Set(Tsk.Name, taskName);
DateTime startTime = DateTime.Now;
if (DateTime.TryParse(dr[“Start Date”].ToString(), out startTime))
{
task.Set(Tsk.Start, startTime);
task.Set(Tsk.ManualStart, startTime);
}
DateTime endTime = DateTime.Now;
task.Set(Tsk.ManualFinish, endTime);
task.Set(Tsk.Finish, endTime);
double totalMinutes = (endTime - task.Get(Tsk.Start)).TotalMinutes;
var duration = project.GetDuration(totalMinutes, Aspose.Tasks.TimeUnitType.Minute);
task.Set(Tsk.ManualDuration, duration);
task.Set(Tsk.Duration, duration);
}
CreateMPP_Sep05.zip (28.7 KB)
Thanks for the above code it works fine for start date and End date but its not working for Actual start and Actual End.
Please find the code and test data.