Beispiel #1
0
        private WitMappingIndex BuildIndex(WorkItemStore destWIStore, IEnumerable <WorkItem> existingTargetWorkItems, WorkItemsStageConfiguration mapping)
        {
            var index = new WitMappingIndex();

            if (mapping.HasIndex)
            {
                if (!System.IO.File.Exists(mapping.IndexFile))
                {
                    //HACK on first run the file cannot exists, so create an empty one
                    index = WitMappingIndex.CreateEmpty(mapping.IndexFile);
                }
                else
                {
                    index = WitMappingIndex.Load(mapping.IndexFile, destWIStore);
                }//if
            }
            else
            {
                index.Clear();
                foreach (var targetWI in existingTargetWorkItems)
                {
                    var originatingFieldMap = mapping.FindIdFieldForTargetWorkItemType(targetWI.Type.Name);
                    var v = targetWI.Fields[originatingFieldMap.Destination].Value;
                    // could be that the destination exists, with no origin (e.g. manual intervention)
                    int originatingId = (int)(v ?? 0);
                    index.Add(originatingId, targetWI);
                } //for
            }     //if

            return(index);
        }
        public static WitMappingIndex CreateEmpty(string pathToDataFile)
        {
            var mapping = new WitMappingIndex();

            mapping.Save(pathToDataFile);
            return(mapping);
        }
Beispiel #3
0
        private List <WorkItem> ExamineSaveErrors(BatchSaveError[] errors, WitMappingIndex index)
        {
            // log what failed
            var failedWorkItems = new List <WorkItem>();

            foreach (var err in errors)
            {
                failedWorkItems.Add(err.WorkItem);
                eventSink.SaveError(err.Exception, err.WorkItem);
                foreach (Field f in err.WorkItem.Fields)
                {
                    if (!f.IsValid)
                    {
                        eventSink.SaveErrorInvalidField(err.WorkItem, f);
                    }
                }//for
                saveErrors++;

                // ChangeLog also
                int targetId = err.WorkItem.IsNew ? err.WorkItem.TemporaryId : err.WorkItem.Id;
                this.ChangeLog.AddEntry(
                    new WorkItemFailureEntry(
                        index.GetSourceIdFromTargetId(targetId),
                        targetId,
                        err.Exception.Message));
            }//for
            return(failedWorkItems);
        }
Beispiel #4
0
        private List <WorkItem> SaveWorkItems(WorkItemsStageConfiguration mapping, WitMappingIndex index, WorkItemStore destWIStore, List <WorkItem> changedWorkItems, bool testOnly)
        {
            var failedWorkItems = new List <WorkItem>();

            if (testOnly)
            {
                eventSink.SavingSkipped();
            }
            else
            {
                var errors = destWIStore.BatchSave(changedWorkItems.ToArray(), SaveFlags.MergeAll);
                failedWorkItems = ExamineSaveErrors(errors, index);
            }//if

            var validWorkItems = changedWorkItems.Except(failedWorkItems);

            // some succeeded: their Ids could be changed, so refresh index
            if (!testOnly)
            {
                UpdateIndex(index, validWorkItems, mapping);
                foreach (var item in validWorkItems)
                {
                    this.ChangeLog.AddEntry(
                        new WorkItemChangeEntry(
                            index.GetSourceIdFromTargetId(item.Id),
                            item.Id,
                            item.IsNew ? WorkItemChangeEntry.Change.New : WorkItemChangeEntry.Change.Update));
                } //for
            }     //if

            return(validWorkItems.ToList());
        }
Beispiel #5
0
        private void SaveWorkItems3Passes(WorkItemsStageConfiguration mapping, WitMappingIndex index, bool testOnly, WorkItemStore destWIStore, List <WorkItem> newWorkItems, List <WorkItem> updatedWorkItems, List <WorkItem> validWorkItems)
        {
            eventSink.SaveFirstPassSavingNewWorkItems(newWorkItems);
            //HACK: force all new workitems to the Initial state
            var realStates = new Dictionary <WorkItem, string>();

            newWorkItems.ForEach(w =>
            {
                realStates.Add(w, w.State);
                w.State = GetInitialState(w);
            });
            validWorkItems.AddRange(SaveWorkItems(mapping, index, destWIStore, newWorkItems, testOnly));

            eventSink.SaveSecondPassUpdatingNewWorkItemsState(newWorkItems);
            // and now update the no-more-new WI with the real state
            newWorkItems.ForEach(w =>
            {
                w.State = realStates[w];
            });
            validWorkItems.AddRange(SaveWorkItems(mapping, index, destWIStore, newWorkItems, testOnly));

            eventSink.SaveThirdPassSavingUpdatedWorkItems(updatedWorkItems);
            // existing WI do not need tricks
            validWorkItems.AddRange(SaveWorkItems(mapping, index, destWIStore, updatedWorkItems, testOnly));
        }
Beispiel #6
0
 internal SyncContext(SyncContext rhs)
 {
     this.sourceConnection  = rhs.sourceConnection;
     this.sourceWIStore     = rhs.sourceWIStore;
     this.sourceProjectName = rhs.sourceProjectName;
     this.destWIStore       = rhs.destWIStore;
     this.destProjectName   = rhs.destProjectName;
     this.mapping           = rhs.mapping;
     this.index             = rhs.index;
     this.eventSink         = rhs.eventSink;
 }
Beispiel #7
0
 internal SyncContext(TfsConnection sourceConnection, WorkItemStore sourceWIStore, string sourceProjectName, WorkItemStore destWIStore, string destProjectName, WorkItemsStageConfiguration mapping, WitMappingIndex index, IEngineEvents eventSink)
 {
     this.sourceConnection  = sourceConnection;
     this.sourceWIStore     = sourceWIStore;
     this.sourceProjectName = sourceProjectName;
     this.destWIStore       = destWIStore;
     this.destProjectName   = destProjectName;
     this.mapping           = mapping;
     this.index             = index;
     this.eventSink         = eventSink;
 }
Beispiel #8
0
 private void SaveLinks(WorkItemsStageConfiguration mapping, WitMappingIndex index, WorkItemStore destWIStore, IEnumerable <WorkItem> changedWorkItems, bool testOnly)
 {
     if (testOnly)
     {
         eventSink.SavingSkipped();
     }
     else
     {
         var errors = destWIStore.BatchSave(changedWorkItems.ToArray(), SaveFlags.MergeAll);
         ExamineSaveErrors(errors, index);
     }//if
 }
        public static WitMappingIndex Load(string pathToDataFile, WorkItemStore store)
        {
            using (var reader = new XmlTextReader(pathToDataFile))
            {
                var mapping = new WitMappingIndex();

                LoadIndex(reader, "ForwardIndex", mapping.ForwardIndex);
                LoadIndex(reader, "BackwardIndex", mapping.BackwardIndex);

                mapping.Rebuild(store);

                return(mapping);
            }//using
        }
Beispiel #10
0
 private void UpdateIndex(WitMappingIndex index, IEnumerable <WorkItem> updatedWorkItems, WorkItemsStageConfiguration mapping)
 {
     if (mapping.HasIndex)
     {
         index.Update(updatedWorkItems);
         index.Save(mapping.IndexFile);
     }
     else
     {
         foreach (var dst in updatedWorkItems)
         {
             var originatingFieldMap = mapping.FindIdFieldForTargetWorkItemType(dst.Type.Name);
             int originatingId       = (int)dst.Fields[originatingFieldMap.Destination].Value;
             index.Update(originatingId, dst);
         }//for
     }
 }