public override int Prepare(StageConfiguration configuration) { mapping = (WorkItemsStageConfiguration)configuration; Debug.Assert(mapping != null); sourceWIStore = sourceConn.Collection.GetService <WorkItemStore>(); if (mapping.Mode.HasFlag(WorkItemsStageConfiguration.Modes.BypassWorkItemStoreRules)) { eventSink.BypassingRulesOnDestinationWorkItemStore(destConn); // this will turn off validation! destWIStore = new WorkItemStore(destConn.Collection, WorkItemStoreFlags.BypassRules); } else { destWIStore = destConn.Collection.GetService <WorkItemStore>(); }//if mapping.SetDefaults(sourceConn, sourceWIStore, destConn, destWIStore); eventSink.DumpMapping(mapping); checker = new WorkItemsStageConfigurationChecker(sourceWIStore, sourceConn.ProjectName, destWIStore, destConn.ProjectName, eventSink); checker.AgnosticCheck(mapping); if (!checker.Passed) { // abort return(checker.ErrorCount); } return(0); }
private void ExecuteStages() { foreach (var stage in preparedStages) { int stageErrors = -1; try { eventSink.ExecutingStage(stage); StageConfiguration config = GetStageConfiguration(stage); config.TestOnly = configuration.TestOnly; stageErrors = stage.Execute(config); eventSink.StageCompleted(stage, stageErrors); syncErrors += stageErrors; } catch (Exception ex) { if (configuration.StopPipelineOnFirstError) { throw; } else { eventSink.StageError(stage, ex); syncErrors++; } } finally { this.changeLog.Append(stage.ChangeLog); } //try } //for }
private void PrepareStages() { preparedStages.Clear(); foreach (var stage in requestedStages) { int stageErrors = -1; try { eventSink.PreparingStage(stage); StageConfiguration config = GetStageConfiguration(stage); stageErrors = stage.Prepare(config); eventSink.StagePrepared(stage, stageErrors); // only succeeded stages will be executed preparedStages.Add(stage); } catch (Exception ex) { if (configuration.StopPipelineOnFirstError) { throw; } else { eventSink.StagePreparationError(stage, ex); } } //try } //for }
public override int Execute(StageConfiguration configuration) { var config = ((AreasAndIterationsStageConfiguration)configuration); bool areas = options.HasFlag(StageOptions.Areas); bool iterations = options.HasFlag(StageOptions.Iterations); this.testMode = configuration.TestOnly; var sourceWIStore = sourceConn.Collection.GetService <WorkItemStore>(); var destWIStore = destConn.Collection.GetService <WorkItemStore>(); var sourceProject = sourceWIStore.Projects[sourceConn.ProjectName]; var destProject = destWIStore.Projects[destConn.ProjectName]; eventSink.ReadingAreaAndIterationInfoFromSource(); sourceCSS = sourceConn.Collection.GetService <ICommonStructureService4>(); destCSS = destConn.Collection.GetService <ICommonStructureService4>(); foreach (NodeInfo info in destCSS.ListStructures(destProject.Uri.ToString())) { if (info.StructureType == "ProjectModelHierarchy") { rootAreaNode = info; } else if (info.StructureType == "ProjectLifecycle") { rootIterationNode = info; } } if (areas) { eventSink.SyncingAreas(); SyncNodes(sourceProject.AreaRootNodes); } if (iterations) { eventSink.SyncingIterations(); SyncNodes(sourceProject.IterationRootNodes); } return(saveErrors); }
public override int Execute(StageConfiguration configuration) { mapping = (GlobalListsStageConfiguration)configuration; var sourceWIStore = sourceConn.Collection.GetService <WorkItemStore>(); var destWIStore = destConn.Collection.GetService <WorkItemStore>(); var updateList = new List <XmlElement>(); eventSink.ReadingGlobalListsFromSource(); // get Global Lists from TFS collection var sourceGL = sourceWIStore.ExportGlobalLists(); eventSink.SelectingGlobalLists(); // read the XML and get only the GLOBALLIST element. foreach (XmlElement glElement in sourceGL.GetElementsByTagName("GLOBALLIST")) { string glName = glElement.Attributes["name"].Value.ToString(); if (mapping.IsIncluded(glName)) { eventSink.GlobalListQueuedForUpdate(glName); // queue updateList.Add(glElement); } //if } //for list eventSink.BuildingGlobalListUpdateMessage(); XmlDocument updateDoc = new XmlDocument(); XmlProcessingInstruction _xmlProcessingInstruction; _xmlProcessingInstruction = updateDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='utf-8'"); updateDoc.AppendChild(_xmlProcessingInstruction); XmlElement updateRoot = updateDoc.CreateElement("gl", "GLOBALLISTS", "http://schemas.microsoft.com/VisualStudio/2005/workitemtracking/globallists"); foreach (var glSourceElement in updateList) { var glUpdateElement = updateDoc.ImportNode(glSourceElement, true); updateRoot.AppendChild(glUpdateElement); }//for updateDoc.AppendChild(updateRoot); eventSink.UpdatingGlobalListsOnDestination(); if (!configuration.TestOnly) { destWIStore.ImportGlobalLists(updateDoc.InnerXml); foreach (var glSourceElement in updateList) { string glName = glSourceElement.Attributes["name"].Value.ToString(); this.ChangeLog.AddEntry(new GlobalListChangeEntry(glName)); }//for } eventSink.GlobalListsUpdated(); return(saveErrors); }
public override int Prepare(StageConfiguration configuration) { mapping = (GlobalListsStageConfiguration)configuration; return(0); }
public override int Prepare(StageConfiguration configuration) { return(0); }
public override int Execute(StageConfiguration configuration) { mapping = (WorkItemsStageConfiguration)configuration; var sourceRunner = new QueryRunner(sourceWIStore, sourceConn.ProjectName); eventSink.ExecutingSourceQuery(mapping.SourceQuery, sourceConn); var sourceResult = sourceRunner.RunQuery(mapping.SourceQuery); if (sourceResult == null) { eventSink.SourceQueryNotFound(mapping.SourceQuery); return(3); } var destRunner = new QueryRunner(destWIStore, destConn.ProjectName); eventSink.ExecutingDestinationQuery(mapping.DestinationQuery, destConn); var destResult = destRunner.RunQuery(mapping.DestinationQuery); if (destResult == null) { eventSink.DestinationQueryNotFound(mapping.DestinationQuery); return(4); } // use query data for more thorough checks checker.Check(sourceResult, mapping, destResult); if (!checker.Passed) { // abort return(checker.ErrorCount); } // this needs also connection to target, better after query execution, so we have warm caches var index = BuildIndex(destWIStore, destResult.WorkItems.Values, mapping); var context = new SyncContext(sourceConn, sourceWIStore, sourceConn.ProjectName, destWIStore, destConn.ProjectName, mapping, index, eventSink); var workItemMapper = new WorkItemMapper(context); // configure options workItemMapper.UseEditableProperty = mapping.Mode.HasFlag(WorkItemsStageConfiguration.Modes.UseEditableProperty); workItemMapper.OpenTargetWorkItem = mapping.Mode.HasFlag(WorkItemsStageConfiguration.Modes.OpenTargetWorkItem); workItemMapper.PartialOpenTargetWorkItem = mapping.Mode.HasFlag(WorkItemsStageConfiguration.Modes.PartialOpenTargetWorkItem); List <WorkItem> newWorkItems; List <WorkItem> updatedWorkItems; workItemMapper.MapWorkItems(sourceResult, destResult, out newWorkItems, out updatedWorkItems); // from http://social.msdn.microsoft.com/Forums/vstudio/en-US/0cbc378b-09ad-4899-865d-b418aecb8375/work-item-links-error-message-unexplained // "It happens when you add a link when you are creating a new work item. If you add the link after the new work item is saved then it works OK." eventSink.SavingWorkItems(newWorkItems, updatedWorkItems); var validWorkItems = new List <WorkItem>(); if (mapping.Mode.HasFlag(WorkItemsStageConfiguration.Modes.CreateThenUpdate)) { // uncommon path eventSink.UsingThreePassSavingAlgorithm(); SaveWorkItems3Passes(mapping, index, configuration.TestOnly, destWIStore, newWorkItems, updatedWorkItems, validWorkItems); // multi-pass records the same WI object multiple times validWorkItems = validWorkItems.DistinctBy(x => x.Id, null).ToList(); } else { // normal path var changedWorkItems = newWorkItems.Concat(updatedWorkItems).ToList(); var savedWorkItems = SaveWorkItems(mapping, index, destWIStore, changedWorkItems, configuration.TestOnly); validWorkItems.AddRange(savedWorkItems); }//if workItemMapper.CleanUp(); var linkMapper = new LinkMapper(context); var changedLinks = linkMapper.MapLinks(sourceResult.WorkItems.Values, validWorkItems); eventSink.SavingLinks(changedLinks, validWorkItems); SaveLinks(mapping, index, destWIStore, validWorkItems, configuration.TestOnly); return(saveErrors); }
abstract public int Execute(StageConfiguration configuration);
abstract public int Prepare(StageConfiguration configuration);