Example #1
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              SeedManager seedManager,
                              MigrationManager migrationManager)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                loggerFactory.AddSerilog();
                Log.Logger().Information("Application is starting...");
                Log.Logger().Information("Configuration:");

                ConfigurationProvider.GetType().GetProperties().ToList().ForEach(prop =>
                {
                    Log.Logger().Information("[{name}] = '{value}'", prop.Name, prop.GetValue(ConfigurationProvider));
                });

                DateTimeContext.Initialize(ConfigurationProvider.TimeZone);

                Log.Logger().Information("Configure EF Mappings...");
                MappingConfig.RegisterMappings();

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseDatabaseErrorPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error"); //todo IS incorrect page diesnt exist yet!!
                    app.UseHsts();
                    app.UseHttpsRedirection();
                }

                app.UseStaticFiles(new StaticFileOptions {
                    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot"))
                });
                app.UseSession();
                app.UseAuthentication();

                app.UseMvc(routes =>
                {
                    routes.MapRoute(name: "Area", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
                    routes.MapRoute(name: "Area2", template: "{area:exists}/{controller=Home}/{action=Index}/{isReadonly?}");

                    routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
                    routes.MapRoute(name: "default2", template: "{controller=Home}/{action=Index}/{isReadonly?}");
                });

                //migrationManager.EnsureCreated(ConfigurationProvider);
                //migrationManager.ApplyMigrations(ConfigurationProvider);
                seedManager.Seed(ConfigurationProvider);
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");

                throw;
            }
            finally
            {
                stopwatch.Stop();
                Log.Logger().Information("Startup time: {Seconds}s", stopwatch.Elapsed.Seconds);
            }
        }
Example #2
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, BasicSeedManager seedManager, MigrationManager migrationManager)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                loggerFactory.AddSerilog();

                Log.Logger().Information("Application is starting...");
                Log.Logger().Information("Configuration:");

                ConfigurationProvider.GetType().GetProperties().ToList().ForEach(prop =>
                {
                    Log.Logger().Information("[{name}] = '{value}'", prop.Name,
                                             prop.GetValue(ConfigurationProvider));
                });

                DateTimeContext.Initialize(ConfigurationProvider.TimeZone);

                Log.Logger().Information("Configure EF Mappings...");
                MappingConfig.RegisterMappings();


                Log.Logger().Information("Configure Jwt Bearer Authentication...");
                app.ConfigJwtBearerMiddleware();

                app.UseDefaultFiles();
                app.UseStaticFiles();

                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Default}/{action=Index}/{id?}");

                    routes.MapRoute(
                        name: "admin",
                        template: "{*url}",
                        defaults: new { controller = "Default", action = "Index" }
                        );
                });



                //app.Use(async (context, next) =>
                //{
                //  await next();
                //  if (context.Response.StatusCode == 404 &&
                //      !Path.HasExtension(context.Request.Path.Value) &&
                //      !context.Request.Path.Value.StartsWith("/api/"))
                //  {
                //    context.Request.Path = "/index.html";
                //    await next();
                //  }
                //});

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

                    migrationManager.ApplyMigrations(ConfigurationProvider);

                    //seedManager.Seed();
                }
                else
                {
                    app.UseExceptionHandler("/error");
                }
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");
                throw;
            }
            finally
            {
                stopwatch.Stop();
                Log.Logger().Information("Startup time: {Seconds}s", stopwatch.Elapsed.Seconds);
            }
        }