Пример #1
0
        public GetRestoreMultipleWorkItemsResponse.Items PeremenentlyDeleteMultipleItems(string[] ids)
        {
            GetRestoreMultipleWorkItemsResponse.Items viewModel    = new GetRestoreMultipleWorkItemsResponse.Items();
            WorkItemBatchPost.BatchRequest[]          postDocument = new WorkItemBatchPost.BatchRequest[3];
            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json-patch+json" }
            };

            var i = 0;

            foreach (var id in ids)
            {
                postDocument[i] = new WorkItemBatchPost.BatchRequest
                {
                    method  = "DELETE",
                    uri     = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview",
                    headers = headers
                };

                i = i + 1;
            }
            ;

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

                var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json");

                var method  = new HttpMethod("POST");
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview")
                {
                    Content = postValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <GetRestoreMultipleWorkItemsResponse.Items>().Result;
                }
                else
                {
                    dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync <dynamic>();
                    Newtonsoft.Json.Linq.JContainer msg  = responseForInvalidStatusCode.Result;
                    viewModel.Message = msg.ToString();
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Пример #2
0
        public GetRestoreMultipleWorkItemsResponse.Items RestoreMultipleItems(string[] ids)
        {
            GetRestoreMultipleWorkItemsResponse.Items viewModel    = new GetRestoreMultipleWorkItemsResponse.Items();
            WorkItemBatchPost.BatchRequest[]          postDocument = new WorkItemBatchPost.BatchRequest[3];
            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json-patch+json" }
            };

            Object[] postBody = new Object[1];
            postBody[0] = new { op = "replace", path = "/IsDeleted", value = "false" };
            var i = 0;

            foreach (var id in ids)
            {
                postDocument[i] = new WorkItemBatchPost.BatchRequest
                {
                    method  = "PATCH",
                    uri     = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview",
                    headers = headers,
                    body    = postBody
                };

                i = i + 1;
            }
            ;

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

                var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json");

                var method  = new HttpMethod("POST");
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview")
                {
                    Content = postValue
                };
                var response = client.SendAsync(request).Result;

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

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Пример #3
0
        // <summary>
        // Create work item and link the multiple work items
        // </summary>
        // <param name="projectName"></param>
        // <returns>WorkItemPatchResponse.WorkItem</returns>
        public WorkItemBatchPostResponse CreateAndLinkMultipleWorkItems(string projectName)
        {
            WorkItemBatchPost.BatchRequest[] batchRequests = new WorkItemBatchPost.BatchRequest[2];
            Dictionary <string, string>      headers       = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json-patch+json" }
            };

            Object[] parentPatchDocumentBody = new Object[2];
            parentPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "Customer can sign in using their Microsoft Account" };
            parentPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-1" };
            batchRequests[0]           = new WorkItemBatchPost.BatchRequest {
                method  = "PATCH",
                uri     = '/' + projectName + "/_apis/wit/workitems/$User Story?api-version=2.2",
                headers = headers,
                body    = parentPatchDocumentBody
            };

            Object[] childPatchDocumentBody = new Object[3];
            childPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" };
            childPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-2" };
            childPatchDocumentBody[2] = new {
                op    = "add",
                path  = "/relations/-",
                value = new
                {
                    rel = "System.LinkTypes.Hierarchy-Reverse",
                    url = _configuration.UriString + "_apis/wit/workitems/-1"
                }
            };

            batchRequests[1] = new WorkItemBatchPost.BatchRequest {
                method  = "PATCH",
                uri     = '/' + projectName + "/_apis/wit/workitems/$Task?api-version=2.2",
                headers = headers,
                body    = childPatchDocumentBody
            };

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

                var batchRequest = new StringContent(JsonConvert.SerializeObject(batchRequests), Encoding.UTF8, "application/json");
                var method       = new HttpMethod("POST");

                // send the request
                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=2.2")
                {
                    Content = batchRequest
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    var stringResponse = response.Content.ReadAsStringAsync();
                    WorkItemBatchPostResponse batchResponse = response.Content.ReadAsAsync <WorkItemBatchPostResponse>().Result;
                    return(batchResponse);
                }
            }

            return(null);
        }