Beispiel #1
0
        /// <summary>
        /// Post Build
        /// </summary>
        /// <param name="build"></param>
        /// <returns></returns>
        public async Task <BuildDto> PostBuild(BuildDto build)
        {
            DefinitionRequestDto definitionRequestDto = new DefinitionRequestDto
            {
                Definition   = build,
                SourceBranch = _optionsDto.SourceBranch
            };

            string json = JsonConvert.SerializeObject(definitionRequestDto);

            // Setup resources
            string uri = $"{ _optionsDto.SourceUri }/_apis/build/builds?api-version=5.0";

            // Post build
            var response = await _httpClient.PostAsync <BuildDto>(uri, json);

            //Return Repository List
            return(response);
        }
Beispiel #2
0
        internal async Task<HttpResponseMessage> Post(string uri, HttpContent content)
        {
            try
            {
                using (var client = new CustomHttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.ExpectContinue = false;
                    //credentials
                    client.DefaultRequestHeaders.Authorization = Credentials.GetAuthenticationHeader();
                    client.DefaultRequestHeaders.Add("IdEmpresa", /*HttpContext.Current.Session["IdEmpresa" + HttpContext.Current.Session.SessionID]?.ToString() ??*/ Guid.Empty.ToString());
                    client.DefaultRequestHeaders.Add("IdUsuario", /*HttpContext.Current.Session["idUsuario" + HttpContext.Current.Session.SessionID]?.ToString() ??*/ "0");
                    client.DefaultRequestHeaders.Add("Nombre", (/*(UsuarioModelo)HttpContext.Current.Session["usuario" + HttpContext.Current.Session.SessionID])?.Nombre ?? */"----");
                    client.DefaultRequestHeaders.Add("Correo", (/*(UsuarioModelo)HttpContext.Current.Session["usuario" + HttpContext.Current.Session.SessionID])?.Correo ??*/ "*****@*****.**");


                    //obtenemos el timeOut de la solicitud
                    var timeOut = 60;

                    //tiempo de espera del servicio
                    client.Timeout = TimeSpan.FromMinutes(timeOut);
                    var response = client.PostAsync(uri, content).Result;
                    return response;
                }
            }
            catch (AggregateException ee)
            {
                //retorna una exception 
                var exc = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    ReasonPhrase = ee.InnerException != null ? ee.InnerException.Message : ee.Message
                };

                return exc;
            }
            catch (Exception ee)
            {
                //retorna una exception              
                throw ee;
            }
        }