Migrate to Aspose.Tasks for .NET 8.0.0+

Aspose.Tasks for .NET 8.0.0 is a revamped version of the API that includes considerable changes from usage perspective. Key differences of both the implementations include:

  • Legacy API allowed to set public fields of various project data classes such as Project, Tasks, Resource, etc. while the new implementation introduces Set and Get methods to achieve the same
  • Recalculate methods required to be called manually by user in the legacy API after certain operations such as Resource Assignments. The new Aspose.Tasks for .NET API performs most of such calculations automatically without user intervention required.
  • The new API provides manual as well as automatic recalculation modes similar to Microsoft Project (MSP). Manual mode calculates only the necessary fields whereas automatic mode recalculates everything. This eliminates the need of calling recalculating methods manually and improves overall API usage.

This new API is incompatible with the Legacy API and the objective of this article is to help you migrate your code to the new API. The article shows comparative code samples of the Legacy and the new API implementation, and includes:

Setting Default Project Properties

Aspose.Tasks’ legacy API allowed setting default properties of a project by directly setting the public attributes of the Project class. In the new API implementation, however, it exposes Set and Get methods to achieve the same.

Legacy API Code Sample

 1Project prj = new Project();
 2prj.IsScheduleFromStart = true;
 3prj.StartDate = DateTime.Now;
 4prj.DefaultStartTime = prj.StartDate;
 5prj.DefaultTaskType = TaskType.FixedDuration;
 6prj.DefaultStandardRate = 15;
 7prj.DefaultOvertimeRate = 12;
 8prj.DefaultTaskEVMethod = EarnedValueMethodType.PercentComplete;
 9prj.DefaultFixedCostAccrual = CostAccrualType.Prorated;
10prj.Save( "Project4.xml" , Aspose.Tasks.Saving.SaveFileFormat.XML);
 1'Create a project instance
 2Dim prj As New Project()
 3prj.IsScheduleFromStart = True
 4prj.StartDate = DateTime.Now
 5prj.DefaultStartTime = prj.StartDate
 6prj.DefaultTaskType = TaskType.FixedDuration
 7prj.DefaultStandardRate = 15
 8prj.DefaultOvertimeRate = 12
 9prj.DefaultTaskEVMethod = EarnedValueMethodType.PercentComplete
10prj.DefaultFixedCostAccrual = CostAccrualType.Prorated
11prj.Save("Project4.xml", Aspose.Tasks.Saving.SaveFileFormat.XML)

New Aspose.Tasks for .NET 8.x Approach

 1Project project = new Project();
 2project.Set(Prj.ScheduleFromStart,true);
 3project.Set(Prj.StartDate, DateTime.Now);
 4project.Set(Prj.DefaultStartTime,project.Get(Prj.StartDate));
 5project.Set(Prj.DefaultTaskType, TaskType.FixedDuration);
 6project.Set(Prj.DefaultStandardRate, 15);
 7project.Set(Prj.DefaultOvertimeRate, 12);
 8project.Set(Prj.DefaultTaskEVMethod, EarnedValueMethodType.PercentComplete);
 9project.Set(Prj.DefaultFixedCostAccrual, CostAccrualType.Prorated);
10project.Save("ProjectDefaultProps.xml", SaveFileFormat.XML);

 1Dim project As New Project()
 2project.[Set](Prj.ScheduleFromStart, True)
 3project.[Set](Prj.StartDate, DateTime.Now)
 4project.[Set](Prj.DefaultStartTime, project.[Get](Prj.StartDate))
 5project.[Set](Prj.DefaultTaskType, TaskType.FixedDuration)
 6project.[Set](Prj.DefaultStandardRate, 15)
 7project.[Set](Prj.DefaultOvertimeRate, 12)
 8project.[Set](Prj.DefaultTaskEVMethod, EarnedValueMethodType.PercentComplete)
 9project.[Set](Prj.DefaultFixedCostAccrual, CostAccrualType.Prorated)
10project.Save("ProjectDefaultProps.xml", SaveFileFormat.XML)

Creating and Adding Calendar to a Project

In order for proper functionality of Calendar items added to the Project, the legacy API required to recalculate Calendar UIDs. In the new API, however, UIDs recalculation are automatically dealt and there is no need to call the calculations manually.

Legacy API Code Sample

 1Project prj =  new Project();
 2Aspose.Tasks.Calendar cal1 = new  Aspose.Tasks.Calendar();
 3cal1.Name ="no info";
 4Aspose.Tasks.Calendar cal2 = new  Aspose.Tasks.Calendar(1);
 5cal2.Name = "no name";
 6Aspose.Tasks.Calendar cal3 = new  Aspose.Tasks.Calendar( "cal3" );
 7prj.Calendars.Add(cal1);
 8prj.Calendars.Add(cal2);
 9prj.Calendars.Add(cal3);
10prj.CalcCalendarUids();
11prj.Save( "Project.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML);

 1'Create a project instance
 2Dim prj As New Project()
 3'Define Calendar
 4Dim cal1 As New Aspose.Tasks.Calendar()
 5cal1.Name = "no info"
 6Dim cal2 As New Aspose.Tasks.Calendar(1)
 7cal2.Name = "no name"
 8Dim cal3 As New Aspose.Tasks.Calendar("cal3")
 9prj.Calendars.Add(cal1)
10prj.Calendars.Add(cal2)
11prj.Calendars.Add(cal3)
12prj.CalcCalendarUids()
13'Save the Project
14prj.Save("Project.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML)

New Aspose.Tasks for .NET 8.x Approach

1//Create a project instance
2Project prj = new Project();
3Aspose.Tasks.Calendar cal1 = prj.Calendars.Add("no info");
4Aspose.Tasks.Calendar cal2 = prj.Calendars.Add("no name");
5Aspose.Tasks.Calendar cal3 = prj.Calendars.Add("cal3");
6prj.Save("Project.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML);

1'Create a project instance
2Dim prj As New Project()
3Dim cal1 As Aspose.Tasks.Calendar = prj.Calendars.Add("no info")
4Dim cal2 As Aspose.Tasks.Calendar = prj.Calendars.Add("no name")
5Dim cal3 As Aspose.Tasks.Calendar = prj.Calendars.Add("cal3")
6prj.Save("Project.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML)

Making A Standard Calendar

Recalculating Calendar UIDs are no more required in the new ASpose.Tasks’ API as compared to the legacy API.

Legacy API Code Sample

1//Create a project instance
2Project prj = new  Project();
3//Define Calendar and make it standard
4Aspose.Tasks.Calendar cal1 = new  Aspose.Tasks.Calendar("My Cal");
5Aspose.Tasks.Calendar.MakeStandardCalendar(cal1);
6prj.Calendars.Add(cal1);
7prj.CalcCalendarUids();
8prj.Save( "Project.Xml" , Aspose.Tasks.Saving.SaveFileFormat.XML);

1'Create a project instance
2Dim prj As New Project()
3'Define Calendar and make it standard
4Dim cal1 As New Aspose.Tasks.Calendar("My Cal")
5Aspose.Tasks.Calendar.MakeStandardCalendar(cal1)
6prj.Calendars.Add(cal1)
7prj.CalcCalendarUids()
8'Save the Project
9prj.Save("Project.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML)

New Aspose.Tasks for .NET 8.x Approach

1// Create a project instance
2Project project = new Project();
3// Define Calendar and make it standard
4Aspose.Tasks.Calendar cal1 = project.Calendars.Add("My Cal");
5Aspose.Tasks.Calendar.MakeStandardCalendar(cal1);
6project.Save("Project.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML);

1'Create a project instance
2Dim project As New Project()
3'Define Calendar and make it standard
4Dim cal1 As Aspose.Tasks.Calendar = project.Calendars.Add("My Cal")
5Aspose.Tasks.Calendar.MakeStandardCalendar(cal1)
6'Save the Project
7project.Save("Project.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML)

Create and Add Task to Project

Creating a new task in the legacy API, it required to define a root task, add it to the project as its root task, and then add a new task to this root task as a child. The new API, however, doesn’t need you to define the root task and takes care of it automatically while adding the first task to the project.

Legacy API Code Sample

 1Project project = new Project();
 2Task rootTask = new Task();
 3Task tskGen = new Task("Task1");
 4tskGen.Id = 1;
 5tskGen.Uid = 1;
 6tskGen.Start = DateTime.Parse("17-Aug-2009 8:00 AM" );
 7tskGen.Finish = DateTime.Parse( "17-Aug-2009 5:00 PM" );
 8project.RootTask = rootTask;
 9project.RootTask.Children.Add(tskGen);
10project.Save("Project.xml", SaveFileFormat.XML);
1Dim project As New Project()
2Dim tskGen As New Task("Task1")
3tskGen.Id = 1
4tskGen.Uid = 1
5tskGen.Start = DateTime.Parse("17-Aug-2009 8:00 AM")
6tskGen.Finish = DateTime.Parse("17-Aug-2009 5:00 PM")
7project.RootTask = rootTask
8project.RootTask.Children.Add(tskGen)
9project.Save("Project.xml", SaveFileFormat.XML)

New Aspose.Tasks for .NET 8.x Approach

1Project project = new Project();
2Task task = project.RootTask.Children.Add("Task 1");
3task.Set(Tsk.Start, project.RootTask.Get(Tsk.Start).AddDays(1));
4// set task start day
5project.Save("CreateTasks.xml", SaveFileFormat.XML);

1Dim project As New Project()
2Dim task As Task = project.RootTask.Children.Add("Task 1")
3task.[Set](Tsk.Start, project.RootTask.[Get](Tsk.Start).AddDays(1))
4'set task start day
5project.Save("CreateTasks.xml", SaveFileFormat.XML)

Create and Add Resource to Project

Set and Get methods have been added to the Resource class of the API for manipulating attributes related to a project’s Resource.

Legacy API Code Sample

1Project project = new Project();
2Resource res =   Resource(new "Res1");
3res.Id = 1;
4res.Uid = 1;
5res.Start = DateTime.Parse("19-Aug-2009 8:00 AM");
6res.Finish = DateTime.Parse("19-Aug-2009 5:00 PM");
7project.Resources.Add(res);
8project.Save("Project.xml", SaveFileFormat.XML);

1Dim project As New Project()
2Dim res As New Resource("Res1")
3res.Id = 1
4res.Uid = 1
5res.Start = DateTime.Parse("19-Aug-2009 8:00 AM")
6res.Finish = DateTime.Parse("19-Aug-2009 5:00 PM")
7project.Resources.Add(res)
8project.Save("Project.xml", SaveFileFormat.XML)

New Aspose.Tasks for .NET 8.x Approach

1Project project = new Project();
2Resource rsc = project.Resources.Add("R1");
3rsc.Set(Rsc.Start, DateTime.Parse("31-Aug-2014 8:00 AM"));
4rsc.Set(Rsc.Finish, DateTime.Parse("31-Aug-2014 5:00 PM"));
5project.Save("CreateResource.xml", SaveFileFormat.XML);

1Dim project As New Project()
2Dim rsc As Resource = project.Resources.Add("R1")
3rsc.[Set](Rsc.Start, DateTime.Parse("31-Aug-2014 8:00 AM"))
4rsc.[Set](Rsc.Finish, DateTime.Parse("31-Aug-2014 5:00 PM"))
5project.Save("CreateResource.xml", SaveFileFormat.XML)

Create and Add Resource Assignment to Project

The ResourceAssignment class also introduces the Set and Get methods similar to other data collections of the API such as Tasks, Resources and Tasks Links.

Legacy API Code Sample

 1Project project = new Project();
 2Task tskRoot =  new Task();
 3Task task = new Task("Task");
 4Resource rsc = new Resource();
 5rsc.StandardRate = 10;
 6rsc.OvertimeRate = 15;
 7ResourceAssignment assignment = new ResourceAssignment(task, rsc);
 8assignment.Uid = 1;
 9assignment.Start = DateTime.Parse("18-Aug-2009 8:00 AM" );
10assignment.Finish = DateTime.Parse("18-Aug-2009 5:00 PM" );
11project.RootTask = tskRoot;
12project.RootTask.Children.Add(task);
13project.Resources.Add(res);
14project.ResourceAssignments.Add(assignment);
15project.Save("project.xml", SaveFileFormat.XML);

 1Dim project As New Project()
 2Dim tskRoot As New Task()
 3Dim task As New Task("Task")
 4Dim rsc As New Resource()
 5rsc.StandardRate = 10
 6rsc.OvertimeRate = 15
 7Dim assignment As New ResourceAssignment(task, rsc)
 8assignment.Start = DateTime.Parse("18-Aug-2009 8:00 AM" )
 9assignment.Finish = DateTime.Parse("18-Aug-2009 5:00 PM" )
10assignment.Uid = 1
11project.RootTask = tskRoot
12project.RootTask.Children.Add(task)
13project.Resources.Add(res)
14project.ResourceAssignments.Add(assignment)
15project.Save("project.xml", SaveFileFormat.XML)

New Aspose.Tasks for .NET 8.x Approach

1Project project = new Project();
2Task task = project.RootTask.Children.Add("Task");
3Resource rsc = project.Resources.Add("Rsc");
4rsc.Set(Rsc.StandardRate, 10);
5rsc.Set(Rsc.OvertimeRate, 15);
6ResourceAssignment assignment = project.ResourceAssignments.Add(task, rsc);
7assignment.Set(Assn.Start,DateTime.Parse("18-Aug-2009 8:00 AM" );
8assignment.Set(Assn.Finish, DateTime.Parse("18-Aug-2009 5:00 PM" );
9project.Save("ResourceAssignments.xml", SaveFileFormat.XML);

1Dim project As New Project()
2Dim task As Task = project.RootTask.Children.Add("Task")
3Dim rsc As Resource = project.Resources.Add("Rsc")
4rsc.[Set](Rsc.StandardRate, 10)
5rsc.[Set](Rsc.OvertimeRate, 15)
6Dim assignment As ResourceAssignment = project.ResourceAssignments.Add(task, rsc)
7assignment.Set(Assn.Start,DateTime.Parse("18-Aug-2009 8:00 AM" )
8assignment.Set(Assn.Finish, DateTime.Parse("18-Aug-2009 5:00 PM" ) project.Save("ResourceAssignments.xml", SaveFileFormat.XML)
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.