Hey, No Problem I made it work and works like charm. Do you know how?
ProjectPlanDocument plan = new ProjectPlanDocument();
plan.TaskItems.Add(new TaskItem { Id = 1, Name = “First” });
plan.TaskItems.Add(new TaskItem { Id = 2, Name = “Second” });
plan.TaskItems.Add(new TaskItem { Id = 3, Name = “Third” });
plan.Dependencies.Add(new Dependency { From = “1”, To = “3” });
plan.Dependencies.Add(new Dependency { From = “2”, To = “3” });
Project p = new Project();
int dynamicNumber = 1000;
for (int i = 0; i < 3; i++)
{
foreach (var task in plan.TaskItems)
p.RootTask.Children.Add(new Task { Name = task.Name, Id = task.Id + dynamicNumber });
ChildTasksCollector collector = new ChildTasksCollector(); // Create a ChildTasksCollector instance
TaskUtils.Apply(p.RootTask, collector, 1); // Collect all the tasks from RootTask using TaskUtils
foreach (var depe in plan.Dependencies)
{
var fromTask = collector.Tasks.Where(t => t.Id == int.Parse(depe.From) + dynamicNumber).FirstOrDefault();
var toTask = collector.Tasks.Where(t => t.Id == int.Parse(depe.To) + dynamicNumber).FirstOrDefault();
p.TaskLinks.Add(new TaskLink(fromTask, toTask, TaskLinkType.FinishToStart));
}
p.CalcTaskIds();
p.UpdateReferences();
dynamicNumber += 1000;
}
foreach (var task in p.RootTask.Children)
System.Diagnostics.Trace.Write(task.Id);
foreach (var link in p.TaskLinks)
System.Diagnostics.Trace.Write(link.PredTask.Id);