private void setPredecessors(Item rootWBS, Tasks tasks, Dictionary <string, string> rowsIds) { var activities = rootWBS.getItemsByXPath("//Item[@type='Activity2']"); for (int i = 0; i < activities.getItemCount(); i++) { var activity = activities.getItemByIndex(i); var predecessors = activity.getRelationships("Predecessor"); for (int y = 0; y < predecessors.getItemCount(); y++) { int taskIndex = 0; if (!int.TryParse(activity.getProperty("inumber", string.Empty), out taskIndex)) { continue; } if (rowsIds.ContainsKey(predecessors.getItemByIndex(y).getProperty("related_id"))) { string predID = rowsIds[predecessors.getItemByIndex(y).getProperty("related_id")]; PjTaskLinkType precType = (PjTaskLinkType)predecessorTypes[predecessors.getItemByIndex(y).getProperty("precedence_type")]; var lead = predecessors.getItemByIndex(y).getProperty("lead_lag"); tasks[taskIndex].TaskDependencies.Add(tasks[short.Parse(predID)], precType, lead); } } } }
/// <summary> /// A method that adds the Dependencies from RadGanttView to MS Project using a recursion /// The method gets the Dependencies from an IGanttTask and adds them as LinkPredecessors collection of MS Project Task. /// </summary> /// <param name="tasks">A collection of MS Project Tasks.</param> /// <param name="ganttTasks">A collection of IGanttTasks.</param> private void FillTasksWithDependencies(IEnumerable <Task> tasks, IEnumerable <IGanttTask> ganttTasks) { foreach (GanttTask currentGanttTask in ganttTasks) { if (currentGanttTask.Dependencies.Count > 0) { var msProjectTask = tasks.Where(a => a.Name.Equals(this.ReplaceInvalidCharacters(currentGanttTask.Title))).FirstOrDefault(); if (msProjectTask != null) { foreach (var dependentTask in currentGanttTask.Dependencies) { var dependentTaskInMsProject = tasks.Where(a => a.Name.Equals(this.ReplaceInvalidCharacters(dependentTask.FromTask.Title))).FirstOrDefault(); if (dependentTaskInMsProject != null) { PjTaskLinkType taskPjType = default(PjTaskLinkType); switch (dependentTask.Type) { case DependencyType.FinishFinish: taskPjType = PjTaskLinkType.pjFinishToFinish; break; case DependencyType.FinishStart: taskPjType = PjTaskLinkType.pjFinishToStart; break; case DependencyType.StartFinish: taskPjType = PjTaskLinkType.pjStartToFinish; break; case DependencyType.StartStart: taskPjType = PjTaskLinkType.pjStartToStart; break; } msProjectTask.LinkPredecessors(dependentTaskInMsProject, taskPjType, Type.Missing); } } } } if (currentGanttTask.Children.Count > 0) { this.FillTasksWithDependencies(tasks, currentGanttTask.Children); } } }
public void DownloadProject(Project activeProject, string projectId) { var ap = activeProject; // first call server method to get an ordered list of project rows Item z = InnovatorManager.Instance.CreateNewItem("Project", "select_project_tree"); //Item z = innov.newItem("Project", "select_project_tree"); //string this_project_id = dd_projects.SelectedItem.Tag.ToString(); //"5266E1D280F84861A1BBCF5E50A9C65B"; z.setID(projectId); Item tree = z.apply(); if (tree.isError()) { MessageBox.Show("Error getting Project Tree"); return; } // create a dictionary object to convert ids to row numbers // using key=id, value= row number Dictionary <string, string> d = new Dictionary <string, string>(); var at = ap.Tasks; var r = ap.Resources; var u = 1; // counter for unknown assigments // populate the MSProject and dictionary object for (var x = 1; x < tree.getItemCount(); x++) { Item task = tree.getItemByIndex(x); d.Add(task.getProperty("id"), (Int16.Parse(task.getProperty("n")) - 1).ToString()); at.Add(task.getProperty("name")); int lev = Int16.Parse(task.getProperty("l")); if (lev > at[x].OutlineLevel) { at[x].OutlineIndent(); } else { while (at[x].OutlineLevel > lev) { at[x].OutlineOutdent(); } } switch (task.getType()) { case "W": Item wbs = InnovatorManager.Instance.CreateNewItem("WBS Element", "get"); wbs.setID(task.getProperty("id")); wbs = wbs.apply(); break; case "A": Item act = InnovatorManager.Instance.CreateNewItem("Activity2", "get"); act.setID(task.getProperty("id")); var assts = InnovatorManager.Instance.CreateNewItem("Activity2 Assignment", "get"); assts.setAttribute("select", "role,related_id,percent_load,work_est"); assts.setAttribute("related_expand", "0"); act.addRelationship(assts); act = act.apply(); at[x].Duration = act.getProperty("expected_duration"); at[x].Start = InnovatorManager.Instance.InnovatorDateToLocalDate(act.getProperty("date_due_sched")); at[x].Finish = InnovatorManager.Instance.InnovatorDateToLocalDate(act.getProperty("date_due_sched")); at[x].Estimated = false; var res = act.getItemsByXPath("//Item[@type='Activity2 Assignment']"); for (var y = 0; y < res.getItemCount(); y++) { string name = res.getItemByIndex(y).getPropertyAttribute("related_id", "keyed_name"); if (string.IsNullOrEmpty(name)) { name = res.getItemByIndex(y).getProperty("role", "Unknown"); if (name == "Unknown") { name += u; u += 1; } } var units = res.getItemByIndex(y).getProperty("percent_load"); try { var n = r[name]; } catch (System.Exception ex) { r.Add(name); } at[x].Assignments.Add(at[x].ID, r[name].ID); } break; } } // traverse tasks again, the first time there could have been predecessors not created yet for (int x = 1; x < tree.getItemCount(); x++) { Item task = tree.getItemByIndex(x); if (task.getType() == "A") { Item act = InnovatorManager.Instance.CreateNewItem("Activity2", "get"); act.setID(task.getProperty("id")); var preds = InnovatorManager.Instance.CreateNewItem("Predecessor", "get"); preds.setAttribute("select", "related_id,precedence_type,lead_lag"); preds.setAttribute("related_expand", "0"); act.addRelationship(preds); act = act.apply(); var pred = act.getItemsByXPath("//Item[@type='Predecessor']"); for (int y = 0; y < pred.getItemCount(); y++) { string PredID = d[pred.getItemByIndex(y).getProperty("related_id")]; PjTaskLinkType precType = (PjTaskLinkType)predecessorTypes[pred.getItemByIndex(y).getProperty("precedence_type")]; var lead = pred.getItemByIndex(y).getProperty("lead_lag"); at[x].TaskDependencies.Add(at[short.Parse(PredID)], precType, lead); } } } }