Exemple #1
0
        public static HttpRequestMessage GetRequestMessage(string endpoint, ICodeBuildRequest request)
        {
            #region Preconditions

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            #endregion

            var actionName = request.GetType().Name.Replace("Request", "");

            var json = new JsonSerializer().Serialize(request, serializationOptions);

            // 2016-10-06
            // X-Amz-Target: CodeBuild_20161006.StopBuild

            return(new HttpRequestMessage(HttpMethod.Post, endpoint)
            {
                Headers =
                {
                    { "x-amz-target", "CodeBuild_20161006." + actionName },
                },
                Content = new StringContent(json.ToString(pretty: false), Encoding.UTF8, "application/x-amz-json-1.1")
            });
        }
Exemple #2
0
        private async Task <T> SendAsync <T>(ICodeBuildRequest request)
            where T : new()
        {
            var responseText = await SendAsync(GetRequestMessage(Endpoint, request)).ConfigureAwait(false);

            if (responseText.Length == 0)
            {
                return(new T());
            }

            // TEMP try / catch ... remove once all the JSON deserialization methods are verified

            try
            {
                return(JsonObject.Parse(responseText).As <T>());
            }
            catch
            {
                throw new Exception("error deserializing: " + responseText);
            }
        }
Exemple #3
0
        private async Task <T> SendAsync <T>(ICodeBuildRequest request)
            where T : new()
        {
            var responseText = await SendAsync(GetRequestMessage(Endpoint, request)).ConfigureAwait(false);

            if (responseText.Length == 0)
            {
                return(new T());
            }

            // TEMP try / catch ... remove once all the JSON deserialization methods are verified

            try
            {
                return(JsonSerializer.Deserialize <T>(responseText, jso));
            }
            catch (Exception ex)
            {
                throw new Exception("Dserialize error for " + responseText, ex);
            }
        }