private ExecutionItem TransformToExecutionItem(RevisionReference revRef) { var item = _context.GetItem(revRef.OriginId); var rev = item.Revisions[revRef.RevIndex]; rev.Time = revRef.Time; return(new ExecutionItem() { OriginId = item.OriginId, WiId = item.WiId, WiType = item.Type, Revision = rev }); }
public bool ImportRevision(WiRevision rev, WorkItem wi) { var incomplete = false; try { if (rev.Index == 0) { EnsureClassificationFields(rev); } EnsureDateFields(rev, wi); EnsureAuthorFields(rev); EnsureAssigneeField(rev, wi); EnsureFieldsOnStateChange(rev, wi); var attachmentMap = new Dictionary <string, Attachment>(); if (rev.Attachments.Any() && !ApplyAttachments(rev, wi, attachmentMap)) { incomplete = true; } if (rev.Fields.Any() && !UpdateWIFields(rev.Fields, wi)) { incomplete = true; } if (rev.Links.Any() && !ApplyLinks(rev, wi)) { incomplete = true; } if (incomplete) { Logger.Log(LogLevel.Warning, $"'{rev.ToString()}' - not all changes were saved."); } if (rev.Attachments.All(a => a.Change != ReferenceChangeType.Added) && rev.AttachmentReferences) { Logger.Log(LogLevel.Debug, $"Correcting description on '{rev.ToString()}'."); CorrectDescription(wi, _context.GetItem(rev.ParentOriginId), rev); } if (!string.IsNullOrEmpty(wi.History)) { Logger.Log(LogLevel.Debug, $"Correcting comments on '{rev.ToString()}'."); CorrectComment(wi, _context.GetItem(rev.ParentOriginId), rev); } SaveWorkItem(rev, wi); foreach (var wiAtt in rev.Attachments) { if (attachmentMap.TryGetValue(wiAtt.AttOriginId, out Attachment tfsAtt) && tfsAtt.IsSaved) { _context.Journal.MarkAttachmentAsProcessed(wiAtt.AttOriginId, tfsAtt.Id); } } if (rev.Attachments.Any(a => a.Change == ReferenceChangeType.Added) && rev.AttachmentReferences) { Logger.Log(LogLevel.Debug, $"Correcting description on separate revision on '{rev.ToString()}'."); try { if (CorrectDescription(wi, _context.GetItem(rev.ParentOriginId), rev)) { SaveWorkItem(rev, wi); } } catch (Exception ex) { Logger.Log(ex, $"Failed to correct description for '{wi.Id}', rev '{rev.ToString()}'."); } } _context.Journal.MarkRevProcessed(rev.ParentOriginId, wi.Id, rev.Index); Logger.Log(LogLevel.Debug, $"Imported revision."); wi.Close(); return(true); } catch (AbortMigrationException) { throw; } catch (Exception ex) { Logger.Log(ex, $"Failed to import revisions for '{wi.Id}'."); return(false); } }
public bool ImportRevision(WiRevision rev, WorkItem wi) { try { bool incomplete = false; if (rev.Index == 0) { EnsureClasificationFields(rev); } EnsureDateFields(rev); EnsureAuthorFields(rev); var attachmentMap = new Dictionary <string, Attachment>(); if (rev.Attachments.Any() && !ApplyAttachments(rev, wi, attachmentMap)) { incomplete = true; } if (rev.Fields.Any() && !UpdateWIFields(rev.Fields, wi)) { incomplete = true; } if (rev.Links.Any() && !ApplyLinks(rev, wi)) { incomplete = true; } if (incomplete) { Logger.Log(LogLevel.Warning, $"{rev.ToString()} - not all changes were implemented"); } if (!rev.Attachments.Any(a => a.Change == ReferenceChangeType.Added) && rev.AttachmentReferences) { Logger.Log(LogLevel.Info, $"Correcting description on {rev.ToString()}"); CorrectDescription(wi, _context.GetItem(rev.ParentOriginId), rev); } SaveWorkItem(rev, wi); if (rev.Attachments.Any(a => a.Change == ReferenceChangeType.Added) && rev.AttachmentReferences) { Logger.Log(LogLevel.Info, $"Correcting description on separate revision on {rev.ToString()}"); try { if (CorrectDescription(wi, _context.GetItem(rev.ParentOriginId), rev)) { SaveWorkItem(rev, wi); } } catch (Exception ex) { Logger.Log(ex); } } _context.Journal.MarkRevProcessed(rev.ParentOriginId, wi.Id, rev.Index); foreach (var wiAtt in rev.Attachments) { if (attachmentMap.TryGetValue(wiAtt.AttOriginId, out Attachment tfsAtt) && tfsAtt.IsSaved) { _context.Journal.MarkAttachmentAsProcessed(wiAtt.AttOriginId, tfsAtt.Id); } } Logger.Log(LogLevel.Info, $"Imported {rev.ToString()}"); wi.Close(); return(true); } catch (AbortMigrationException ame) { throw new AbortMigrationException(ame.Reason) { Revision = rev }; } catch (Exception ex) { Logger.Log(ex); return(false); } }