public void InitializeOk()
        {
            // setup
            this.context = new TemplateDbContext(this.contextOptions);
            var seeder = new TemplateDbContextSeedData(context);

            // action
            seeder.Initialize();
        }
Beispiel #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, TemplateDbContextSeedData seeder)
        {
            loggerFactory.AddConsole();

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

            app.Use(async(context, next) =>
            {
                await next();

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

            string libPath = Path.GetFullPath(Path.Combine(env.WebRootPath, @"..\node_modules\"));

            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(libPath),
                RequestPath  = new PathString("/node_modules")
            });

            app.UseStaticFiles(new StaticFileOptions
            {
        #if DEBUG
                OnPrepareResponse = (context) =>
                {
                    // Disable caching of all static files.
                    context.Context.Response.Headers["Cache-Control"] = "no-cache, no-store";
                    context.Context.Response.Headers["Pragma"]        = "no-cache";
                    context.Context.Response.Headers["Expires"]       = "-1";
                }
        #endif
            });

            app.UseMvc();
            seeder.Initialize();
        }
        /// <summary>
        /// Configures the specified application.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="env">The env.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="seeder">The seeder.</param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, TemplateDbContextSeedData seeder)
        {
            loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            /*loggerFactory
             * .WithFilter(new FilterLoggerSettings
             * {
             * { "TemplateCore", LogLevel.Information }
             * })
             * .AddConsole();*/

            // add Trace Source logging

            /*var testSwitch = new SourceSwitch("sourceSwitch", "Logging");
             * testSwitch.Level = SourceLevels.Warning;
             * loggerFactory.AddTraceSource(testSwitch,
             * new TextWriterTraceListener(writer: Console.Out));*/

            var locOptions = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >();

            app.UseRequestLocalization(locOptions.Value);

            // error handling, while at development mode, show error page.
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();

                // status code pages
                // app.UseStatusCodePages();
                // app.UseStatusCodePagesWithReExecute("/errors/{0}");
                // app.UseExceptionHandler("/Error/Error");
                // app.UseStatusCodePagesWithReExecute("/Error/Errors/{0}");
            }
            else
            {
                // custom error page.
                // app.UseExceptionHandler("/Home/Error");

                // status code pages
                app.UseExceptionHandler("/Error/Error");
                app.UseStatusCodePagesWithReExecute("/Error/Errors/{0}");
            }

            app.UseStaticFiles();
            app.UseIdentity();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            // seed database.
            seeder.Initialize();

            /*// Create a catch-all response
             * app.Run(async (context) =>
             * {
             * if (context.Request.Path.Value.Contains("boom"))
             * {
             *  throw new Exception("boom!");
             * }
             * var logger = loggerFactory.CreateLogger(typeof(UserController));
             * logger.LogInformation("No endpoint found for request {path}", context.Request.Path);
             * await context.Response.WriteAsync("No endpoint found - try /api/todo.");
             * });*/
        }