コード例 #1
0
        public GetOperationResponse.Operation GetOperation(string url)
        {
            // create a viewmodel that is a class that represents the returned json response
            GetOperationResponse.Operation viewModel = new GetOperationResponse.Operation();

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

                // connect to the REST endpoint
                HttpResponseMessage response = client.GetAsync(url).Result;

                // check to see if we have a succesfull respond
                if (response.IsSuccessStatusCode)
                {
                    // set the viewmodel from the content in the response
                    viewModel = response.Content.ReadAsAsync <GetOperationResponse.Operation>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
コード例 #2
0
        public GetOperationResponse.Operation CreateTeamProject(string name)
        {
            GetOperationResponse.Operation operation = new GetOperationResponse.Operation();

            Object teamProject = new
            {
                name         = name,
                description  = "VanDelay Industries travel app",
                capabilities = new
                {
                    versioncontrol = new
                    {
                        sourceControlType = "Git"
                    },
                    processTemplate = new
                    {
                        templateTypeId = "6b724908-ef14-45cf-84f8-768b5384da45"
                    }
                }
            };

            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);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json");
                var method     = new HttpMethod("POST");

                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

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

                operation.HttpStatusCode = response.StatusCode;

                return(operation);
            }
        }
コード例 #3
0
        public GetOperationResponse.Operation ChangeTeamProjectDescription(string projectId, string projectDescription)
        {
            GetOperationResponse.Operation opertion = new GetOperationResponse.Operation();

            Object projectData = new
            {
                description = projectDescription
            };

            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);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json");
                var method     = new HttpMethod("PATCH");

                var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

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

                opertion.HttpStatusCode = response.StatusCode;

                return(opertion);
            }
        }