コード例 #1
0
        /// <summary>
        /// Services the invoker internal.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="token">The token.</param>
        /// <param name="data">The data.</param>
        /// <param name="uriBuilder">The URI builder.</param>
        /// <param name="cookie">The cookie.</param>
        /// <param name="requiresAuthentication">if set to <c>true</c> [requires authentication].</param>
        /// <param name="isRetry">if set to <c>true</c> [is retry].</param>
        /// <returns></returns>
        private async Task <string> ServiceInvokerInternal(
            HttpRequestMethod method,
            string endpoint,
            CancellationToken token,
            string data,
            UriBuilder uriBuilder,
            Cookie cookie,
            bool requiresAuthentication,
            bool isRetry = false)
        {
            HttpResponseMessage response = null;
            string    result             = null;
            Exception exr;

            try
            {
                _requestMediator.WaitOne();
                LogConsumer.Trace("ServiceInvokerAsync -&gt; Method: {0} | Endpoint: {1}", method.GetHumanReadableValue(), endpoint);
                LogConsumer.Debug(uriBuilder.ToString());
                var cookieContainer = new CookieContainer();
                using var handler = new HttpClientHandler { CookieContainer = cookieContainer };
                using var client  = new HttpClient(handler);
                ConfigureClient(client, requiresAuthentication);
                if (cookie != null)
                {
                    cookieContainer.Add(uriBuilder.Uri, cookie);
                }

                response = await RequestInternalAsync(method, token, data, client, uriBuilder)
                           .ConfigureAwait(false);

                token.ThrowIfCancellationRequested();
                result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
                return(result);
            }
            catch (AggregateException e)
            {
                var ex = e.InnerExceptions.FirstOrDefault() ?? e.InnerException ?? e;
                exr = HandleException(ex, response, uriBuilder.Uri, method, data, result);
                if (isRetry)
                {
                    throw exr;
                }
            }
            catch (Exception e)
            {
                exr = HandleException(e, response, uriBuilder.Uri, method, data, result);
                if (isRetry)
                {
                    throw exr;
                }
            }
            return(await ServiceInvokerInternal(method, endpoint, token, data, uriBuilder, cookie, requiresAuthentication, true).ConfigureAwait(false));
        }
コード例 #2
0
 /// <summary>
 /// Propagates the message internal.
 /// </summary>
 /// <param name="message">The message.</param>
 private void PropagateMessageInternal(string message)
 {
     try
     {
         _propagationStrategy.Propagate(message, _redis.QueuePrefix, _redis.Subscriber);
     }
     catch (Exception e)
     {
         LogConsumer.Debug("Message: {0} | Stack Trace: {1}", e.Message, e.StackTrace);
     }
 }