public MergeTask CreateMergeTask(IWorkItem parent, string taskTitle) { var tfs = TfsTeamDataAccess.GetTfsTeamProjectCollection(); var store = tfs.GetService <WorkItemStore>(); var project = store.Projects[parent.Type.Project.Name]; var taskType = project.WorkItemTypes["Task"]; var hierarchyLinkType = store.WorkItemLinkTypes[CoreLinkTypeReferenceNames.Hierarchy]; var tfsParent = GetTfsWorkItem(parent.Id); if (tfsParent == null) { return(null); } var existing = (from WorkItemLink l in tfsParent.WorkItemLinks select l).ToList() .Find(p => p.LinkTypeEnd.Name == "Child" && GetTfsWorkItem(p.TargetId).Title == taskTitle); if (existing != null) { var tfsExistingWorkItem = GetTfsWorkItem(existing.TargetId); return(new MergeTask(MapWorkItem(tfsExistingWorkItem)) { Parent = MapWorkItem(tfsParent) }); } var task = new TfsWorkItem(taskType) { Title = taskTitle }; task.Fields["Assigned To"].Value = "Jill LaMay"; // todo: get identity task.Links.Add(new WorkItemLink(hierarchyLinkType.ReverseEnd, parent.Id)); // Check for data script and tag. var changesets = TfsSourceDataAccess.GetTfsChangesetsByPathName(tfs, tfsParent, "Data Scripts").ToList(); // todo: not hard code. obvs. if (changesets.Any()) { changesets.SelectMany(s => s.Changes).GroupBy(g => g.Item.ServerItem).ToList().ForEach(f => { var descr = string.Format("{0} Data Script: {1};", task.Fields["Description"].Value, f.First().Item.ServerItem); task.Title = descr; // temp }); //task.Fields["Tags"].Value = "data-script"; // todo: Not in 2012 :( } // todo: turn off save while testing //task.Save(); //task.State = "Active"; //task.Save(); return(new MergeTask(MapWorkItem(task)) { Parent = parent }); }
public IEnumerable <MergeTask> GetWorkItemsWithMigrationScripts(Project project, string state) { var tfs = TfsTeamDataAccess.GetTfsTeamProjectCollection(); var tasks = new List <MergeTask>(); var workItems = GetWorkItemsByState(project, state); workItems.ToList().ForEach(workItem => { var tfsWorkItem = GetTfsWorkItem(workItem.Id); // Check for data script and tag. var changesets = TfsSourceDataAccess.GetTfsChangesetsByPathName(tfs, tfsWorkItem, "Data Scripts").ToList(); // todo: not hard code. obvs. if (changesets.Any()) { tasks.AddRange(changesets.SelectMany(s => s.Changes).GroupBy(g => g.Item.ServerItem).Select(change => new MergeTask { Title = string.Format("Execute Data Script: {0};", change.First().Item.ServerItem), Parent = workItem })); } }); return(tasks); }