Project's calculation modes
Contents
[
Hide
Show
]Project Calculation Modes
Aspose.Tasks for .NET API provides three project calculation modes which define how values of dependent properties are calculated when the value of a property is set. These calculation modes are:
- None - Sets only necessary properties and does not perform any calculations
- Manual - Sets only dependent object properties without recalculation of any other data
- Automatic - Recalculates dates, work and cost properties automatically
This examples below shows the usage of each of these with the help of code samples.
Project Calculation Mode - None
1// Create empty project and set calculation mode to None
2Project project = new Project();
3project.CalculationMode = CalculationMode.None;
4
5// Add a new task
6Task task = project.RootTask.Children.Add("Task");
7
8// Note that even ids were not calculated
9Console.WriteLine("Task.Id Equals 0 : {0} ", task.Get(Tsk.Id).Equals(0));
10Console.WriteLine("Task.OutlineLevel Equals 0 : {0} ", task.Get(Tsk.OutlineLevel).Equals(0));
11Console.WriteLine("Task Start Equals DateTime.MinValue : {0} ", task.Get(Tsk.Start).Equals(DateTime.MinValue));
12Console.WriteLine("Task Finish Equals DateTime.MinValue : {0} ", task.Get(Tsk.Finish).Equals(DateTime.MinValue));
13Console.WriteLine("Task Duration Equals 0 mins : {0} ", task.Get(Tsk.Duration).ToString().Equals("0 mins"));
14
15// Set duration property
16task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
17Console.WriteLine("Task Duration Equals 2 days : {0} ", task.Get(Tsk.Duration).ToString().Equals("2 days"));
18Console.WriteLine("Task Start Equals DateTime.MinValue : {0} ", task.Get(Tsk.Start).Equals(DateTime.MinValue));
19Console.WriteLine("Task Finish Equals DateTime.MinValue : {0} ", task.Get(Tsk.Finish).Equals(DateTime.MinValue));
Project Calculation Mode - Manual
1// Create empty project and set calculation mode to Manual
2Project project = new Project();
3project.CalculationMode = CalculationMode.Manual;
4
5// Set project start date and add new tasks
6project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
7Task task1 = project.RootTask.Children.Add("Task 1");
8Task task2 = project.RootTask.Children.Add("Task 2");
9
10// The necessary properties are set in manual mode
11Console.WriteLine("Task1.Id Equals 1 : {0} ", task1.Get(Tsk.Id).Equals(1));
12Console.WriteLine("Task1 OutlineLevel Equals 1 : {0} ", task1.Get(Tsk.OutlineLevel).Equals(1));
13Console.WriteLine("Task1 Start Equals 15/04/2015 08:00 AM : {0} ", task1.Get(Tsk.Start).Equals(new DateTime(2015, 4, 15, 8, 0, 0)));
14Console.WriteLine("Task1 Finish Equals 15/04/2015 05:00 PM : {0} ", task1.Get(Tsk.Finish).Equals(new DateTime(2015, 4, 15, 17, 0, 0)));
15Console.WriteLine("Task1 Duration Equals 1 day : {0} ", task1.Get(Tsk.Duration).ToString().Equals("1 day"));
16Console.WriteLine("Task2 Start Equals 15/04/2015 08:00 AM : {0} ", task2.Get(Tsk.Start).Equals(new DateTime(2015, 4, 15, 8, 0, 0)));
17Console.WriteLine("Task2 Finish Equals 15/04/2015 05:00 PM : {0} ", task2.Get(Tsk.Finish).Equals(new DateTime(2015, 4, 15, 17, 0, 0)));
18Console.WriteLine("Task2 Duration Equals 1 day : {0} ", task2.Get(Tsk.Duration).ToString().Equals("1 day"));
19
20// When we link two tasks together their dates are not recalculated in manual mode
21TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
22
23// Task 2 Start has not been changed
24Console.WriteLine("Task1 Start Equals Task2 Start : {0} ", task1.Get(Tsk.Start).Equals(task2.Get(Tsk.Start)));
25Console.WriteLine("Task1 Finish Equals Task2 Finish : {0} ", task1.Get(Tsk.Finish).Equals(task2.Get(Tsk.Finish)));
Project Calculation Mode - Automatic
1// Create empty project and set calculation mode to Automatic
2Project project = new Project();
3project.CalculationMode = CalculationMode.Automatic;
4
5// Set project start date and add new tasks
6project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
7Task task1 = project.RootTask.Children.Add("Task 1");
8Task task2 = project.RootTask.Children.Add("Task 2");
9
10// Link tasks
11TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
12
13// Verify dates have been recalculated
14Console.WriteLine("Task1 Start + 1 Equals Task2 Start : {0} ", task1.Get(Tsk.Start).AddDays(1).Equals(task2.Get(Tsk.Start)));
15Console.WriteLine("Task1 Finish + 1 Equals Task2 Finish : {0} ", task1.Get(Tsk.Finish).AddDays(1).Equals(task2.Get(Tsk.Finish)));
16Console.WriteLine("RootTask Finish Equals Task2 Finish : {0} ", task2.Get(Tsk.Finish).Equals(project.RootTask.Get(Tsk.Finish)));
17Console.WriteLine("Project Finish Date Equals Task2 Finish : {0} ", task2.Get(Tsk.Finish).Equals(project.Get(Prj.FinishDate)));