internal WorkItemWrapper(EngineContext context, WorkItem item) { _context = context; _item = item; _relationCollection = new WorkItemRelationWrapperCollection(this, _item.Relations); if (item.Id.HasValue) { Id = new PermanentWorkItemId(item.Id.Value); Changes.Add(new JsonPatchOperation() { Operation = Operation.Test, Path = "/rev", Value = item.Rev }); _context.Tracker.TrackExisting(this); } else { Id = new TemporaryWorkItemId(_context.Tracker); Changes.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/id", Value = Id.Value }); _context.Tracker.TrackNew(this); } }
internal void ReplaceIdAndResetChanges(int oldId, int newId) { if (oldId >= 0) { throw new ArgumentOutOfRangeException(nameof(oldId)); } Id = new PermanentWorkItemId(newId); var candidates = Changes.Where(op => op.Path == "/relations/-"); foreach (var op in candidates) { var patch = op.Value as RelationPatch; string url = patch.url; int pos = url.LastIndexOf('/') + 1; int relId = int.Parse(url.Substring(pos)); if (relId == oldId) { patch.url = url.Substring(0, pos) + newId.ToString(); break; } } Changes.RemoveAll(op => op.Path.StartsWith("/fields/") || op.Path == "/id"); }
internal WorkItemWrapper(EngineContext context, WorkItem item) { _context = context; _item = item; _originalValues = new Dictionary <string, object>(item.Fields); Relations = new WorkItemRelationWrapperCollection(this, _item.Relations); if (item.Id.HasValue) { Id = new PermanentWorkItemId(item.Id.Value); AddRevisionCheck(item, context); //for simplify testing: item.Url can be null IsDeleted = item.Url?.EndsWith($"/recyclebin/{item.Id.Value}", StringComparison.OrdinalIgnoreCase) ?? false; IsReadOnly = false; _context.Tracker.TrackExisting(this); } else { Id = new TemporaryWorkItemId(_context.Tracker); Changes.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/id", Value = Id.Value }); _context.Tracker.TrackNew(this); } }
internal WorkItemWrapper(EngineContext context, WorkItem item) { _context = context.Track(this); if (item.Id.HasValue) { Id = new PermanentWorkItemId(item.Id.Value); Changes.Add(new JsonPatchOperation() { Operation = Operation.Test, Path = "/rev", Value = item.Rev }); } else { Id = new TemporaryWorkItemId(); Changes.Add(new JsonPatchOperation() { Operation = Operation.Test, Path = "/id", Value = Id }); } _item = item; }
internal WorkItemWrapper LoadWorkItem(int id, Func <int, WorkItemWrapper> loader) { var key = new PermanentWorkItemId(id); return(tracked.ContainsKey(key) ? tracked[key].Current : loader(id)); }
internal WorkItemWrapper LoadWorkItem(int id, Func <int, WorkItemWrapper> loader) { var key = new PermanentWorkItemId(id); return(tracked.TryGetValue(key, out var value) ? value.Current : loader(id)); }
private WorkItemRelationWrapper(string relationUrl) { if (!string.IsNullOrWhiteSpace(relationUrl)) { var relationUri = new Uri(relationUrl); var id = int.Parse(relationUri.Segments.Last()); LinkedId = new PermanentWorkItemId(id); } }
internal WorkItemWrapper(EngineContext context, WorkItem item, bool isReadOnly) // we cannot reuse the code, because tracking is different //: this(context, item) { _context = context; _item = item; Relations = new WorkItemRelationWrapperCollection(this, _item.Relations); Id = new PermanentWorkItemId(item.Id.Value); AddRevisionCheck(item, context); IsDeleted = item.Url?.EndsWith($"/recyclebin/{item.Id}", StringComparison.OrdinalIgnoreCase) ?? false; IsReadOnly = isReadOnly; _context.Tracker.TrackRevision(this); }
internal WorkItemWrapper(EngineContext context, WorkItem item, bool isReadOnly) // we cannot reuse the code, because tracking is different //: this(context, item) { _context = context; Id = new PermanentWorkItemId(item.Id.Value); Changes.Add(new JsonPatchOperation() { Operation = Operation.Test, Path = "/rev", Value = item.Rev }); _isReadOnly = isReadOnly; _item = item; _relationCollection = new WorkItemRelationWrapperCollection(this, _item.Relations); _context.Tracker.TrackRevision(this); }