Пример #1
0
        public static HareDuFactory Initialize(Action <HareDuClientConfigurationProvider> configuration)
        {
            if (configuration == null)
            {
                throw new HareDuClientConfigurationException("Settings cannot be null and should at least have user credentials, RabbitMQ server URL and port.");
            }

            try
            {
                var init = new HareDuClientConfigurationProviderImpl();
                configuration(init);

                HareDuClientSettings settings = init.Settings.Value;

                ValidateSettings(settings);

                HttpClient client = GetHttpClient(settings);

                HareDuFactory factory = new HareDuFactoryImpl(client);

                return(factory);
            }
            catch (Exception e)
            {
                throw new HareDuClientInitException("Unable to initialize the HareDu client.", e);
            }
        }
Пример #2
0
 protected ResourceBase(HttpClient client, HareDuClientSettings settings)
     : base(settings.LoggerSettings.Name, settings.LoggerSettings.Logger, settings.LoggerSettings.Enable)
 {
     _client   = client;
     _settings = settings;
     _policy   = Policy <Task <HttpResponseMessage> >
                 .Handle <HttpRequestException>()
                 .Retry(_settings.TransientRetrySettings.RetryLimit, (e, i) => LogRetryError(e.Exception, i));
 }
Пример #3
0
        static void ValidateSettings(HareDuClientSettings settings)
        {
            if (settings.IsNull())
            {
                throw new HareDuClientConfigurationException("Settings cannot be null and should at least have user credentials, RabbitMQ server URL and port.");
            }

            if (settings.Credentials.IsNull() || string.IsNullOrWhiteSpace(settings.Credentials.Username) || string.IsNullOrWhiteSpace(settings.Credentials.Password))
            {
                throw new UserCredentialsMissingException("Username and password are required and cannot be empty.");
            }

            if (string.IsNullOrWhiteSpace(settings.RabbitMqServerUrl))
            {
                throw new HostUrlMissingException("Host URL is required and cannot be empty.");
            }
        }
Пример #4
0
        public static HareDuFactory Initialize(string configuration)
        {
            try
            {
                HareDuClientSettings settings = SerializerCache.Deserializer.Deserialize <HareDuClientSettings>(new JsonTextReader(new StringReader(configuration)));

                ValidateSettings(settings);

                HttpClient client = GetHttpClient(settings);

                HareDuFactory factory = new HareDuFactoryImpl(client, settings);

                return(factory);
            }
            catch (Exception e)
            {
                throw new HareDuClientInitException("Unable to initialize the HareDu client.", e);
            }
        }
Пример #5
0
        public static HareDuFactory Initialize(Action <HareDuClientConfigurationProvider> configuration)
        {
            try
            {
                var init = new HareDuClientConfigurationProviderImpl();
                configuration(init);

                HareDuClientSettings settings = init.Settings.Value;

                ValidateSettings(settings);

                HttpClient client = GetHttpClient(settings);

                HareDuFactory factory = new HareDuFactoryImpl(client, settings);

                return(factory);
            }
            catch (Exception e)
            {
                throw new HareDuClientInitException("Unable to initialize the HareDu client.", e);
            }
        }
Пример #6
0
        static HttpClient GetHttpClient(HareDuClientSettings settings)
        {
            var uri     = new Uri($"{settings.RabbitMqServerUrl}/");
            var handler = new HttpClientHandler
            {
                Credentials = new NetworkCredential(settings.Credentials.Username, settings.Credentials.Password)
            };

            var client = new HttpClient(handler)
            {
                BaseAddress = uri
            };

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            if (settings.Timeout != TimeSpan.Zero)
            {
                client.Timeout = settings.Timeout;
            }

            return(client);
        }
Пример #7
0
        public static HareDuFactory Initialize(Func <HareDuClientSettings> configuration)
        {
            try
            {
                if (configuration == null)
                {
                    throw new HareDuClientConfigurationException("Settings cannot be null and should at least have user credentials, RabbitMQ server URL and port.");
                }

                HareDuClientSettings settings = configuration();

                ValidateSettings(settings);

                HttpClient client = GetHttpClient(settings);

                HareDuFactory factory = new HareDuFactoryImpl(client, settings);

                return(factory);
            }
            catch (Exception e)
            {
                throw new HareDuClientInitException("Unable to initialize the HareDu client.", e);
            }
        }
Пример #8
0
        public static HareDuFactory Initialize(string configuration)
        {
            if (string.IsNullOrWhiteSpace(configuration))
            {
                throw new HareDuClientConfigurationException("Settings cannot be null and should at least have user credentials, RabbitMQ server URL and port.");
            }

            try
            {
                HareDuClientSettings settings = SerializerCache.Deserializer.Deserialize <HareDuClientSettings>(new JsonTextReader(new StringReader(configuration)));

                ValidateSettings(settings);

                HttpClient client = GetHttpClient(settings);

                HareDuFactory factory = new HareDuFactoryImpl(client);

                return(factory);
            }
            catch (Exception e)
            {
                throw new HareDuClientInitException("Unable to initialize the HareDu client.", e);
            }
        }
Пример #9
0
 public QueueImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #10
0
 public ServerImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #11
0
 public ExchangeImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #12
0
 public BindingImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #13
0
 public GlobalParameterImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #14
0
 public HareDuFactoryImpl(HttpClient httpClient, HareDuClientSettings settings)
     : base(settings.LoggerSettings.Name, settings.LoggerSettings.Logger, settings.LoggerSettings.Enable)
 {
     _httpClient = httpClient;
     _settings   = settings;
 }
Пример #15
0
 public VirtualHostImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #16
0
 public UserPermissionsImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #17
0
 public ScopedParameterImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }
Пример #18
0
 public PolicyImpl(HttpClient client, HareDuClientSettings settings)
     : base(client, settings)
 {
 }