/// <inheritdoc/>
        public TfsWorkItem GetWorkItemForIssue(string issueId, int issueActivityCount)
        {
            bool isNew = false;

            if (string.IsNullOrEmpty(issueId))
            {
                throw new ArgumentNullException(nameof(issueId));
            }

            if (this.parentWorkItemId == -1)
            {
                throw new Exception("Please run ConfigureAsync first.");
            }

            var hasChange      = false;
            var parentWorkItem = this.workItems.Single(w => w.Id == this.parentWorkItemId);

            string[] commentParts = null;
            var      workItemLink = parentWorkItem.Links.FirstOrDefault(l =>
            {
                if (l.Comment.StartsWith(issueId))
                {
                    commentParts = l.Comment.Split(':');
                    return(true);
                }

                return(false);
            });
            InMemoryWorkItem workItem = null;

            if (workItemLink != null)
            {
                if (!commentParts[1].Equals(issueActivityCount.ToString(CultureInfo.InvariantCulture)))
                {
                    hasChange = true;
                }

                workItem = this.workItems.Single(w => w.Id == workItemLink.RelatedWorkItemId);
            }
            else
            {
                workItem  = new InMemoryWorkItem();
                hasChange = true;
                isNew     = true;
            }

            var issueSignature = $"{issueId}:{issueActivityCount}";
            var imtw           = new InMemoryTfsWorkItem(workItem)
            {
                HasChange = hasChange, IssueSignature = issueSignature
            };

            imtw.IsNew = isNew;
            return(imtw);
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public TfsWorkItem GetWorkItemForIssue(string issueId, int issueActivityCount)
        {
            bool isNew = false;
            if (string.IsNullOrEmpty(issueId))
            {
                throw new ArgumentNullException(nameof(issueId));
            }

            if (this.parentWorkItemId == -1)
            {
                throw new Exception("Please run ConfigureAsync first.");
            }

            var hasChange = false;
            var parentWorkItem = this.workItems.Single(w => w.Id == this.parentWorkItemId);
            string[] commentParts = null;
            var workItemLink = parentWorkItem.Links.FirstOrDefault(l =>
                {
                    if (l.Comment.StartsWith(issueId))
                    {
                        commentParts = l.Comment.Split(':');
                        return true;
                    }

                    return false;
                });
            InMemoryWorkItem workItem = null;
            if (workItemLink != null)
            {
                if (!commentParts[1].Equals(issueActivityCount.ToString(CultureInfo.InvariantCulture)))
                {
                    hasChange = true;
                }

                workItem = this.workItems.Single(w => w.Id == workItemLink.RelatedWorkItemId);
            }
            else
            {
                workItem = new InMemoryWorkItem();
                hasChange = true;
                isNew = true;
            }

            var issueSignature = $"{issueId}:{issueActivityCount}";
            var imtw= new InMemoryTfsWorkItem(workItem) { HasChange = hasChange, IssueSignature = issueSignature };
            imtw.IsNew = isNew;
            return imtw;
        }