Beispiel #1
0
        /// <summary>
        ///  Image Gallery API - Post Message
        /// </summary>
        /// <param name="client"></param>
        /// <param name="policy"></param>
        /// <param name="image"></param>
        /// <param name="apiUri"></param>
        /// <param name="waitForPostComplete"></param>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        private static async Task PostImageGalleryApi(HttpClient client, RetryPolicy policy, ImageForCreation image, string apiUri, bool waitForPostComplete, CancellationToken cancellation)
        {
            Log.Verbose("ImageGalleryAPI Post {@Image}| {FileSize}", image.ToString(), image.Bytes.Length);

            try
            {
                var serializedImageForCreation = JsonConvert.SerializeObject(image);

                // TODO - Log Transaction Time/Sucess Message
                await policy.ExecuteAsync(async token => await client.PostAsync(
                                              $"{apiUri}/api/images",
                                              new StringContent(serializedImageForCreation, System.Text.Encoding.Unicode, "application/json"), cancellation)
                                          .ConfigureAwait(waitForPostComplete), cancellation).ContinueWith(r =>
                {
                    if (!r.Result.IsSuccessStatusCode)
                    {
                        Log.Error("{@Status} ImageGalleryAPI Post Error {@Image}", r.Result.StatusCode.ToString(),
                                  image.ToString());
                    }
                    else
                    {
                        Log.Information("{@Status} ImageGalleryAPI Post Complete {@Image}", r.Result.StatusCode,
                                        image.ToString());
                    }
                    r.Result.Dispose();
                }, cancellation);
            }
            catch (JsonSerializationException ex)
            {
                Log.Error(ex, "ImageGalleryAPI Post JSON Exception: {ex}", ex.InnerException?.Message ?? ex.Message);
            }
            catch (HttpRequestException ex)
            {
                Log.Error(ex, "ImageGalleryAPI Post HTTP Exception: {ex}", ex.InnerException?.Message ?? ex.Message);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "ImageGalleryAPI Post General Exception: {ex}", ex.InnerException?.Message ?? ex.Message);
            }
        }
        /// <summary>
        ///  Image Gallery API - Post Message
        /// </summary>
        /// <param name="client"></param>
        /// <param name="image"></param>
        /// <param name="apiUri"></param>
        /// <param name="waitForPostComplete"></param>
        /// <returns></returns>
        private static async Task <HttpResponseMessage> GoPostImageGalleryApi(HttpClient client, ImageForCreation image, string apiUri, bool waitForPostComplete)
        {
            Log.Information("ImageGalleryAPI Post {@Image}", image.ToString());

            // TODO - Add Errors to be Handled
            var serializedImageForCreation = JsonConvert.SerializeObject(image);

            var response = await client.PostAsync(
                $"{apiUri}/api/images",
                new StringContent(serializedImageForCreation, System.Text.Encoding.Unicode, "application/json"))
                           .ConfigureAwait(waitForPostComplete);

            // TODO - Log Transaction Time/Sucess Message
            if (waitForPostComplete)
            {
                Log.Information("{@Status} Post Complete {@Image}", response.StatusCode, image.ToString());
            }

            return(response);
        }
Beispiel #3
0
        public async Task PostImageGalleryApi(TokenResponse token, ImageForCreation image, CancellationToken cancellation)
        {
            _httpClient.SetBearerToken(token.AccessToken);

            var serializedImageForCreation = JsonConvert.SerializeObject(image);

            await _httpClient.PostAsync(
                $"/api/images",
                new StringContent(serializedImageForCreation, System.Text.Encoding.Unicode, "application/json"), cancellation)
            .ContinueWith(r =>
            {
                if (!r.Result.IsSuccessStatusCode)
                {
                    Log.Error("{@Status} ImageGalleryCommand Post Error {@Image}", r.Result.StatusCode.ToString(), image.ToString());
                }
                else
                {
                    Log.Information("{@Status} ImageGalleryCommand Post Complete {@Image}", r.Result.StatusCode, image.ToString());
                }
            }, cancellation);
        }