예제 #1
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            //Set global date, ovverride if set
            var options = new DateSettings();

            Configuration.GetSection("DateSettings").Bind(options);
            setApplicationDate(options.CurrentDateOverride);
        }
예제 #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,
                              RoleManager <IdentityRole> roleManager,
                              IBusinessDateRepository businessDateRepository,
                              IDateService dateService,
                              IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                Console.WriteLine("In Development mode");
                Console.WriteLine("Database Connection String: " + Configuration.GetConnectionString("Default"));
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseExceptionHandler(
                builder =>
            {
                builder.Run(
                    async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                    var error = context.Features.Get <IExceptionHandlerFeature>();
                    if (error != null)
                    {
                        //context.Response.AddApplicationError(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);
                    }
                });
            });

            app.UseAuthentication();
            app.UseDefaultFiles();
            app.UseCors("AllowAll");
            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
            app.UseAuthentication();

            //Create Roles if not exist
            //CORE DUMP ONCE SET!!!!!!!! TODO!!!!!!
            CreateUserRoles(serviceProvider).Wait();

            //Create Admin User if not exist
            CreateAdminUser(serviceProvider).Wait();

            //Create List Of Status if not already set
            CreatePlanningAppStatuses(serviceProvider).Wait();

            //Set global date, ovverride if set
            var options = new DateSettings();

            Configuration.GetSection("DateSettings").Bind(options);
            setApplicationDate(options.CurrentDateOverride, dateService, businessDateRepository);
        }