Пример #1
0
        /// <summary>
        /// Configures the services.
        /// </summary>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory, IConfiguration configuration, IStorageEngine store)
        {
            app.UseCors(builder => builder
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin()
                        .WithExposedHeaders("Content-Range", "Content-Length", "Content-Encoding"));

            app.Map("/stream", managedWebSocketsApp =>
            {
                if (bool.Parse(configuration["enable_transaction_stream"]))
                {
                    managedWebSocketsApp.UseWebSockets();
                    managedWebSocketsApp.Use(next => new TransactionStreamMiddleware(next).Invoke);
                }
            });


            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Openchain API");
            });


            // Add MVC to the request pipeline.
            app.UseMvc();

            // Verify the transaction validator
            app.ApplicationServices.GetService <TransactionValidator>();

            // Activate singletons
            TransactionStreamSubscriber subscriber = app.ApplicationServices.GetService <TransactionStreamSubscriber>();

            if (subscriber != null)
            {
                runningTasks.Add(subscriber.Subscribe(CancellationToken.None));
            }

            app.ApplicationServices.GetService <IMutationValidator>();

            LedgerAnchorWorker anchorWorker = app.ApplicationServices.GetService <LedgerAnchorWorker>();

            if (anchorWorker != null)
            {
                runningTasks.Add(anchorWorker.Run(CancellationToken.None));
            }
        }
Пример #2
0
        /// <summary>
        /// Configures the services.
        /// </summary>
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory, IConfiguration configuration, IStorageEngine store)
        {
            app.UseCors(builder => builder
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin()
                        .WithExposedHeaders("Content-Range", "Content-Length", "Content-Encoding"));

            app.UseIISPlatformHandler();

            app.Map("/stream", managedWebSocketsApp =>
            {
                if (bool.Parse(configuration["enable_transaction_stream"]))
                {
                    managedWebSocketsApp.UseWebSockets(new WebSocketOptions()
                    {
                        ReplaceFeature = true
                    });
                    managedWebSocketsApp.Use(next => new TransactionStreamMiddleware(next).Invoke);
                }
            });

            // Add MVC to the request pipeline.
            app.UseMvc();

            // Verify the transaction validator
            app.ApplicationServices.GetService <TransactionValidator>();

            // Activate singletons
            TransactionStreamSubscriber subscriber = app.ApplicationServices.GetService <TransactionStreamSubscriber>();

            if (subscriber != null)
            {
                runningTasks.Add(subscriber.Subscribe(CancellationToken.None));
            }

            app.ApplicationServices.GetService <IMutationValidator>();

            LedgerAnchorWorker anchorWorker = app.ApplicationServices.GetService <LedgerAnchorWorker>();

            if (anchorWorker != null)
            {
                runningTasks.Add(anchorWorker.Run(CancellationToken.None));
            }
        }