Exemple #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, Context context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();
            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

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

            DbSeed.Seed(context);
        }
Exemple #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            DbSeed.Seed(app.ApplicationServices);
            app.UseStaticFiles();
            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseCookiePolicy();
            app.UseStatusCodePages();
            container.AutoCrossWireAspNetComponents(app);
            container.RegisterPageModels(app);
            container.Verify();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext dbContext, ApplicationDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.Use((request, next) =>
            {
                var sv = new CultureInfo("sv-SE");
                System.Threading.Thread.CurrentThread.CurrentCulture   = sv;
                System.Threading.Thread.CurrentThread.CurrentUICulture = sv;
                return(next());
            });

            app.UseStaticFiles();

            app.UseAuthentication();

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

            // DbSeed.Seed(context);
            DbSeed.Seed(dbContext);
        }
Exemple #4
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)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

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

            app.UseStaticFiles();

            app.UseIdentity();

            DbSeed.Seed(app);

            // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemple #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

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

            DbSeed.Seed(context, userManager, roleManager);
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext dBcontext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            DbSeed.Seed(dBcontext);
        }
Exemple #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, DbSeed seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }



            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "area",
                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            seed.Seed();
        }
Exemple #8
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.ApplyConfiguration(new CategoryConfiguration());

            DbSeed.Seed(modelBuilder);
        }
        public void TryLogIn_NullInput_ShouldReturnNull()
        {
            DbSeed.Seed(this.fixture.Context);
            UserViewModel  input      = null;
            UserRepository repository = new UserRepository(fixture.Context);

            Assert.Null(repository.TryLogIn(input));
        }
 public static void Main(string[] args)
 {
     using (var seed = new DbSeed(new Context(options: new DbContextOptionsBuilder().UseSqlite(@"Data Source=.\Data\Data.db").Options)))
     {
         seed.Seed();
     }
     CreateHostBuilder(args).Build().Run();
 }
Exemple #11
0
        public static void Main(string[] args)
        {
            IHost host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                ApplicationDbContext applicationDbContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                DbSeed.Seed(applicationDbContext);
            }

            host.Run();
        }
Exemple #12
0
        // public static void Main(string[] args)
        //{
        //  CreateHostBuilder(args).Build().Run();
        // }

        public static void Main(string[] args)
        {
            IHost host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <MusiCloudContext>();
                DbSeed.Seed(context);
            }
            host.Run();
        }
Exemple #13
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService<QuotesDbContext>();
                await context.Database.MigrateAsync();
                await DbSeed.Seed(context);
            }

            await host.RunAsync();
        }
Exemple #14
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
                using (var context = scope.ServiceProvider.GetService <AppDbContext>())
                {
                    context.Database.EnsureCreated();
                    var passwordHasher = scope.ServiceProvider.GetService <IPasswordHasher>();
                    DbSeed.Seed(context, passwordHasher);
                }

            host.Run();
        }
Exemple #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });

            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var dbContext = serviceScope.ServiceProvider.GetService <WorkAssistantDbContext>();

                dbContext.Database.Migrate();
                DbSeed.Seed(dbContext);
            }
        }
        public void TryLogIn_UserInputWithNotExistingCredentials_ShouldReturnNull(string login, string password)
        {
            DbSeed.Seed(this.fixture.Context);
            User user = new User
            {
                Login    = login,
                Password = password,
            };
            UserViewModel inputUser = new UserViewModel(user);

            UserRepository repository = new UserRepository(fixture.Context);

            var result = repository.TryLogIn(inputUser);

            Assert.Null(result);
        }
Exemple #17
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context,
                              UserManager <ApplicationUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            var suppoertedCultures = new[]
            {
                new CultureInfo("en-US"),
                new CultureInfo("sv-SE")
            };
            var options = new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("sv-SE"),
                SupportedCultures     = suppoertedCultures,
                SupportedUICultures   = suppoertedCultures
            };

            options.RequestCultureProviders = new[]
            {
                new CookieRequestCultureProvider()
                {
                    Options = options
                }
            };
            app.UseRequestLocalization(options);
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}/{slug?}");
            });
            DbSeed.Seed(context, userManager, roleManager);
        }
 private static void CreateDbIfNotExist(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var context = services.GetRequiredService <MyEventsContext>();
             DbSeed.Seed(context);
         }
         catch (Exception ex)
         {
             var logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(ex, "An error occured while creating database!");
         }
     }
 }
        public void TryLogIn_UserInputWithCapitalizedExistingCredentials_ShouldReturnNull()
        {
            DbSeed.Seed(this.fixture.Context);
            User user = new User
            {
                FirstName = "Даша",
                SurName   = "Волкова",
                Login     = "******",
                Password  = "******",
            };
            UserViewModel inputUser = new UserViewModel(user);

            UserRepository repository = new UserRepository(fixture.Context);

            var result = repository.TryLogIn(inputUser);

            Assert.Null(result);
        }
Exemple #20
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    var context = scope.ServiceProvider.GetRequiredService <ShopDbContext>();

                    await context.Database.MigrateAsync();

                    await DbSeed.Seed(context);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
            }

            host.Run();
        }
Exemple #21
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var context = services.GetRequiredService <ConsultantContext>();
                    context.Database.EnsureCreated();
                    DbSeed.Seed(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred creating the DB.");
                }
            }

            host.Run();
        }
Exemple #22
0
 protected override void Seed(MySqlDbContext context)
 {
     DbSeed.Seed(context);
 }
Exemple #23
0
 protected override void Seed(DefaultDbContext context)
 {
     DbSeed.Seed(context);
 }
Exemple #24
0
        public override void Seed(AppTenantsContext context, string tenantId)
        {
            var dbSeeder = new DbSeed();

            dbSeeder.Seed(context, settings.SeedTenants);
        }
Exemple #25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ILoggerFactory loggerFactory,
            ImperaContext dbContext,
            DbSeed dbSeed)
        {
            if (env.IsDevelopment())
            {
                app.UsePathBase("/api");
            }

            NLog.LogManager.Configuration.Variables["configDir"] = Configuration["LogDir"];

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

            // Enable Cors
            app.UseCors(b => b
                        .WithOrigins("http://localhost:8080", "https://dev.imperaonline.de", "https://imperaonline.de", "https://www.imperaonline.de")
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .WithExposedHeaders("X-MiniProfiler-Ids")
                        .AllowCredentials());

            // Auth
            app.UseAuthentication();

            // TODO: Fix, how does this work?
            //app.UseOpenIddict();

            // Enable serving client and static assets
            app.UseResponseCompression();
            app.UseDefaultFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    // Do not cache main entry point.
                    if (!ctx.File.Name.Contains("index.html"))
                    {
                        ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=6000000");
                    }
                }
            });

            app.UseMiniProfiler();

            // Configure swagger generation & UI
            app.UseOpenApi();
            app.UseSwaggerUi3();

            app.UseMvc(routes =>
            {
                // Route for sub areas, i.e. Admin
                routes.MapRoute("areaRoute", "{area:exists}/{controller=News}/{action=Index}");

                routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseWebSockets();
            app.UseSignalR(routes =>
            {
                routes.MapHub <Hubs.MessagingHub>("/signalr/chat");
                routes.MapHub <Hubs.GameHub>("/signalr/game");
            });

            // Initialize database
            Log.Info("Initializing database...").Write();
            if (env.IsDevelopment())
            {
                if (Startup.RunningUnderTest)
                {
                    dbContext.Database.EnsureDeleted();
                }
                else
                {
                    dbContext.Database.Migrate();
                }
            }
            else
            {
                Log.Info("Starting migration...").Write();
                dbContext.Database.Migrate();
                Log.Info("...done.").Write();
            }
            Log.Info("...done.").Write();

            Log.Info("Seeding database...").Write();
            dbSeed.Seed(dbContext).Wait();
            Log.Info("...done.").Write();

            // Hangfire
            app.UseHangfireServer(new BackgroundJobServerOptions
            {
                Queues                  = new[] { JobQueues.Critical, JobQueues.Normal },
                WorkerCount             = 2,
                SchedulePollingInterval = TimeSpan.FromSeconds(30),
                ServerCheckInterval     = TimeSpan.FromSeconds(60),
                HeartbeatInterval       = TimeSpan.FromSeconds(60)
            });
            app.UseHangfireDashboard("/Admin/Hangfire", new DashboardOptions
            {
                Authorization = new[] { new HangfireAuthorizationFilter() }
            });

            Hangfire.Common.JobHelper.SetSerializerSettings(new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });

            // Configure Impera background jobs
            JobConfig.Configure();
        }
Exemple #26
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,
            ImperaContext dbContext,
            DbSeed dbSeed)
        {
            loggerFactory.AddNLog();
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.AddNLogWeb();
            NLog.LogManager.Configuration.Variables["configDir"] = Configuration["LogDir"];

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

            // Enable Cors
            app.UseCors(b => b
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .WithExposedHeaders("X-MiniProfiler-Ids")
                        .DisallowCredentials()
                        .Build());

            // Auth
            app.UseIdentity();

            /*app.UseFacebookAuthentication(new FacebookOptions
             * {
             *  AppId = Configuration["Authentication:Facebook:AppId"],
             *  AppSecret = Configuration["Authentication:Facebook:AppSecret"]
             * });
             *
             * app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions
             * {
             *  ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"],
             *  ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"]
             * });*/

            app.UseOAuthValidation(options =>
            {
                options.Events = new AspNet.Security.OAuth.Validation.OAuthValidationEvents
                {
                    // Note: for SignalR connections, the default Authorization header does not work,
                    // because the WebSockets JS API doesn't allow setting custom parameters.
                    // To work around this limitation, the access token is retrieved from the query string.
                    OnRetrieveToken = context =>
                    {
                        context.Token = context.Request.Query["bearer_token"];

                        if (string.IsNullOrEmpty(context.Token))
                        {
                            context.Token = context.Request.Cookies["bearer_token"];
                        }

                        return(Task.FromResult(0));
                    }
                };
            });
            app.UseOpenIddict();

            // Enable serving client and static assets
            app.UseResponseCompression();
            app.UseDefaultFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    // Do not cache main entry point.
                    if (!ctx.File.Name.Contains("index.html"))
                    {
                        ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=6000000");
                    }
                }
            });

            app.UseMiniProfiler(new StackExchange.Profiling.MiniProfilerOptions
            {
                RouteBasePath = "~/admin/profiler",

                SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(),

                // Control storage
                Storage = new MemoryCacheStorage(TimeSpan.FromMinutes(60))
            });

            app.UseMvc(routes =>
            {
                // Route for sub areas, i.e. Admin
                routes.MapRoute("areaRoute", "{area:exists}/{controller=News}/{action=Index}");

                routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseWebSockets();
            app.UseSignalR();

            app.UseSwagger();
            app.UseSwaggerUi();

            // Initialize database
            Log.Info("Initializing database...").Write();
            if (env.IsDevelopment())
            {
                if (Startup.RunningUnderTest)
                {
                    dbContext.Database.EnsureDeleted();
                }

                dbContext.Database.Migrate();
            }
            else
            {
                Log.Info("Starting migration...").Write();
                dbContext.Database.Migrate();
                Log.Info("...done.").Write();
            }
            Log.Info("...done.").Write();

            Log.Info("Seeding database...").Write();
            dbSeed.Seed(dbContext).Wait();
            Log.Info("...done.").Write();

            AutoMapperConfig.Configure();

            // Hangfire
            app.UseHangfireServer(new BackgroundJobServerOptions
            {
                Queues                  = new[] { JobQueues.Critical, JobQueues.Normal },
                WorkerCount             = 2,
                SchedulePollingInterval = TimeSpan.FromSeconds(30),
                ServerCheckInterval     = TimeSpan.FromSeconds(60),
                HeartbeatInterval       = TimeSpan.FromSeconds(60)
            });
            app.UseHangfireDashboard("/Admin/Hangfire", new DashboardOptions
            {
                Authorization = new[] { new HangfireAuthorizationFilter() }
            });

            Hangfire.Common.JobHelper.SetSerializerSettings(new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });

            // Configure Impera background jobs
            JobConfig.Configure();
        }