Пример #1
0
 public WorkItemStore(EngineContext context, WorkItem workItem) : this(context)
 {
     //initialize tracker with initial work item
     var wrapper = new WorkItemWrapper(_context, workItem);
     //store event initiator identity
     _triggerIdentity = wrapper.ChangedBy;
 }
Пример #2
0
 internal void TrackExisting(WorkItemWrapper workItemWrapper)
 {
     if (IsTracked(workItemWrapper))
     {
         throw new InvalidOperationException($"Work item {workItemWrapper.Id} is already tracked");
     }
     TrackNew(workItemWrapper);
 }
Пример #3
0
 internal WorkItemRelationWrapperCollection(WorkItemWrapper workItem, IList <WorkItemRelation> relations)
 {
     _pivotWorkItem = workItem;
     _original      = relations == null
         ? new List <WorkItemRelationWrapper>()
         : new List <WorkItemRelationWrapper>(relations.Select(relation =>
                                                               new WorkItemRelationWrapper(_pivotWorkItem, relation)));
 }
Пример #4
0
 internal void TrackRevision(WorkItemWrapper workItemWrapper)
 {
     if (!tracked.ContainsKey(workItemWrapper.Id))
     {
         // should never happen...
         throw new InvalidOperationException($"Work item {workItemWrapper.Id} was never loaded");
     }
     tracked[workItemWrapper.Id].Revisions.Add(workItemWrapper.Rev, workItemWrapper);
 }
 internal WorkItemRelationWrapperCollection(WorkItemWrapper workItem, IList <WorkItemRelation> relations)
 {
     _pivotWorkItem = workItem;
     _original      = relations == null
         ? new List <WorkItemRelationWrapper>()
         : new List <WorkItemRelationWrapper>(relations.Select(relation =>
                                                               new WorkItemRelationWrapper(_pivotWorkItem, relation)));
     // do we need deep cloning?
     _current = new List <WorkItemRelationWrapper>(_original);
 }
Пример #6
0
 internal WorkItemRelationWrapper(WorkItemWrapper item, string type, string url, string comment)
 {
     _item     = item;
     _relation = new WorkItemRelation()
     {
         Rel        = type,
         Url        = url,
         Attributes = { { "comment", comment } }
     };
 }
Пример #7
0
        internal void TrackExisting(WorkItemWrapper workItemWrapper)
        {
            if (IsTracked(workItemWrapper))
            {
                throw new InvalidOperationException($"Work item {workItemWrapper.Id} is already tracked");
            }
            var t = new TrackedWrapper(workItemWrapper.Id.Value, workItemWrapper);

            tracked.Add(workItemWrapper.Id, t);
        }
Пример #8
0
        internal WorkItemRelationWrapperCollection(WorkItemWrapper workItem, IList <WorkItemRelation> relations)
        {
            _pivotWorkItem = workItem;
            _original      = relations == null
                ? new List <WorkItemRelationWrapper>()
                : relations.Where(relation => relation.Rel.StartsWith("System.LinkType"))
                             .Select(relation => new WorkItemRelationWrapper(relation))
                             .ToList();

            // do we need deep cloning?
            _current = new List <WorkItemRelationWrapper>(_original);
        }
Пример #9
0
 internal void TrackRevision(WorkItemWrapper workItemWrapper)
 {
     if (tracked.TryGetValue(workItemWrapper.Id, out var value))
     {
         value.Revisions.Add(workItemWrapper.Rev, workItemWrapper);
     }
     else
     {
         // should never happen...
         throw new InvalidOperationException($"Work item {workItemWrapper.Id} was never loaded");
     }
 }
Пример #10
0
        private static bool ChangeRecycleStatus(WorkItemWrapper workItem, RecycleStatus toRecycleStatus)
        {
            if ((toRecycleStatus == RecycleStatus.ToDelete && workItem.IsDeleted) ||
                (toRecycleStatus == RecycleStatus.ToRestore && !workItem.IsDeleted))
            {
                return(false);
            }

            var previousStatus = workItem.RecycleStatus;

            workItem.RecycleStatus = toRecycleStatus;

            var updated = previousStatus != workItem.RecycleStatus;

            workItem.IsDirty = updated || workItem.IsDirty;
            return(updated);
        }
Пример #11
0
        public WorkItemWrapper(EngineContext context, WorkItemWrapper template, string type)
        {
            _context = context.Track(this);

            Id = new TemporaryWorkItemId();

            _item = new WorkItem();
            _item.Fields[CoreFieldRefNames.TeamProject]  = template.TeamProject;
            _item.Fields[CoreFieldRefNames.WorkItemType] = type;
            _item.Fields[CoreFieldRefNames.Id]           = Id.Value;

            Changes.Add(new JsonPatchOperation()
            {
                Operation = Operation.Test,
                Path      = "/id",
                Value     = Id
            });
        }
Пример #12
0
        public WorkItemWrapper(EngineContext context, WorkItemWrapper template, string type)
        {
            _context = context;

            Id = new TemporaryWorkItemId(_context.Tracker);

            _item = new WorkItem();
            _item.Fields[CoreFieldRefNames.TeamProject]  = template.TeamProject;
            _item.Fields[CoreFieldRefNames.WorkItemType] = type;
            _item.Fields[CoreFieldRefNames.Id]           = Id.Value;
            _relationCollection = new WorkItemRelationWrapperCollection(this, _item.Relations);

            Changes.Add(new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/id",
                Value     = Id.Value
            });
            _context.Tracker.TrackNew(this);
        }
Пример #13
0
        public WorkItemWrapper NewWorkItem(string workItemType)
        {
            var item = new WorkItem()
            {
                Fields = new Dictionary <string, object>()
                {
                    { CoreFieldRefNames.WorkItemType, workItemType },
                    { CoreFieldRefNames.TeamProject, _context.ProjectId.ToString() }
                },
                Relations = new List <WorkItemRelation>(),
                Links     = new Microsoft.VisualStudio.Services.WebApi.ReferenceLinks()
            };
            var wrapper = new WorkItemWrapper(_context, item);

            _context.Logger.WriteVerbose($"Made new workitem with temporary id {wrapper.Id.Value}");
            //HACK
            string baseUriString = _context.Client.BaseAddress.AbsoluteUri;

            item.Url = $"{baseUriString}/_apis/wit/workitems/{wrapper.Id.Value}";
            return(wrapper);
        }
Пример #14
0
        public WorkItemWrapper NewWorkItem(string workItemType, string projectName = null)
        {
            // TODO check workItemType and projectName values by querying AzDO
            var item = new WorkItem
            {
                Fields = new Dictionary <string, object>
                {
                    { CoreFieldRefNames.WorkItemType, workItemType },
                    { CoreFieldRefNames.TeamProject, projectName ?? _context.ProjectName }
                },
                Relations = new List <WorkItemRelation>(),
                Links     = new Microsoft.VisualStudio.Services.WebApi.ReferenceLinks()
            };
            var wrapper = new WorkItemWrapper(_context, item);

            _context.Logger.WriteVerbose($"Made new workitem in {wrapper.TeamProject} with temporary id {wrapper.Id}");
            //HACK
            string baseUriString = _clients.WitClient.BaseAddress.AbsoluteUri;

            item.Url = FormattableString.Invariant($"{baseUriString}/_apis/wit/workitems/{wrapper.Id}");
            return(wrapper);
        }
Пример #15
0
        internal void TrackNew(WorkItemWrapper workItemWrapper)
        {
            var t = new TrackedWrapper(workItemWrapper.Id.Value, workItemWrapper);

            tracked.Add(workItemWrapper.Id, t);
        }
Пример #16
0
 internal WorkItemRelationWrapper(WorkItemWrapper item, WorkItemRelation relation)
 {
     _item     = item;
     _relation = relation;
 }
Пример #17
0
 internal TrackedWrapper(int id, WorkItemWrapper wrapper)
 {
     Id      = id;
     Current = wrapper;
 }
 public void AddRelatedLink(WorkItemWrapper item, string comment = null)
 {
     AddRelatedLink(item.Url, comment);
 }
        public void AddChild(WorkItemWrapper child)
        {
            var r = new WorkItemRelationWrapper(child, CoreRelationRefNames.Children, child.Url, string.Empty);

            AddRelation(r);
        }
        public void AddParent(WorkItemWrapper parent)
        {
            var r = new WorkItemRelationWrapper(parent, CoreRelationRefNames.Parent, parent.Url, string.Empty);

            AddRelation(r);
        }
Пример #21
0
 internal EngineContext Track(WorkItemWrapper workItemWrapper)
 {
     wrappers.Add(workItemWrapper);
     return(this);
 }
Пример #22
0
        public bool RestoreWorkItem(WorkItemWrapper workItem)
        {
            _context.Logger.WriteVerbose($"Mark workitem for Restire {workItem.Id}");

            return(ChangeRecycleStatus(workItem, RecycleStatus.ToRestore));
        }
Пример #23
0
        public bool DeleteWorkItem(WorkItemWrapper workItem)
        {
            _context.Logger.WriteVerbose($"Mark workitem for Delete {workItem.Id}");

            return(ChangeRecycleStatus(workItem, RecycleStatus.ToDelete));
        }
Пример #24
0
 internal bool IsTracked(WorkItemWrapper workItemWrapper)
 {
     return(tracked.ContainsKey(workItemWrapper.Id));
 }
Пример #25
0
 public WorkItemStore(EngineContext context, WorkItem workItem) : this(context)
 {
     //initialize tracker with initial work item
     _ = new WorkItemWrapper(_context, workItem);
 }