Example #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)
        {
            #region CultureInfo

            CultureInfo[] supportedCultures = { new("pl-PL") };
            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("pl-PL"),
                SupportedCultures     = supportedCultures,
                SupportedUICultures   = supportedCultures
            });

            #endregion

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseStaticFiles();

            app.UseRouting();

            var cookiePolicyOptions = new CookiePolicyOptions {
                MinimumSameSitePolicy = SameSiteMode.Strict
            };

            app.UseCookiePolicy(cookiePolicyOptions);

            app.UseAuthorization();

            app.UseAuthentication();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    "default",
                    "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(
                    "areas",
                    "{area}/{controller}/{action}/{id?}");
                endpoints.MapControllers();
            });

            #region HttpContextAccessor

            // Important Add HttpContextAccessor
            NetAppCommon.HttpContextAccessor.AppContext.Configure(app.ApplicationServices
                                                                  .GetRequiredService <IHttpContextAccessor>());

            #endregion

            #region Migracja bazy danych

            Task.Run(() =>
            {
                try
                {
                    // Migracja bazy danych Knf.DataBase.Data.DataBaseContext
                    EntityContextHelper.RunMigrationAsync <Knf.DataBase.Data.DataBaseContext>(app.ApplicationServices)
                    .Wait();
                }
                catch (Exception e)
                {
                    _log4Net.Error(e);
                    if (null != e.InnerException)
                    {
                        _log4Net.Error(e.InnerException);
                    }
                }
            }).Wait();


            Task.Run(() =>
            {
                try
                {
                    // Migracja bazy danych PortalApiGus.ApiRegon.DataBase.Data.DataBaseContext
                    EntityContextHelper.RunMigrationAsync <DataBaseContext>(app.ApplicationServices)
                    .Wait();
                }
                catch (Exception e)
                {
                    _log4Net.Error(e);
                    if (null != e.InnerException)
                    {
                        _log4Net.Error(e.InnerException);
                    }
                }
            }).Wait();

            Task.Run(() =>
            {
                try
                {
                    // Migracja bazy danych ApiWykazuPodatnikowVatData.Data.ApiWykazuPodatnikowVatDataDbContext
                    EntityContextHelper.RunMigrationAsync <ApiWykazuPodatnikowVatDataDbContext>(app.ApplicationServices)
                    .Wait();
                }
                catch (Exception e)
                {
                    _log4Net.Error(e);
                    if (null != e.InnerException)
                    {
                        _log4Net.Error(e.InnerException);
                    }
                }
            }).Wait();

            Task.Run(() =>
            {
                try
                {
                    // Migracja bazy danych Vies.Core.Database.Data.ViesCoreDatabaseContext
                    EntityContextHelper.RunMigrationAsync <ViesCoreDatabaseContext>(app.ApplicationServices).Wait();
                }
                catch (Exception e)
                {
                    _log4Net.Error(e);
                    if (null != e.InnerException)
                    {
                        _log4Net.Error(e.InnerException);
                    }
                }
            }).Wait();

            Task.Run(() =>
            {
                try
                {
                    // Migracja bazy danych Knf.DataBase.Data.DataBaseContext
                    EntityContextHelper.RunMigrationAsync <Knf.DataBase.Data.DataBaseContext>(app.ApplicationServices)
                    .Wait();
                }
                catch (Exception e)
                {
                    _log4Net.Error(e);
                    if (null != e.InnerException)
                    {
                        _log4Net.Error(e.InnerException);
                    }
                }
            }).Wait();

            Task.Run(() =>
            {
                try
                {
                    // Migracja bazy danych EulerHermes.DataBase.Data.DataBaseContext
                    EntityContextHelper
                    .RunMigrationAsync <EulerHermes.DataBase.Data.DataBaseContext>(app.ApplicationServices).Wait();
                }
                catch (Exception e)
                {
                    _log4Net.Error(e);
                    if (null != e.InnerException)
                    {
                        _log4Net.Error(e.InnerException);
                    }
                }
            }).Wait();

            #endregion
        }