コード例 #1
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);
        }
コード例 #2
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());
        }