public IBlockchainWalletsApi CreateNew(string url, bool withCaching           = true,
                                               IClientCacheManager clientCacheManager = null, params DelegatingHandler[] handlers)
        {
            var builder = new HttpClientGeneratorBuilder(url)
                          .WithAdditionalDelegatingHandler(new UserAgentMessageHandler());

            if (withCaching)
            {
                //explicit strategy declaration
                builder.WithCachingStrategy(new AttributeBasedCachingStrategy());
            }
            else
            {
                //By default it is AttributeBasedCachingStrategy, so if no caching turn it off
                builder.WithoutCaching();
            }

            if (handlers != null)
            {
                foreach (var handler in handlers)
                {
                    builder.WithAdditionalDelegatingHandler(handler);
                }
            }

            clientCacheManager = clientCacheManager ?? new ClientCacheManager();
            var httpClientGenerator = builder.Create(clientCacheManager);

            return(httpClientGenerator.Generate <IBlockchainWalletsApi>());
        }
 public IBlockchainWalletsApi CreateNew(BlockchainWalletsClientSettings settings,
                                        bool withCaching = true,
                                        IClientCacheManager clientCacheManager = null,
                                        params DelegatingHandler[] handlers)
 {
     return(CreateNew(settings?.ServiceUrl, withCaching, clientCacheManager, handlers));
 }
        public IBlockPassClient CreateNew(string url, string apiKey, bool withCaching = true,
                                          IClientCacheManager clientCacheManager      = null, params DelegatingHandler[] handlers)
        {
            var builder = new HttpClientGeneratorBuilder(url)
                          .WithAdditionalDelegatingHandler(new ContentTypeHandler())
                          .WithAdditionalDelegatingHandler(new ApiKeyHeaderHandler(apiKey))
                          .WithAdditionalDelegatingHandler(new ResponseHandler());

            if (withCaching)
            {
                //explicit strategy declaration
                builder.WithCachingStrategy(new AttributeBasedCachingStrategy());
            }
            else
            {
                //By default it is AttributeBasedCachingStrategy, so if no caching turn it off
                builder.WithoutCaching();
            }

            foreach (var handler in handlers)
            {
                builder.WithAdditionalDelegatingHandler(handler);
            }

            clientCacheManager = clientCacheManager ?? new ClientCacheManager();
            var httpClientGenerator = builder.Create(clientCacheManager);

            return(httpClientGenerator.Generate <IBlockPassClient>());
        }
Exemple #4
0
        public IBlockchainCashoutPreconditionsCheckApi CreateNew(string url, bool withCaching           = true,
                                                                 IClientCacheManager clientCacheManager = null, params DelegatingHandler[] handlers)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            var builder = new HttpClientGeneratorBuilder(url);

            if (withCaching)
            {
                //explicit strategy declaration
                builder.WithCachingStrategy(new AttributeBasedCachingStrategy());
            }
            else
            {
                //By default it is AttributeBasedCachingStrategy, so if no caching turn it off
                builder.WithoutCaching();
            }

            if (handlers != null)
            {
                foreach (var handler in handlers)
                {
                    builder.WithAdditionalDelegatingHandler(handler);
                }
            }

            clientCacheManager = clientCacheManager ?? new ClientCacheManager();
            var httpClientGenerator = builder.Create(clientCacheManager);

            return(httpClientGenerator.Generate <IBlockchainCashoutPreconditionsCheckApi>());
        }
Exemple #5
0
 /// <summary>
 /// Creates the configured <see cref="HttpClientGenerator"/> instance
 /// </summary>
 /// <param name="cacheManager">Instance of class which is responsible for clients cache invalidation only.
 /// Use Lykke.HttpClientGenerator.Caching.ClientCacheManager</param>
 /// <returns></returns>
 public HttpClientGenerator Create(IClientCacheManager cacheManager)
 {
     return(new HttpClientGenerator(_rootUrl,
                                    GetCallsWrappers(cacheManager),
                                    GetDelegatingHandlers(),
                                    _jsonSerializerSettings,
                                    _urlParameterFormatter));
 }
Exemple #6
0
        public IBlockchainCashoutPreconditionsCheckApi CreateNew(BlockchainCashoutPreconditionsClientSettings settings,
                                                                 bool withCaching = true,
                                                                 IClientCacheManager clientCacheManager = null,
                                                                 params DelegatingHandler[] handlers)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            return(CreateNew(settings.ServiceUrl, withCaching, clientCacheManager, handlers));
        }
Exemple #7
0
        private IEnumerable <ICallsWrapper> GetCallsWrappers(IClientCacheManager cacheManager)
        {
            if (_additionalCallsWrappers != null)
            {
                foreach (var additionalCallsWrapper in _additionalCallsWrappers)
                {
                    yield return(additionalCallsWrapper);
                }
            }

            if (_cachingStrategy != null)
            {
                var cacheProvider = new RemovableAsyncCacheProvider(new MemoryCache(new MemoryCacheOptions()));
                CachingCallsWrapper cachingCallsWrapper = new CachingCallsWrapper(_cachingStrategy, cacheProvider);
                if (cacheManager != null)
                {
                    cacheManager.OnInvalidate += cachingCallsWrapper.InvalidateCache;
                }

                yield return(cachingCallsWrapper);
            }
        }
Exemple #8
0
        private readonly IClientCacheManager _clientCacheManager; //Required to Invalidate Cache on request

        public BlockchainExplorersProvider(Lykke.Service.BlockchainSettings.Client.IBlockchainSettingsClient client,
                                           IClientCacheManager clientCacheManager)
        {
            _client             = client;
            _clientCacheManager = clientCacheManager;
        }