当前位置: 首页>>代码示例>>C#>>正文


C# IRetryPolicy类代码示例

本文整理汇总了C#中IRetryPolicy的典型用法代码示例。如果您正苦于以下问题:C# IRetryPolicy类的具体用法?C# IRetryPolicy怎么用?C# IRetryPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IRetryPolicy类属于命名空间,在下文中一共展示了IRetryPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HttpRestClientConfiguration

        public HttpRestClientConfiguration(HttpMessageHandler defaultHttpClientHandler = null,
            IEnumerable<DelegatingHandler> messageProcessingHandlers = null,
            IRetryPolicy retryPolicy = null, 
            TimeSpan? httpRequestTimeout = null)
        {
            this._httpRequestTimeout = httpRequestTimeout ?? TimeSpan.FromMinutes(1);
            this.HttpMessageHandler = defaultHttpClientHandler ?? new HttpClientHandler();
            if (messageProcessingHandlers == null)
            {
                this._additionalDelegatingHandlers = new ReadOnlyCollection<DelegatingHandler>(new List<DelegatingHandler>());
            }
            else
            {
                this._additionalDelegatingHandlers = new ReadOnlyCollection<DelegatingHandler>(messageProcessingHandlers.ToList());
            }

            this.RetryPolicy = retryPolicy ?? new NoRetryPolicy();

            //Here we chain the delegating handlers such that each delegating handler has the next one as its inner handler
            for (int i = this.DelegatingHandlers.Count - 1; i >= 0; i--)
            {
                if (i - 1 >= 0)
                {
                    this.DelegatingHandlers[i - 1].InnerHandler = this.DelegatingHandlers[i];
                }
            }

            //the first delegating handler has the default defaultHttpClientHandler as its inner handler
            if (this.DelegatingHandlers.Any())
            {
                this.DelegatingHandlers.Last().InnerHandler = this.HttpMessageHandler;
            }

        }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:34,代码来源:HttpRestClientConfiguration.cs

示例2: Execute

        public static void Execute(Action method, IRetryPolicy retryPolicy, IBackOffScheme backOffScheme, int numRetries = Constants.LoadBalancingHelperNumRetriesDefault)
        {
            int retryCount = 0;
            bool requestSuccess = false;
            while ((!requestSuccess) && (retryCount < numRetries))
            {
                try
                {
                    method();
                    requestSuccess = true;
                }
                catch (Exception ex)
                {
                    Trace.TraceError("\tAttempt {0} failed with exception {1} - {2}", retryCount, ex.GetType(), ex.Message);

                    retryCount++;
                    if ((retryCount < numRetries) && (retryPolicy.ShouldRetryAttempt(ex)))
                    {
                        var sleepInterval = backOffScheme.GetRetryInterval(retryCount);
                        if (sleepInterval != default (TimeSpan))
                        {
                            Trace.TraceInformation("\tWill retry after {0} milliseconds......", sleepInterval.TotalMilliseconds);
                            Thread.Sleep(sleepInterval);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
开发者ID:gitter-badger,项目名称:hbase-sdk-for-net,代码行数:32,代码来源:LoadBalancingHelper.cs

示例3: DownloadBlob

        public Task DownloadBlob(
            Uri uri,
            string localFile,
            FileEncryption fileEncryption,
            ulong initializationVector,
            CloudBlobClient client,
            CancellationToken cancellationToken,
            IRetryPolicy retryPolicy,
            Func<string> getSharedAccessSignature = null,
            long start = 0,
            long length = -1,
            int parallelTransferThreadCount = 10,
            int numberOfConcurrentTransfers = 2)
        {
            if (client != null && getSharedAccessSignature != null)
            {
                throw new InvalidOperationException("The arguments client and getSharedAccessSignature cannot both be non-null");
            }

            SetConnectionLimits(uri, Environment.ProcessorCount * numberOfConcurrentTransfers * parallelTransferThreadCount);

            Task task =
                Task.Factory.StartNew(
                    () =>
                        DownloadFileFromBlob(uri, localFile, fileEncryption, initializationVector, client,
                            cancellationToken, retryPolicy, getSharedAccessSignature, start: start, length: length,
                            parallelTransferThreadCount: parallelTransferThreadCount));
            return task;
        }
开发者ID:shushengli,项目名称:azure-sdk-for-media-services,代码行数:29,代码来源:BlobDownloader.cs

示例4: ExecuteReaderAsyncWithRetry

 public static Task<SqlDataReader> ExecuteReaderAsyncWithRetry(
                                                               SqlCommand command,
                                                               CommandBehavior behavior,
                                                               IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteReaderAsync(behavior));
 }
开发者ID:cleverguy25,项目名称:Fleeting,代码行数:7,代码来源:SqlCommandExtensions.cs

示例5: ExecuteNonQueryAsyncWithRetry

 public static Task<int> ExecuteNonQueryAsyncWithRetry(
                                                       SqlCommand command,
                                                       CancellationToken cancellationToken,
                                                       IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteNonQueryAsync(cancellationToken));
 }
开发者ID:cleverguy25,项目名称:Fleeting,代码行数:7,代码来源:SqlCommandExtensions.cs

示例6: UploadBlob

 public Task UploadBlob(
     Uri url,
     string localFile,
     FileEncryption fileEncryption,
     CancellationToken cancellationToken,
     CloudBlobClient client,
     IRetryPolicy retryPolicy,
     string contentType = null,
     string subDirectory = "",
     Func<string> getSharedAccessSignature = null)
 {
     SetConnectionLimits(url);
     return Task.Factory.StartNew(
         () => UploadFileToBlob(
             cancellationToken,
             url,
             localFile,
             contentType,
             subDirectory,
             fileEncryption,
             client,
             retryPolicy,
             getSharedAccessSignature),
         cancellationToken);
 }
开发者ID:Ginichen,项目名称:azure-sdk-for-media-services,代码行数:25,代码来源:BlobUploader.cs

示例7: HaConnection

        /// <summary>
        /// Initialize a <see cref="HaConnection"/> with a list of <see cref="ManagedConnectionFactory"/>
        /// These connection factories are responsibile for creating <see cref="IConnection"/> to nodes in the clusters
        /// </summary>
        /// <param name="retryPolicy"></param>
        /// <param name="watcher"></param>
        /// <param name="connectionFactories"></param>
        public HaConnection(IRetryPolicy retryPolicy, IRabbitWatcher watcher, IList<ManagedConnectionFactory> connectionFactories) : base(retryPolicy, watcher)
        {        
            _connectionFactories = new RoundRobinList<ConnectionFactory>(connectionFactories);
            ConnectionEstablished handler = (endpoint, virtualHost) =>
            {
                if (_connectionFactories.All.Any(f => f.Endpoint + f.VirtualHost == endpoint + virtualHost))
                {
                    if (!IsConnected)
                    {
                        while (_connectionFactories.Current.Endpoint + _connectionFactories.Current.VirtualHost != endpoint + virtualHost)
                        {
                            //IF there are 2 different Tunnels using 2 HaConnection with 2 lists of cluster nodes in different orders:
                            //Example:

                            // ConnectionString1: host=q1;username=guest;password=guest|host=q2;username=guest;password=guest|host=q3;username=guest;password=guest
                            // ConnectionString2: host=q2;username=guest;password=guest|host=q3;username=guest;password=guest|host=q1;username=guest;password=guest

                            // When the first tunnel established the connection successfully to q1, it fires event and these lines of code is triggered.
                            // The 2nd HaConnection needs to set it's _connectionFactories.Current to q1 established by other tunnel. Before changing, _connectionFactories.Current is q3 by the order in the ConnectionString2 
                            _connectionFactories.GetNext();
                        }
                    }

                    FireConnectedEvent();
                }
            };
            ManagedConnectionFactory.ConnectionEstablished += handler;
            _unsubscribeEvents = () => { ManagedConnectionFactory.ConnectionEstablished -= handler; };
        }
开发者ID:vanthoainguyen,项目名称:Burrow.NET,代码行数:36,代码来源:HaConnection.cs

示例8: OpenAsyncWithRetry

 public static Task OpenAsyncWithRetry(
                                       this SqlConnection connection,
                                       CancellationToken cancellationToken,
                                       IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => connection.OpenAsync(cancellationToken));
 }
开发者ID:cleverguy25,项目名称:Fleeting,代码行数:7,代码来源:SqlConnectionExtensions.cs

示例9: UploadBlob

 public Task UploadBlob(
     Uri url,
     string localFile,
     FileEncryption fileEncryption,
     CancellationToken cancellationToken,
     CloudBlobClient client,
     IRetryPolicy retryPolicy,
     string contentType = null,
     string subDirectory = "",
     Func<string> getSharedAccessSignature = null,
     int parallelTransferThreadCount = 10,
     int numberOfConcurrentTransfers = default(int))
 {
     SetConnectionLimits(url, numberOfConcurrentTransfers);
     return Task.Factory.StartNew(
         () => UploadFileToBlob(
             cancellationToken,
             url,
             localFile,
             contentType,
             subDirectory,
             fileEncryption,
             client,
             retryPolicy,
             getSharedAccessSignature,
             parallelTransferThreadCount),
             cancellationToken);
 }
开发者ID:JeromeZhao,项目名称:azure-sdk-for-media-services,代码行数:28,代码来源:BlobUploader.cs

示例10: EventStreamProducer

        public EventStreamProducer(IEventStreamWriter streamWriter, IRetryPolicy retryPolicy)
        {
            Require.NotNull(streamWriter, "streamWriter");
            Require.NotNull(retryPolicy, "retryPolicy");

            m_streamWriter = streamWriter;
            m_retryPolicy = retryPolicy;
        }
开发者ID:savamura,项目名称:Journalist,代码行数:8,代码来源:EventStreamProducer.cs

示例11: Policies

 /// <summary>
 ///  Creates a new <code>Policies</code> object using the provided policies.
 /// </summary>
 /// <param name="loadBalancingPolicy"> the load balancing policy to use. </param>
 /// <param name="reconnectionPolicy"> the reconnection policy to use. </param>
 /// <param name="retryPolicy"> the retry policy to use.</param>
 public Policies(ILoadBalancingPolicy loadBalancingPolicy,
                 IReconnectionPolicy reconnectionPolicy,
                 IRetryPolicy retryPolicy)
 {
     this._loadBalancingPolicy = loadBalancingPolicy;
     this._reconnectionPolicy = reconnectionPolicy;
     this._retryPolicy = retryPolicy;
 }
开发者ID:hjarraya,项目名称:csharp-driver,代码行数:14,代码来源:Policies.cs

示例12: AbstractionContext

 /// <summary>
 /// Initializes a new instance of the AbstractionContext class.
 /// </summary>
 /// <param name="tokenSource">A Cancellation token source.</param>
 /// <param name="logger">A logger instance.</param>
 /// <param name="httpOperationTimeout">The HTTP operation timeout.</param>
 /// <param name="retryPolicy">The retry policy.</param>
 public AbstractionContext(CancellationTokenSource tokenSource, ILogger logger, TimeSpan httpOperationTimeout, IRetryPolicy retryPolicy)
 {
     this.RetryPolicy = retryPolicy;
     tokenSource.ArgumentNotNull("tokenSource");
     logger.ArgumentNotNull("logger");
     this.CancellationTokenSource = tokenSource;
     this.Logger = logger;
     this.HttpOperationTimeout = httpOperationTimeout;
 }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:16,代码来源:AbstractionContext.cs

示例13: HttpRestClientRetryPolicy

        public HttpRestClientRetryPolicy(IRetryPolicy retryPolicy)
        {
            if (retryPolicy == null)
            {
                throw new ArgumentNullException("retryPolicy");
            }

            this.retryPolicy = retryPolicy;
        }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:9,代码来源:HttpRestClientRetryPolicy.cs

示例14: ElasticRequestProcessor

        public ElasticRequestProcessor(IElasticConnection connection, IElasticMapping mapping, ILog log, IRetryPolicy retryPolicy)
        {
            Argument.EnsureNotNull("connection", connection);
            Argument.EnsureNotNull("mapping", mapping);
            Argument.EnsureNotNull("log", log);
            Argument.EnsureNotNull("retryPolicy", retryPolicy);

            this.connection = connection;
            this.mapping = mapping;
            this.log = log;
            this.retryPolicy = retryPolicy;
        }
开发者ID:jarlrasm,项目名称:ElasticLINQ,代码行数:12,代码来源:ElasticRequestProcessor.cs

示例15: AzureTableDefaultPolicies

        static AzureTableDefaultPolicies()
        {
            MaxTableCreationRetries = 60;
            PauseBetweenTableCreationRetries = TimeSpan.FromSeconds(1);

            MaxTableOperationRetries = 5;
            PauseBetweenTableOperationRetries = TimeSpan.FromMilliseconds(100);

            MaxBusyRetries = 120;
            PauseBetweenBusyRetries = TimeSpan.FromMilliseconds(500);
#if DEBUG
            if (Debugger.IsAttached)
            {
                PauseBetweenTableCreationRetries = PauseBetweenTableCreationRetries.Multiply(100);
                PauseBetweenTableOperationRetries = PauseBetweenTableOperationRetries.Multiply(100);
                PauseBetweenBusyRetries = PauseBetweenBusyRetries.Multiply(10);
            }
#endif
            TableCreationRetryPolicy = new LinearRetry(PauseBetweenTableCreationRetries, MaxTableCreationRetries); // 60 x 1s
            TableCreationTimeout = PauseBetweenTableCreationRetries.Multiply(MaxTableCreationRetries).Multiply(3);    // 3 min

            TableOperationRetryPolicy = new LinearRetry(PauseBetweenTableOperationRetries, MaxTableOperationRetries); // 5 x 100ms
            TableOperationTimeout = PauseBetweenTableOperationRetries.Multiply(MaxTableOperationRetries).Multiply(6);    // 3 sec

            BusyRetriesTimeout = PauseBetweenBusyRetries.Multiply(MaxBusyRetries);  // 1 minute
        }
开发者ID:stanroze,项目名称:orleans,代码行数:26,代码来源:AzureTableDefaultPolicies.cs


注:本文中的IRetryPolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。