Exemple #1
0
        public FileStitchController(ITopicClient topic, IHttpMessageFactory httpMessageFactory)
        {
            this.topic = topic ?? throw new ArgumentNullException(nameof(topic));
            this.httpMessageFactory = httpMessageFactory ?? throw new ArgumentNullException(nameof(httpMessageFactory));

            // asyncronously handle transient exceptions by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policy = Policy.Handle <Exception>().WaitAndRetryAsync(Constants.MAX_TRANSIENT_EXCEPTIONS, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));

            // syncronously handle transient file IO exceptions (excluding security exceptions) by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policyFile = Policy.Handle <Exception>(ex => !(ex is SecurityException || ex is UnauthorizedAccessException))
                         .WaitAndRetry(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));
        }
        public OnPremUploadDownloadController(ITopicClient topic, CloudBlobContainer container, IHttpMessageFactory messageFactory, IConfiguration config)
        {
            this.topic          = topic ?? throw new ArgumentNullException(nameof(topic));
            this.container      = container ?? throw new ArgumentNullException(nameof(container));
            this.messageFactory = messageFactory ?? throw new ArgumentNullException(nameof(messageFactory));
            this.config         = config ?? throw new ArgumentNullException(nameof(config));

            // asyncronously handle transient exceptions by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policy = Policy.Handle <Exception>().WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));

            // syncronously handle transient file IO exceptions (excluding security exceptions) by waiting 0.5 seconds, 2 seconds, 4 seconds, etc., before retrying, and finally throwing the exception
            policyFile = Policy.Handle <Exception>(ex => !(ex is SecurityException || ex is UnauthorizedAccessException))
                         .WaitAndRetry(3, i => TimeSpan.FromSeconds(0.5 * Math.Pow(2, i)));
        }