Пример #1
0
        public void Configure(IApplicationBuilder app)
        {
            if (_hostingEnvironment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/error");
                if (bool.TryParse(_appConfiguration["HSTS"] ?? "False", out var useHsts) && useHsts)
                {
                    app.UseHsts();
                }
            }

            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseStaticFiles();
            app.UseMvc();

            var logger = _loggerFactory.CreateLogger <Startup>();

            app.EnsureDatabase(connStr =>
            {
                logger.LogCritical("正在创建新的数据库结构...");

                var loggingConfig = _appConfiguration.GetSection(Configuration.ConfigKeyLogging);
                SqliteMigrator.Migrate(connStr, migrationLogging => Configuration.ConfigureFileLogging(migrationLogging, loggingConfig, true /* enable full logging for migrations */));

                logger.LogCritical("数据库结构创建完成");
            }, logger);
        }
Пример #2
0
        private void InitDatabaseIfNeeded(IApplicationBuilder app)
        {
            app.EnsureDatabase(connStr =>
            {
                _startupLogger.LogCritical("正在创建新的数据库结构...");

                var loggingConfig = _appConfiguration.GetSection(WebHostConfiguration.ConfigKeyLogging);
                SqliteMigrator.Migrate(connStr, migrationLogging =>
                                       FileLoggingExtensions.AddSeriFileLogger(migrationLogging, loggingConfig /* enable full logging for migrations */));

                _startupLogger.LogCritical("数据库结构创建完成");
            }, _startupLogger);
        }
Пример #3
0
        static void InitializeDatabase(string connectionString, ILogger <Startup> logger, IConfiguration loggingConfiguration)
        {
            var sqliteConnection = new SqliteConnection(connectionString);
            var dataSource       = sqliteConnection.DataSource;

            logger.LogInformation($"数据库位置:{dataSource}");
            if (!File.Exists(dataSource))
            {
                logger.LogCritical("正在创建新的数据库结构...");

                SqliteMigrator.Migrate(connectionString, logging => Configurer.ConfigureFileLogging(logging, true, loggingConfiguration));

                logger.LogCritical("数据库结构创建完成");
            }
        }
Пример #4
0
        public void Configure(IApplicationBuilder app)
        {
            if (_hostingEnvironment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/error");
                if (bool.TryParse(_appConfiguration["HSTS"] ?? "False", out var useHsts) && useHsts)
                {
                    app.UseHsts();
                }
            }

            app.Use(async(ctx, next) =>
            {
                var readonlyDataSettings = ctx.RequestServices.GetService <IReadonlyDataSettings>() as ReadonlyDataSettings;
                Debug.Assert(readonlyDataSettings != null, nameof(readonlyDataSettings) + " != null");

                var siteSettings = ctx.RequestServices.GetService <SiteSettings>();
                readonlyDataSettings.IsReadonly = siteSettings.IsReadonly;
                await next();
            });
            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseStaticFiles();
            app.UseMvc();
            var logger = _loggerFactory.CreateLogger <Startup>();

            app.EnsureDatabase(connStr =>
            {
                logger.LogCritical("正在创建新的数据库结构...");

                var loggingConfig = _appConfiguration.GetSection(Configuration.ConfigKeyLogging);
                SqliteMigrator.Migrate(connStr, migrationLogging => Configuration.ConfigureFileLogging(migrationLogging, loggingConfig, true /* enable full logging for migrations */));

                logger.LogCritical("数据库结构创建完成");
            }, logger);
        }
Пример #5
0
        public void PassingTest()
        {
            var migrator = new SqliteMigrator(new SQLiteConnection("Data Source=migrationDat.db").OpenAndReturn());

            migrator.Migrate();
        }