Пример #1
0
        public void DeleteRelatedWorkItemLink(int workItemId, int relatedWorkItemId)
        {
            string  condition = String.Format("[System.Id] = {0}", workItemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem wi = util.WorkItems[0];

            wi.Open();

            RelatedLink link = null;

            foreach (Link l in wi.Links)
            {
                RelatedLink rl = l as RelatedLink;

                if (rl != null)
                {
                    // v1 work item related link does not have direction info
                    // to avoid generating two link change actions for the same link
                    // we only pick one from the work item of smaller id
                    if (rl.RelatedWorkItemId == relatedWorkItemId)
                    {
                        link = rl;
                        break;
                    }
                }
            }

            Debug.Assert(link != null, "link is null");
            wi.Links.Remove(link);

            wi.Save();
        }
Пример #2
0
        public int GetAttachmentCount(int workitemId)
        {
            string  condition = String.Format("[System.Id] = {0}", workitemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem wi = util.WorkItems[0];

            return(wi.AttachedFileCount);
        }
Пример #3
0
        public string GetFieldValue(int workItemId, string fieldName)
        {
            string  condition = String.Format("[System.Id] = {0}", workItemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem wi = util.WorkItems[0];

            return(wi.Fields[fieldName].Value.ToString());
        }
Пример #4
0
        public void AddRelatedWorkItemLink(int workItemId, int relatedWorkItemId)
        {
            string  condition = String.Format("[System.Id] = {0}", workItemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem wi = util.WorkItems[0];

            wi.Open();

            RelatedLink link = new RelatedLink(relatedWorkItemId);

            wi.Links.Add(link);

            wi.Save();
        }
Пример #5
0
        public void UpdateWorkItem(int workItemId, WITChangeAction action)
        {
            string  condition = String.Format("[System.Id] = {0}", workItemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem wi = util.WorkItems[0];

            wi.Open();

            if (!String.IsNullOrEmpty(action.Title))
            {
                wi.Title = action.Title;
            }

            if (!String.IsNullOrEmpty(action.Description))
            {
                wi.Description = action.Description;
            }

            if (!String.IsNullOrEmpty(action.History))
            {
                wi.History = action.History;
            }

            if (!String.IsNullOrEmpty(action.Reason))
            {
                wi.Reason = action.Reason;
            }

            if (!String.IsNullOrEmpty(action.Priority))
            {
                wi.Fields[FIELD_PRIORITY].Value = action.Priority;
            }

            if (!String.IsNullOrEmpty(action.AssignedTo))
            {
                wi.Fields[FIELD_ASSIGNEDTO].Value = action.AssignedTo;
            }

            ArrayList invalidFields = wi.Validate();

            if (invalidFields.Count != 0)
            {
                Assert.Fail("Failed to update work item: {0}", wi.Id);
            }

            wi.Save();
        }
Пример #6
0
        public WITLink GetHyperLink(int workItemId, string location)
        {
            string  condition = String.Format("[System.Id] = {0}", workItemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem  wi      = util.WorkItems[0];
            Hyperlink link    = FindHyperLink(location, wi.Links);
            WITLink   witLink = null;

            if (link != null)
            {
                witLink = new WITLink(link.Location, link.Comment);
            }

            return(witLink);
        }
Пример #7
0
        public void UpdateWorkItemLink(int workItemId, WITLinkChangeAction action)
        {
            string  condition = String.Format("[System.Id] = {0}", workItemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem wi = util.WorkItems[0];

            wi.Open();

            foreach (WITLink witlink in action.Links)
            {
                // Support only Hyperlink
                Hyperlink link = new Hyperlink(witlink.Location);
                link.Comment = witlink.Comment;

                if (action.ActionType == LinkChangeActionType.Add)
                {
                    wi.Links.Add(link);
                }
                else if (action.ActionType == LinkChangeActionType.Delete)
                {
                    Link linkToDelete = FindHyperLink(link.Location, wi.Links);
                    if (linkToDelete != null)
                    {
                        wi.Links.Remove(linkToDelete);
                    }
                }
                // Update link's comment
                else if (action.ActionType == LinkChangeActionType.Edit)
                {
                    Link linkToEdit = FindHyperLink(link.Location, wi.Links);
                    if (linkToEdit != null)
                    {
                        linkToEdit.Comment = link.Comment;
                    }
                }
            }

            ArrayList invalidFields = wi.Validate();

            if (invalidFields.Count != 0)
            {
                Assert.Fail("Failed to update work item: {0}", wi.Id);
            }

            wi.Save();
        }
Пример #8
0
        public void UpdateAttachment(int workItemId, WITAttachmentChangeAction action)
        {
            string  condition = String.Format("[System.Id] = {0}", workItemId);
            WITUtil util      = new WITUtil(WorkItemStore, TeamProjectName, condition, string.Empty);

            WorkItem wi = util.WorkItems[0];

            wi.Open();

            foreach (WITAttachment attachment in action.Attachments)
            {
                if (attachment.ActionType == AttachmentChangeActionType.Add)
                {
                    wi.Attachments.Add(CreateAttachment(attachment.FileName, attachment.Comment));
                }
                else if (attachment.ActionType == AttachmentChangeActionType.Delete)
                {
                    Attachment item = FindAttachment(attachment.FileName, attachment.Comment, wi.Attachments);
                    if (item != null)
                    {
                        wi.Attachments.Remove(item);
                    }
                }
                // Update attachment comment
                else if (attachment.ActionType == AttachmentChangeActionType.Edit)
                {
                    throw new NotImplementedException("EditAttachment is not supported yet");
                    //Attachment item = FindAttachment(attachment.FileName, attachment.Comment, wi.Attachments);
                    //if (item != null)
                    //{
                    // TODO: Update comment
                    // Comment is read-only
                    //item.Comment = attachment.Comment;
                    //}
                }
            }

            ArrayList invalidFields = wi.Validate();

            if (invalidFields.Count != 0)
            {
                Assert.Fail("Failed to update work item: {0}", wi.Id);
            }

            wi.Save();
        }