Esempio n. 1
0
 public EventSubscriber(string shoppingCartHost)
 {
     this.shoppingCartHost = shoppingCartHost;
     this.timer            = new Timer(10 * 1000);
     WriteLine("subscriber created");
     this.timer.AutoReset = false;
     this.timer.Elapsed  += (_, __) =>
     {
         StandardRetryPolicy.StandardRetry(() =>
         {
             SubscriptionCycleCallback().Wait();
             retryCount++;
         });
     };
 }
        private void BuildRuntimePipeline()
        {
#if BCL
            var httpRequestFactory = new HttpWebRequestFactory(new AmazonSecurityProtocolManager());
            var httpHandler        = new HttpHandler <Stream>(httpRequestFactory, this);
#else
            var httpRequestFactory = new HttpRequestMessageFactory(this.Config);
            var httpHandler        = new HttpHandler <System.Net.Http.HttpContent>(httpRequestFactory, this);
#endif
            var preMarshallHandler = new CallbackHandler();
            preMarshallHandler.OnPreInvoke = this.ProcessPreRequestHandlers;

            var postMarshallHandler = new CallbackHandler();
            postMarshallHandler.OnPreInvoke = this.ProcessRequestHandlers;

            var postUnmarshallHandler = new CallbackHandler();
            postUnmarshallHandler.OnPostInvoke = this.ProcessResponseHandlers;

            var errorCallbackHandler = new ErrorCallbackHandler();
            errorCallbackHandler.OnError = this.ProcessExceptionHandlers;

            //Determine which retry policy to use based on the retry mode
            RetryPolicy retryPolicy;
            switch (this.Config.RetryMode)
            {
            case RequestRetryMode.Adaptive:
                retryPolicy = new AdaptiveRetryPolicy(this.Config);
                break;

            case RequestRetryMode.Standard:
                retryPolicy = new StandardRetryPolicy(this.Config);
                break;

            case RequestRetryMode.Legacy:
                retryPolicy = new DefaultRetryPolicy(this.Config);
                break;

            default:
                throw new InvalidOperationException("Unknown retry mode");
            }

            // Build default runtime pipeline.
            this.RuntimePipeline = new RuntimePipeline(new List <IPipelineHandler>
            {
                httpHandler,
                new Unmarshaller(this.SupportResponseLogging),
                new ErrorHandler(_logger),
                postUnmarshallHandler,
                new Signer(),
                //EndpointDiscoveryResolver must come after CredentialsRetriever, RetryHander, and EndpointResolver as it depends on
                //credentials, retrying of requests for 421 web exceptions, and the current set regional endpoint.
                new EndpointDiscoveryHandler(),
                new CredentialsRetriever(this.Credentials),
                new RetryHandler(retryPolicy),
                postMarshallHandler,
                new EndpointResolver(),
                new Marshaller(),
                preMarshallHandler,
                errorCallbackHandler,
                new MetricsHandler()
            },
                                                       _logger
                                                       );

            if (DeterminedCSMConfiguration.Instance.CSMConfiguration.Enabled && !string.IsNullOrEmpty(ServiceMetadata.ServiceId))
            {
                this.RuntimePipeline.AddHandlerBefore <ErrorHandler>(new CSMCallAttemptHandler());
                this.RuntimePipeline.AddHandlerBefore <MetricsHandler>(new CSMCallEventHandler());
            }

            CustomizeRuntimePipeline(this.RuntimePipeline);

            // Apply global pipeline customizations
            RuntimePipelineCustomizerRegistry.Instance.ApplyCustomizations(this.GetType(), this.RuntimePipeline);
        }