Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              ILogService logService,
                              ILogMessageFactory logMessageFactory,
                              IConnectionProvider connectionProvider,
                              IMqttRepository repository,
                              IMqttCommandAdapter commandAdapter,
                              IAdapterSettingService adapterSettingService,
                              IUiConfigurationService uiConfigurationService,
                              INotificationService notificationService,
                              ISettingsService settingsService,
                              IFileSystemService fileSystemService,
                              ILogFormatterService logFormatterService,
                              ILogFileService logFileService,
                              ISettingsProvider settingsProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            settingsProvider.ReadSettings();

            logService.RegisterSinks(new List <IlogSink>
            {
                new ConsoleLogSink(),
                new MemoryLogSink(logMessageFactory, notificationService),
                new FileLogSink(fileSystemService, logFormatterService, logFileService)
            });

            if (Debugger.IsAttached)
            {
                logService.RegisterSink(new DebugLogSink());
            }

            logService.Log(LogSeverity.Info, "Logging started.");

            var repo = new DatabaseRepository();

            repo.InitializeDatabase();

            commandAdapter.Initialize();
            connectionProvider.InitializeConnection();
            repository.Initialize();
            adapterSettingService.Initialize();
            uiConfigurationService.ReadAllConfigurationFiles();

            ConfigureSystemSpecifics(app.ApplicationServices);
            app.ApplicationServices.GetService <ICustomCommandConfigurationService>().ReloadConfiguration();
        }