Exemplo n.º 1
0
        private async Task <T> SendAsync <T>(ISsmRequest request)
            where T : new()
        {
            string responseText = await SendAsync(GetRequestMessage(Endpoint, request)).ConfigureAwait(false);

            return(responseText.Length > 0
                ? JsonObject.Parse(responseText).As <T>()
                : new T());
        }
Exemplo n.º 2
0
        private async Task <T> SendAsync <T>(ISsmRequest request)
            where T : new()
        {
            string responseText = await SendAsync(GetRequestMessage(Endpoint, request)).ConfigureAwait(false);

            return(responseText.Length > 0
                ? JsonSerializer.Deserialize <T>(responseText)
                : new T());
        }
Exemplo n.º 3
0
        private static HttpRequestMessage GetRequestMessage(string endpoint, ISsmRequest request)
        {
            var actionName = request.GetType().Name.Replace("Request", "");

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

            return(new HttpRequestMessage(HttpMethod.Post, endpoint)
            {
                Headers =
                {
                    { "x-amz-target", "AmazonSSM." + actionName },
                },
                Content = new StringContent(json.ToString(pretty: false), Encoding.UTF8, "application/x-amz-json-1.1")
            });
        }
Exemplo n.º 4
0
        private async Task <T> SendAsync <T>(ISsmRequest request)
            where T : new()
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var responseText = await SendAsync(GetRequestMessage(Endpoint, request)).ConfigureAwait(false);

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

            return(JsonObject.Parse(responseText).As <T>());
        }
Exemplo n.º 5
0
        private async Task <T> SendAsync <T>(ISsmRequest 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);
            }
        }