コード例 #1
0
        /// <summary>
        /// Initializes a new instance of InfiniteRepeaterRetryStrategy.
        /// </summary>
        /// <param name="inner">
        /// The IRetryStrategy to remember the last wait time infinitely.
        /// </param>
        public InfiniteRepeaterRetryStrategy(IRetryStrategy inner)
        {
            if (null == inner)
            {
                throw new ArgumentNullException("inner");
            }

            this.inner = inner;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of AddJitterRetryStrategy using a range of the given minPercent (inclusive) to
        /// maxPercent (exclusive).
        /// </summary>
        /// <param name="inner">
        /// The IRetryStrategy to add the jitter to.
        /// </param>
        /// <param name="minPercent">
        /// The inclusive minimum percentage of the range in which to vary the wait times. Must be &gt;= 0 and &lt;
        /// maxPercent.
        /// </param>
        /// <param name="maxPercent">
        /// The exclusive maximum percentage of the range in which to vary the wait times. Must be &gt; 0 and &gt;
        /// minPercent. Can be &gt; 1.
        /// </param>
        /// <remarks>
        /// E.g. by setting minPercent = 0.5 and maxPercent = 2, you can achieve a variation of the wait times from the
        /// inner IRetryStrategy in the range of 50% to 200% i.e. wait at least half as long and at most twice as long.
        /// </remarks>
        public AddJitterRetryStrategy(IRetryStrategy inner, double minPercent, double maxPercent)
        {
            if (null == inner)
            {
                throw new ArgumentNullException("inner");
            }
            else if (minPercent < 0)
            {
                throw new ArgumentOutOfRangeException("minPercent");
            }
            else if (maxPercent <= 0)
            {
                throw new ArgumentOutOfRangeException("maxPercent");
            }
            else if (minPercent >= maxPercent)
            {
                throw new ArgumentException("minPercent must be less than maxPercent.");
            }

            this.inner = inner;

            min = minPercent;
            max = maxPercent;
        }
コード例 #3
0
ファイル: Attempt.cs プロジェクト: pkudrel/Syrup
 /// <summary>
 /// Repeatedly yields a lazy invocation attempt of the action as an enumerable.
 /// </summary>
 public static IEnumerable <Lazy <Attempt> > Do(this IRetryStrategy retryStrategy, Action action,
                                                CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Attempt.Repeatedly.Do(action).UsingStrategy(retryStrategy, cancellationToken));
 }
コード例 #4
0
 public IKeyLock GetKeyLock(string key, DateTime expires, IRetryStrategy retryStrategy = null, string workerId = null)
 {
     throw new NotImplementedException();
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the ReliableConnection class.
 /// </summary>
 /// <param name="innerConnection">The inner connection to wrap.</param>
 /// <param name="retryStrategy">The retry strategy to use.</param>
 public ReliableConnection(DbConnection innerConnection, IRetryStrategy retryStrategy) : base(innerConnection)
 {
     RetryStrategy = retryStrategy;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of AddJitterRetryStrategy using a range of the given minPercent (inclusive) to
 /// 100% (exclusive).
 /// </summary>
 /// <param name="inner">
 /// The IRetryStrategy to add the jitter to.
 /// </param>
 /// <param name="minPercent">
 /// The inclusive minimum percentage of the range in which to vary the wait times. Must be &gt;= 0 and &lt; 1.
 /// </param>
 public AddJitterRetryStrategy(IRetryStrategy inner, double minPercent)
     : this(inner, minPercent, 1)
 {
 }
        public CouchbaseLiteHttpClient GetHttpClient(CookieStore cookieStore, IRetryStrategy retryStrategy)
        {
            var authHandler = BuildHandlerPipeline(cookieStore, retryStrategy);

            // As the handler will not be shared, client.Dispose() needs to be 
            // called once the operation is done to release the unmanaged resources 
            // and disposes of the managed resources.
            var client =  new HttpClient(authHandler, true) 
            {
                Timeout = ReplicationOptions.DefaultRequestTimeout
            };

            client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", String.Format("CouchbaseLite/{0} ({1})", Replication.SyncProtocolVersion, Manager.VersionString));
            client.DefaultRequestHeaders.Connection.Add("keep-alive");

            foreach(var header in Headers)
            {
                var success = client.DefaultRequestHeaders.TryAddWithoutValidation(header.Key, header.Value);
                if (!success)
                    Log.To.Sync.W(Tag, String.Format("Unabled to add header to request: {0}: {1}", header.Key, header.Value));
            }

            var transientHandler = authHandler as TransientErrorRetryHandler;
            var defaultAuthHandler = default(DefaultAuthHandler);
            if (transientHandler != null) {
                defaultAuthHandler = transientHandler.InnerHandler as DefaultAuthHandler;
            } else {
                defaultAuthHandler = authHandler as DefaultAuthHandler;
            }

            return new CouchbaseLiteHttpClient(client, defaultAuthHandler);
        }
コード例 #8
0
        internal CouchbaseBucket(string name, ClusterContext context, IScopeFactory scopeFactory, IRetryOrchestrator retryOrchestrator,
                                 IVBucketKeyMapperFactory vBucketKeyMapperFactory, ILogger <CouchbaseBucket> logger, IRedactor redactor, IBootstrapperFactory bootstrapperFactory,
                                 IRequestTracer tracer, IOperationConfigurator operationConfigurator, IRetryStrategy retryStrategy)
            : base(name, context, scopeFactory, retryOrchestrator, logger, redactor, bootstrapperFactory, tracer, operationConfigurator, retryStrategy)
        {
            _vBucketKeyMapperFactory = vBucketKeyMapperFactory ?? throw new ArgumentNullException(nameof(vBucketKeyMapperFactory));

            _viewClientLazy = new Lazy <IViewClient>(() =>
                                                     context.ServiceProvider.GetRequiredService <IViewClient>()
                                                     );
            _viewManagerLazy = new Lazy <IViewIndexManager>(() =>
                                                            new ViewIndexManager(name,
                                                                                 context.ServiceProvider.GetRequiredService <IServiceUriProvider>(),
                                                                                 context.ServiceProvider.GetRequiredService <CouchbaseHttpClient>(),
                                                                                 context.ServiceProvider.GetRequiredService <ILogger <ViewIndexManager> >(),
                                                                                 redactor));

            _collectionManagerLazy = new Lazy <ICouchbaseCollectionManager>(() =>
                                                                            new CollectionManager(name,
                                                                                                  context.ServiceProvider.GetRequiredService <IServiceUriProvider>(),
                                                                                                  context.ServiceProvider.GetRequiredService <CouchbaseHttpClient>(),
                                                                                                  context.ServiceProvider.GetRequiredService <ILogger <CollectionManager> >(),
                                                                                                  redactor)
                                                                            );
        }
コード例 #9
0
ファイル: OktaClient.cs プロジェクト: i-e-b/okta-sdk-dotnet
        /// <summary>
        /// Initializes a new instance of the <see cref="OktaClient"/> class using the specified <see cref="HttpClient"/>.
        /// </summary>
        /// <param name="apiClientConfiguration">
        /// The client configuration. If <c>null</c>, the library will attempt to load
        /// configuration from an <c>okta.yaml</c> file or environment variables.
        /// </param>
        /// <param name="httpClient">The HTTP client to use for requests to the Okta API.</param>
        /// <param name="logger">The logging interface to use, if any.</param>
        /// <param name="retryStrategy">The retry strategy interface to use, if any.</param>
        /// <param name="serializer">The JSON serializer to use, if any. Using the <c>DefaultSerializer</c> is still strongly recommended since it has all the behavior this SDK needs to work properly.
        /// If a custom serializer is used, the developer is responsible to add the required logic for this SDK to continue working properly. See <see cref="DefaultSerializer"/> to check out what settings can be configured.
        /// </param>
        public OktaClient(OktaClientConfiguration apiClientConfiguration, HttpClient httpClient, ILogger logger = null, IRetryStrategy retryStrategy = null, ISerializer serializer = null)
        {
            Configuration = GetConfigurationOrDefault(apiClientConfiguration);
            OktaClientConfigurationValidator.Validate(Configuration);

            logger     = logger ?? NullLogger.Instance;
            serializer = serializer ?? new DefaultSerializer();

            var resourceFactory = new ResourceFactory(this, logger);
            IOAuthTokenProvider oAuthTokenProvider = (Configuration.AuthorizationMode == AuthorizationMode.PrivateKey) ? new DefaultOAuthTokenProvider(Configuration, resourceFactory, logger: logger) : NullOAuthTokenProvider.Instance;
            var requestExecutor = new DefaultRequestExecutor(Configuration, httpClient, logger, retryStrategy, oAuthTokenProvider);

            _dataStore = new DefaultDataStore(
                requestExecutor,
                serializer,
                resourceFactory,
                logger);

            PayloadHandler.TryRegister <PkixCertPayloadHandler>();
            PayloadHandler.TryRegister <PemFilePayloadHandler>();
            PayloadHandler.TryRegister <X509CaCertPayloadHandler>();
        }
コード例 #10
0
 public RetryMessageQueue(IRetryStrategy retryStrategy, IMessageQueue <T> inner)
 {
     _retryStrategy = retryStrategy ?? throw new ArgumentNullException(nameof(retryStrategy));
     _inner         = inner ?? throw new ArgumentNullException(nameof(inner));
 }
コード例 #11
0
        public CouchbaseLiteHttpClient GetHttpClient(CookieStore cookieStore, IRetryStrategy strategy)
        {
            var handler = strategy != null ? (HttpMessageHandler)new TransientErrorRetryHandler(HttpHandler, strategy) : HttpHandler;
            var client = new HttpClient(handler, false);
            foreach (var header in Headers) {
                var success = client.DefaultRequestHeaders.TryAddWithoutValidation(header.Key, header.Value);
                if (!success) {
                    Console.WriteLine("Unable to add header to request: {0}: {1}", header.Key, header.Value);
                }
            }

            return new CouchbaseLiteHttpClient(client, null);
        }
コード例 #12
0
		/// <summary>
		/// Initializes a new instance of the ReliableConnection class.
		/// </summary>
		/// <param name="innerConnection">The inner connection to wrap.</param>
		/// <param name="retryStrategy">The retry strategy to use.</param>
		public ReliableConnection(DbConnection innerConnection, IRetryStrategy retryStrategy)
		{
			RetryStrategy = retryStrategy;
			InnerConnection = innerConnection;
		}
コード例 #13
0
 public RetryStrategyExecutor(HttpRequestMessage message, IRetryStrategy strategy, CancellationToken token)
 {
     _strategy = strategy.Copy();
     _request = message;
     _token = token;
 }
コード例 #14
0
 public CouchbaseLiteHttpClient GetHttpClient(CookieStore cookieStore, IRetryStrategy strategy)
 {
     var mockHttpClient = new HttpClient(HttpHandler);
     return new CouchbaseLiteHttpClient(mockHttpClient, null);
 }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultRequestExecutor"/> class.
        /// </summary>
        /// <param name="configuration">The client configuration.</param>
        /// <param name="httpClient">The HTTP client to use, if any.</param>
        /// <param name="logger">The logging interface.</param>
        /// <param name="retryStrategy">The retry strategy interface.</param>
        public DefaultRequestExecutor(OktaClientConfiguration configuration, HttpClient httpClient, ILogger logger, IRetryStrategy retryStrategy = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _oktaDomain    = configuration.OktaDomain;
            _logger        = logger;
            _httpClient    = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
            _retryStrategy = retryStrategy ?? new NoRetryStrategy();

            ApplyDefaultClientSettings(_httpClient, _oktaDomain, configuration);
        }
コード例 #16
0
 public QueryOptions RetryStrategy(IRetryStrategy retryStrategy)
 {
     RetryStrategyValue = retryStrategy;
     return(this);
 }
コード例 #17
0
ファイル: Consumer.cs プロジェクト: rokeller/aqua
 /// <summary>
 /// Consumes one message from the queue, applying the given IRetryStrategy to wait for a message if the queue
 /// is empty.
 /// </summary>
 /// <param name="dequeueStrategy">
 /// An instance of IRetryStrategy which defines how long and how often to query the queue for a single message.
 /// </param>
 /// <returns>
 /// True if a message was successfully consumed, false otherwise.
 /// </returns>
 public bool One(IRetryStrategy dequeueStrategy)
 {
     return One(dequeueStrategy, CancellationToken.None);
 }
コード例 #18
0
 public ChangeTrackerBackoff(IRetryStrategy strategy)
 {
     _retryStrategy = strategy;
 }
コード例 #19
0
ファイル: Consumer.cs プロジェクト: rokeller/aqua
        /// <summary>
        /// Consumes one message from the queue, applying the given IRetryStrategy to wait for a message if the queue
        /// is empty.
        /// </summary>
        /// <param name="dequeueStrategy">
        /// An instance of IRetryStrategy which defines how long and how often to query the queue for a single message.
        /// </param>
        /// <param name="cancellationToken">
        /// A CancellationToken to use to check if the operation should be cancelled.
        /// </param>
        /// <returns>
        /// True if a message was successfully consumed, false otherwise.
        /// </returns>
        public bool One(IRetryStrategy dequeueStrategy, CancellationToken cancellationToken)
        {
            if (null == dequeueStrategy)
            {
                throw new ArgumentNullException("dequeueStrategy");
            }

            for (int i = 1; ; i++)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return false;
                }

                using (JobExecutionContext context = JobExecutionContext.Dequeue(this))
                {
                    if (context.Empty)
                    {
                        if (dequeueStrategy.ShouldRetry(i))
                        {
                            Task.Delay(dequeueStrategy.GetWaitTime(i), cancellationToken)
                                .ContinueWith(NoopTaskContinuation)
                                .Wait();

                            continue;
                        }

                        break;
                    }

                    return context.Execute();
                }
            }

            return false;
        }
コード例 #20
0
 public RetryAgent(IRetryStrategy strategy)
 {
     this.strategy = strategy;
 }
コード例 #21
0
 public IKeyLock GetKeyLock(string key, DateTime expires, IRetryStrategy retryStrategy = null, string workerId = null)
 {
     return(new KVSLockWithCAS(key, expires, this, retryStrategy ?? new SimpleLockRetryStrategy(5, 500), workerId));
 }
コード例 #22
0
		/// <summary>
		/// Initializes a new instance of the ReliableConnection class.
		/// A default retry strategy is used.
		/// </summary>
		/// <param name="innerConnection">The inner connection to wrap.</param>
		public ReliableConnection(DbConnection innerConnection) : base(innerConnection)
		{
			// use the default retry strategy by default
			RetryStrategy = Insight.Database.Reliable.RetryStrategy.Default;
		}
コード例 #23
0
 /// <summary>
 /// Retry when provided custom retry strategy returns true.
 /// </summary>
 /// <param name="customStrategy">A custom retry strategy implementation of <see cref="IRetryStrategy{TResult}"/>.</param>
 /// <returns>Returns this instance of <see cref="RetryDefinitionBuilder{TResult}"/>.</returns>
 public RetryDefinitionBuilder <TResult> WhenCustomStrategy(IRetryStrategy <TResult> customStrategy)
 {
     _definition.RetryStrategies.Add(customStrategy);
     return(this);
 }
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the ReliableConnection class.
 /// A default retry strategy is used.
 /// </summary>
 /// <param name="innerConnection">The inner connection to wrap.</param>
 public ReliableConnection(DbConnection innerConnection) : base(innerConnection)
 {
     // use the default retry strategy by default
     RetryStrategy = Insight.Database.Reliable.RetryStrategy.Default;
 }
コード例 #25
0
ファイル: Client.cs プロジェクト: thinkingserious/StrongGrid
 /// <summary>
 /// Initializes a new instance of the <see cref="Client" /> class.
 /// </summary>
 /// <param name="apiKey">Your SendGrid API Key</param>
 /// <param name="baseUri">Base SendGrid API Uri</param>
 /// <param name="apiVersion">The SendGrid API version. Please note: currently, only 'v3' is supported</param>
 /// <param name="httpClient">Allows you to inject your own HttpClient. This is useful, for example, to setup the HtppClient with a proxy</param>
 /// <param name="retryStrategy">The retry strategy.</param>
 public Client(string apiKey, string baseUri = DEFAULT_BASE_URI, string apiVersion = DEFAULT_API_VERSION, HttpClient httpClient = null, IRetryStrategy retryStrategy = null)
     : this(apiKey, null, null, baseUri, apiVersion, httpClient, retryStrategy)
 {
 }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the ReliableCommand class, and bind it to the specified ReliableConnection and innerCommand.
 /// </summary>
 /// <param name="retryStrategy">The retry strategy to use for the command.</param>
 /// <param name="innerConnection">The innerConnection to bind to.</param>
 /// <param name="innerCommand">The innerCommand to bind to.</param>
 public ReliableCommand(IRetryStrategy retryStrategy, ReliableConnection innerConnection, DbCommand innerCommand) : base(innerConnection, innerCommand)
 {
     _retryStrategy = retryStrategy;
 }
コード例 #27
0
ファイル: Client.cs プロジェクト: thinkingserious/StrongGrid
 /// <summary>
 /// Initializes a new instance of the <see cref="Client" /> class.
 /// </summary>
 /// <param name="username">Your username</param>
 /// <param name="password">Your password</param>
 /// <param name="baseUri">Base SendGrid API Uri</param>
 /// <param name="apiVersion">The SendGrid API version. Please note: currently, only 'v3' is supported</param>
 /// <param name="httpClient">Allows you to inject your own HttpClient. This is useful, for example, to setup the HtppClient with a proxy</param>
 /// <param name="retryStrategy">The retry strategy.</param>
 public Client(string username, string password, string baseUri = DEFAULT_BASE_URI, string apiVersion = DEFAULT_API_VERSION, HttpClient httpClient = null, IRetryStrategy retryStrategy = null)
     : this(null, username, password, baseUri, apiVersion, httpClient, retryStrategy)
 {
 }
コード例 #28
0
ファイル: Attempt.cs プロジェクト: pkudrel/Syrup
 /// <summary>
 /// Repeatedly yields a lazy invocation attempt of the factory as an enumerable.
 /// </summary>
 /// <param name="default">The result value when not successful.</param>
 public static IEnumerable <Lazy <Attempt <T> > > Get <T>(this IRetryStrategy retryStrategy, Func <T> factory,
                                                          T @default = default(T), CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Attempt.Repeatedly.Get(factory, @default).UsingStrategy(retryStrategy, cancellationToken));
 }
コード例 #29
0
ファイル: Client.cs プロジェクト: thinkingserious/StrongGrid
        private Client(string apiKey, string username, string password, string baseUri, string apiVersion, HttpClient httpClient, IRetryStrategy retryStrategy)
        {
            _baseUri       = new Uri(string.Format("{0}/{1}", baseUri, apiVersion));
            _retryStrategy = retryStrategy ?? new SendGridRetryStrategy();

            Alerts             = new Alerts(this);
            ApiKeys            = new ApiKeys(this);
            Batches            = new Batches(this);
            Blocks             = new Blocks(this);
            Campaigns          = new Campaigns(this);
            Categories         = new Categories(this);
            Contacts           = new Contacts(this);
            CustomFields       = new CustomFields(this);
            GlobalSuppressions = new GlobalSuppressions(this);
            InvalidEmails      = new InvalidEmails(this);
            Lists             = new Lists(this);
            Mail              = new Mail(this);
            Segments          = new Segments(this);
            SenderIdentities  = new SenderIdentities(this);
            Settings          = new Settings(this);
            SpamReports       = new SpamReports(this);
            Statistics        = new Statistics(this);
            Suppressions      = new Suppressions(this);
            Templates         = new Templates(this);
            UnsubscribeGroups = new UnsubscribeGroups(this);
            User              = new User(this);
            Version           = typeof(Client).GetTypeInfo().Assembly.GetName().Version.ToString();
            Whitelabel        = new Whitelabel(this);

            _mustDisposeHttpClient  = httpClient == null;
            _httpClient             = httpClient ?? new HttpClient();
            _httpClient.BaseAddress = _baseUri;
            _httpClient.DefaultRequestHeaders.Accept.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MEDIA_TYPE));
            if (!string.IsNullOrEmpty(apiKey))
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
            }
            if (!string.IsNullOrEmpty(username))
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(username, ":", password))));
            }
            _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", string.Format("StrongGrid/{0}", Version));
        }
コード例 #30
0
 public RetryWithCircuitBreakerStrategy(RecoveryOptions options, ICircuitBreaker circuitBreaker, IRetryStrategy retry)
 {
     _options        = options;
     _circuitBreaker = circuitBreaker;
     _retry          = retry;
 }
コード例 #31
0
 /// <summary>
 /// Start a new retriable task for a function.
 /// </summary>
 /// <param name="function">The function for which to start a retriable task.</param>
 /// <param name="cancellationToken">The token with which cancellation is signalled.</param>
 /// <param name="strategy">The retry strategy.</param>
 /// <returns>A task which completes when the function is complete.</returns>
 public Task <T> StartNew(Func <T> function, CancellationToken cancellationToken, IRetryStrategy strategy)
 {
     return(this.StartNew(function, cancellationToken, strategy, new AnyException()));
 }
コード例 #32
0
 public CouchbaseLiteHttpClient GetHttpClient(CookieStore cookieStore, IRetryStrategy strategy, bool allowSelfSigned)
コード例 #33
0
 /// <summary>
 /// Start a new retriable task for a function.
 /// </summary>
 /// <param name="function">The function for which to start a retriable task.</param>
 /// <param name="state">The state to pass to the task on creation.</param>
 /// <param name="taskCreationOptions">The task creation options.</param>
 /// <param name="strategy">The retry strategy.</param>
 /// <returns>A task which completes when the function is complete.</returns>
 public Task <T> StartNew(Func <object, T> function, object state, TaskCreationOptions taskCreationOptions, IRetryStrategy strategy)
 {
     return(this.StartNew(function, state, taskCreationOptions, strategy, new AnyException()));
 }
コード例 #34
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OktaClient"/> class using the specified <see cref="HttpClient"/>.
        /// </summary>
        /// <param name="apiClientConfiguration">
        /// The client configuration. If <c>null</c>, the library will attempt to load
        /// configuration from an <c>okta.yaml</c> file or environment variables.
        /// </param>
        /// <param name="httpClient">The HTTP client to use for requests to the Okta API.</param>
        /// <param name="logger">The logging interface to use, if any.</param>
        /// <param name="retryStrategy">The retry strategy interface to use, if any.</param>
        /// <param name="serializer">The JSON serializer to use, if any. Using the <c>DefaultSerializer</c> is still strongly recommended since it has all the behavior this SDK needs to work properly.
        /// If a custom serializer is used, the developer is responsible to add the required logic for this SDK to continue working properly. See <see cref="DefaultSerializer"/> to check out what settings can be configured.
        /// </param>
        public OktaClient(OktaClientConfiguration apiClientConfiguration, HttpClient httpClient, ILogger logger = null, IRetryStrategy retryStrategy = null, ISerializer serializer = null)
        {
            Configuration = GetConfigurationOrDefault(apiClientConfiguration);
            OktaClientConfigurationValidator.Validate(Configuration);

            logger     = logger ?? NullLogger.Instance;
            serializer = serializer ?? new DefaultSerializer();

            var requestExecutor = new DefaultRequestExecutor(Configuration, httpClient, logger, retryStrategy);
            var resourceFactory = new ResourceFactory(this, logger);

            _dataStore = new DefaultDataStore(
                requestExecutor,
                serializer,
                resourceFactory,
                logger);
        }
コード例 #35
0
 /// <summary>
 /// Start a new retriable task for a function.
 /// </summary>
 /// <param name="function">The function for which to start a retriable task.</param>
 /// <param name="cancellationToken">The token with which cancellation is signalled.</param>
 /// <param name="taskCreationOptions">The task creation options.</param>
 /// <param name="scheduler">The task scheduler.</param>
 /// <param name="strategy">The retry strategy.</param>
 /// <returns>A task which completes when the function is complete.</returns>
 public Task <T> StartNew(Func <T> function, CancellationToken cancellationToken, TaskCreationOptions taskCreationOptions, TaskScheduler scheduler, IRetryStrategy strategy)
 {
     return(this.StartNew(function, cancellationToken, taskCreationOptions, scheduler, strategy, new AnyException()));
 }
コード例 #36
0
 public TransientErrorRetryHandler(HttpMessageHandler handler, IRetryStrategy strategy) : base(handler)
 {
     InnerHandler   = handler;
     _retryStrategy = strategy;
 }
コード例 #37
0
 /// <summary>
 /// Start a new retriable task for a function.
 /// </summary>
 /// <param name="function">The function for which to start a retriable task.</param>
 /// <param name="strategy">The retry strategy.</param>
 /// <param name="policy">The retry policy.</param>
 /// <returns>A task which completes when the function is complete.</returns>
 public Task <T> StartNew(Func <T> function, IRetryStrategy strategy, IRetryPolicy policy)
 {
     return(Task <T> .Factory.StartNew(function).ContinueWith(t => HandleTask(t, () => new Task <T>(function), strategy, policy)));
 }
        /// <summary>
        /// Build a pipeline of HttpMessageHandlers.
        /// </summary>
        internal HttpMessageHandler BuildHandlerPipeline (CookieStore store, IRetryStrategy retryStrategy)
        {
            var handler = new WebRequestHandler {
                CookieContainer = store,
                UseCookies = true,
                ReadWriteTimeout = (int)SocketTimeout.TotalMilliseconds
            };

            // For now, we are not using the client cert for identity verification, just to
            // satisfy Mono so it doesn't matter if the user doesn't choose it.
            //handler.ClientCertificates.Add(SSLGenerator.GetOrCreateClientCert());

            if(handler.SupportsAutomaticDecompression) {
                handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            }

            var authHandler = new DefaultAuthHandler (handler, store, SocketTimeout);
            if (retryStrategy == null) {
                return authHandler;
            }

            var retryHandler = new TransientErrorRetryHandler(authHandler, retryStrategy);
            return retryHandler;
        }
コード例 #39
0
 /// <summary>
 /// Start a new retriable task for a function.
 /// </summary>
 /// <param name="function">The function for which to start a retriable task.</param>
 /// <param name="state">The state to pass to the task on creation.</param>
 /// <param name="taskCreationOptions">The task creation options.</param>
 /// <param name="strategy">The retry strategy.</param>
 /// <param name="policy">The retry policy.</param>
 /// <returns>A task which completes when the function is complete.</returns>
 public Task <T> StartNew(Func <object, T> function, object state, TaskCreationOptions taskCreationOptions, IRetryStrategy strategy, IRetryPolicy policy)
 {
     return(Task <T> .Factory.StartNew(function, state, taskCreationOptions).ContinueWith(t => HandleTask(t, () => new Task <T>(function, state, taskCreationOptions), strategy, policy)));
 }
コード例 #40
0
ファイル: Reliable.cs プロジェクト: mletunov/SolutionsNet
 public Reliable(IRetryStrategy retry, Func <Int32, Exception, TimeSpan?> delay)
     : this(ToFunc(retry), delay)
 {
 }
コード例 #41
0
 /// <summary>
 /// Start a new retriable task for a function.
 /// </summary>
 /// <param name="function">The function for which to start a retriable task.</param>
 /// <param name="state">The state to pass to the task on creation.</param>
 /// <param name="cancellationToken">The token with which cancellation is signalled.</param>
 /// <param name="strategy">The retry strategy.</param>
 /// <param name="policy">The retry policy.</param>
 /// <returns>A task which completes when the function is complete.</returns>
 public Task <T> StartNew(Func <object, T> function, object state, CancellationToken cancellationToken, IRetryStrategy strategy, IRetryPolicy policy)
 {
     return(Task <T> .Factory.StartNew(function, state, cancellationToken).ContinueWith(t => HandleTask(t, () => new Task <T>(function, state, cancellationToken), strategy, policy)));
 }
コード例 #42
0
 /// <summary>
 /// Initializes a new instance of AddJitterRetryStrategy using a range of 0% (inclusive) to 100% (exclusive).
 /// </summary>
 /// <param name="inner">
 /// The IRetryStrategy to add the jitter to.
 /// </param>
 public AddJitterRetryStrategy(IRetryStrategy inner)
     : this(inner, 0, 1)
 {
 }
コード例 #43
0
 /// <summary>
 /// Start a new retriable task for a function.
 /// </summary>
 /// <param name="function">The function for which to start a retriable task.</param>
 /// <param name="cancellationToken">The token with which cancellation is signalled.</param>
 /// <param name="taskCreationOptions">The task creation options.</param>
 /// <param name="scheduler">The task scheduler.</param>
 /// <param name="strategy">The retry strategy.</param>
 /// <param name="policy">The retry policy.</param>
 /// <returns>A task which completes when the function is complete.</returns>
 public Task <T> StartNew(Func <T> function, CancellationToken cancellationToken, TaskCreationOptions taskCreationOptions, TaskScheduler scheduler, IRetryStrategy strategy, IRetryPolicy policy)
 {
     return(Task <T> .Factory.StartNew(function, cancellationToken, taskCreationOptions, scheduler).ContinueWith(t => HandleTask(t, () => new Task <T>(function, cancellationToken, taskCreationOptions), strategy, policy)));
 }
コード例 #44
0
 /// <inheritdoc />
 /// <summary>
 /// Create retry with 20ms and with error handler.
 /// </summary>
 /// <param name="retryStrategy"></param>
 /// <param name="errorHandlerStrategy"></param>
 protected WithRetryAndErrorHandler(IRetryStrategy retryStrategy, IErrorHandlerStrategy errorHandlerStrategy) : this(retryStrategy, errorHandlerStrategy, TimeSpan.FromMilliseconds(Constant.DefaultDelay))
 {
 }
コード例 #45
0
 /// <inheritdoc />
 /// <summary>
 /// Create retry with error handler.
 /// </summary>
 /// <param name="retryStrategy"></param>
 /// <param name="errorHandlerStrategy"></param>
 /// <param name="delay"></param>
 protected WithRetryAndErrorHandler(IRetryStrategy retryStrategy, IErrorHandlerStrategy errorHandlerStrategy, TimeSpan delay) : base(retryStrategy, delay)
 {
     _errorHandlerStrategy = errorHandlerStrategy;
 }
コード例 #46
0
		/// <summary>
		/// Initializes a new instance of the ReliableConnection class.
		/// </summary>
		/// <param name="innerConnection">The inner connection to wrap.</param>
		/// <param name="retryStrategy">The retry strategy to use.</param>
		public ReliableConnection(DbConnection innerConnection, IRetryStrategy retryStrategy) : base(innerConnection)
		{
			RetryStrategy = retryStrategy;
		}
コード例 #47
0
 public TransientErrorRetryHandler(HttpMessageHandler handler, IRetryStrategy strategy) : base(handler) 
 { 
     InnerHandler = handler;
     _retryStrategy = strategy;
 }