示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              IMappingService mappingService,
                              IRuntimeCompilerService runtimeCompilerService,
                              IAuthenticationService authService,
                              IRelayService relayService
                              )
        {
            var globalConfig = Configuration.GetSection("Global");

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (globalConfig.GetValue("UseLogFiles", true))
            {
                loggerFactory.AddNLog();

                env.ConfigureNLog("nlog.config");  // <- Throws ArgumentNullException in productive environment
                //LogManager.Configuration = new XmlLoggingConfiguration("nlog.config", true);  // <- Workaround for ArgumentNullException
            }

            runtimeCompilerService.Configure(Configuration.GetSection("RuntimeCompiler"));
            runtimeCompilerService.Init();

            mappingService.Configure(Configuration.GetSection("Plc"));
            mappingService.Init();

            authService.Configure(Configuration.GetSection("Auth"));
            authService.Init();

            app.UseWebPackAuth();

            app.UseCors(options =>
            {
                options.AllowAnyHeader();
                options.AllowAnyMethod();
                options.AllowAnyOrigin();
                options.AllowCredentials();
            });


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }


            if (globalConfig.GetValue("UseSignalR", true))
            {
                relayService.Init();

                if (globalConfig.GetValue("UseWebSockets", true))
                {
                    app.UseWebSockets();
                }
                app.UseSignalR();
            }


            app.UseMvc();

            //Not supported at the moment
            if (globalConfig.GetValue("UseSwagger", true))
            {
                app.UseSwagger();
                app.UseSwaggerUi();
            }
        }