예제 #1
0
        // / <summary>
        // / update a specific work item by id and return that changed worked item
        // / </summary>
        // / <param name="id"></param>
        // / <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemPatchResponse.WorkItem UpdateWorkItemFields(string id)
        {
            WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
            WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[4];

            // change some values on a few fields
            fields[0] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/System.History", value = "adding some history"
            };
            fields[1] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "2"
            };
            fields[2] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.BusinessValue", value = "100"
            };
            fields[3] = new WorkItemPatch.Field()
            {
                op = "add", path = "/fields/Microsoft.VSTS.Common.ValueArea", value = "Architectural"
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = _TFSOwnerProject.authorization;

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call

                // set the httpmethod to Patch
                var method = new HttpMethod("PATCH");

                // send the request
                var request = new HttpRequestMessage(method, _TFSOwnerProject.TFSUrl + "_apis/wit/workitems/" + id + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = _TFSOwnerProject.sendToTFS(client, request);

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <WorkItemPatchResponse.WorkItem>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
예제 #2
0
        public bool updateEAGUIDToTFS()
        {
            if (this.wrappedElement != null)
            {
                WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
                WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[1];

                // replace value on a field that you normally cannot change, like system.createdby
                fields[0] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/Ext_RefId", value = this.wrappedElement.uniqueID
                };

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = _TFSOwnerProject.authorization;

                    // serialize the fields array into a json string
                    var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json");     // mediaType needs to be application/json-patch+json for a patch call

                    // set the httpmethod to Patch
                    var method = new HttpMethod("PATCH");

                    // send the request
                    var request = new HttpRequestMessage(method, _TFSOwnerProject.TFSUrl + "_apis/wit/workitems/" + this.ID + "?api-version=2.2")
                    {
                        Content = patchValue
                    };
                    var response = _TFSOwnerProject.sendToTFS(client, request);

                    return(response.IsSuccessStatusCode);
                }
            }
            return(false);
        }
예제 #3
0
        public bool updateToTFS()
        {
            if (this.wrappedElement != null &&
                !string.IsNullOrEmpty(this.ID))
            {
                WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem();
                WorkItemPatch.Field[]          fields    = new WorkItemPatch.Field[7];

                fields[0] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/System.Title", value = this.title
                };
                fields[1] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/System.Description", value = this.description
                };
                fields[2] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/System.IterationPath", value = this.TFSIteration
                };
                fields[3] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/System.AreaPath", value = this.TFSArea
                };
                fields[4] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/System.AssignedTo", value = this.assignedTo
                };
                fields[5] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/Ext_RefId", value = this.wrappedElement.uniqueID
                };
                fields[6] = new WorkItemPatch.Field()
                {
                    op = "add", path = "/fields/State", value = this.wrappedElement.status
                };

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = _TFSOwnerProject.authorization;

                    // serialize the fields array into a json string
                    var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json");     // mediaType needs to be application/json-patch+json for a patch call

                    // set the httpmethod to Patch
                    var method = new HttpMethod("PATCH");

                    // send the request
                    var request = new HttpRequestMessage(method, _TFSOwnerProject.TFSUrl + "_apis/wit/workitems/" + this.ID + "?api-version=2.2")
                    {
                        Content = patchValue
                    };
                    var response = _TFSOwnerProject.sendToTFS(client, request);
                    if (!response.IsSuccessStatusCode)
                    {
                        Logger.logError("Could not update workitem to TFS with ID: '" + this.ID + " because of error \nStatuscode: "
                                        + response.StatusCode + " Reasonphrase: " + response.ReasonPhrase);
                    }
                    return(response.IsSuccessStatusCode);
                }
            }
            return(false);
        }