Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the asynchronous.
        /// </summary>
        /// <param name="httpClient">The HTTP client.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public Task <bool> InitializeAsync(HttpClient httpClient, RestEaseClientFactoryOptions options = null)
        {
            try
            {
                this.HttpClient = httpClient;
                this.Options    = options;

                this.ApiClient = new RestClient(this.HttpClient)
                {
                    ResponseDeserializer        = this.Options?.ResponseDeserializer,
                    RequestBodySerializer       = this.Options?.JsonRequestBodySerializer,
                    JsonSerializerSettings      = this.Options?.JsonSerializerSettings,
                    RequestQueryParamSerializer = this.Options?.RequestQueryParamSerializer
                };

                this.Api = this.ApiClient.For <T>();

                Serilog.Log.Information("Client Factory Initialized");
                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                Serilog.Log.Error(ex, "Failed to initialize API Client");
            }

            return(Task.FromResult(false));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// initialize the factory.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="clientHandler">The client handler.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// Task&lt;System.Boolean&gt;.
        /// </returns>
        public Task <bool> InitializeAsync(string url, HttpClientHandler clientHandler, RestEaseClientFactoryOptions options = null)
        {
            HttpClient httpClient;

            if (options?.EnableHttpLogging == true)
            {
                var loggingHandler = new HttpLoggingHandler(clientHandler);
                if (this.OnSendAsyncBefore != null)
                {
                    loggingHandler.OnSendAsyncBefore += this.OnSendAsyncBefore;
                }
                if (this.OnSendAsyncAfter != null)
                {
                    loggingHandler.OnSendAsyncAfter += this.OnSendAsyncAfter;
                }

                httpClient = new HttpClient(new HttpLoggingHandler(clientHandler))
                {
                    BaseAddress = new Uri(url)
                };
            }
            else
            {
                httpClient = new HttpClient(clientHandler)
                {
                    BaseAddress = new Uri(url)
                };
            }

            return(this.InitializeAsync(httpClient, options));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes the factory.
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="options">The options.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">token - token cannot be null</exception>
 public Task <bool> InitializeAsync(string url, RestEaseClientFactoryOptions options = null)
 {
     return(this.InitializeAsync(url, new HttpClientHandler(), options));
 }