Esempio n. 1
0
        /// <summary>
        /// Updates a field in the underlying <see cref="WorkItem"/> for the <see cref="TfsWorkItem"/>.
        /// </summary>
        /// <param name="tfsWorkItem">The <see cref="TfsWorkItem"/> instance.</param>
        /// <param name="field">Name of the field.</param>
        /// <param name="value">Value for the field.</param>
        public static void UpdateField(this TfsWorkItem tfsWorkItem, string field, string value)
        {
            if (tfsWorkItem == null)
            {
                throw new ArgumentNullException(nameof(tfsWorkItem));
            }

            dynamic workItem = tfsWorkItem.Item;

            workItem[field] = value;
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public void SaveWorkItem(TfsWorkItem tfsWorkItem)
        {
            var item = tfsWorkItem.Item as WorkItem;

            if (item == null)
            {
                throw new InvalidOperationException("Invalid TfsWorkItem object.");
            }

            if (item.IsNew)
            {
                var linkType = this.workItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"];
                var link     = new WorkItemLink(linkType.ReverseEnd, this.parentWorkItem.Id)
                {
                    Comment = tfsWorkItem.IssueSignature
                };
                item.Links.Add(link);
            }
            else
            {
                foreach (var link in item.Links)
                {
                    var linkToParent = link as RelatedLink;
                    if (linkToParent != null && linkToParent.RelatedWorkItemId == this.parentWorkItem.Id)
                    {
                        linkToParent.Comment = tfsWorkItem.IssueSignature;
                    }
                }
            }
            this.logger.Debug("Added a link to parent work item with {comment}", tfsWorkItem.IssueSignature);

            foreach (Field field in item.Validate())
            {
                this.logger.Warning($"Work item field has invalid value: {field.Name}: {field.Status}");
            }

            item.Save();
            this.logger.Verbose("Saved the tfs work item. All is well!");
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public void SaveWorkItem(TfsWorkItem tfsWorkItem)
        {
            var item = tfsWorkItem.Item as WorkItem;
            if (item == null)
            {
                throw new InvalidOperationException("Invalid TfsWorkItem object.");
            }

            if (item.IsNew)
            {
                var linkType = this.workItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"];
                var link = new WorkItemLink(linkType.ReverseEnd, this.parentWorkItem.Id) { Comment = tfsWorkItem.IssueSignature };
                item.Links.Add(link);
            }
            else
            {
                foreach (var link in item.Links)
                {
                    var linkToParent = link as RelatedLink;
                    if (linkToParent != null && linkToParent.RelatedWorkItemId == this.parentWorkItem.Id)
                    {
                        linkToParent.Comment = tfsWorkItem.IssueSignature;
                    }
                }
            }
            this.logger.Debug("Added a link to parent work item with {comment}", tfsWorkItem.IssueSignature);

            foreach (Field field in item.Validate())
            {
                this.logger.Warning($"Work item field has invalid value: {field.Name}: {field.Status}");
            }

            item.Save();
            this.logger.Verbose("Saved the tfs work item. All is well!");
        }