Ejemplo n.º 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, ILoggerFactory loggerFactory, TrailerCheckContext context)
        {
            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();

            // 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?}");
            });

            DbInitialiser.Initialise(context);
        }
Ejemplo n.º 2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, DatabaseContext context)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

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

            app.UseStaticFiles();

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

            DbInitialiser.Initialise(context);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var env     = services.GetRequiredService <IWebHostEnvironment>();
                    var context = services.GetRequiredService <LrpDbContext>();
                    if (env.IsDevelopment())
                    {
                        context.Database.EnsureDeleted();
                    }

                    context.Database.EnsureCreated();
                    DbInitialiser.Initialise(context);

                    var authContext = services.GetRequiredService <AccountsContext>();
                    authContext.Database.EnsureCreated();
                    authContext.Database.Migrate();
                }
                catch (Exception e)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "A Seeding Error Occured");
                }
            }
            host.Run();
        }
Ejemplo n.º 4
0
 private static void CreateDbIfNotExists(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         var context  = services.GetRequiredService <UserContext>();
         //context.Database.EnsureCreated();
         DbInitialiser.Initialise(context);
     }
 }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env,
                                    ILoggerFactory loggerFactory, ApplicationDbContext context,
                                    UserManager <ApplicationUser> userManager, IServiceProvider serviceProvider)
        {
            app.UseSession();

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

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

            app.UseApplicationInsightsExceptionTelemetry();

            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?}");
            });

            DbInitialiser.Initialise(context);
            await CreateRoles(serviceProvider);

            /*Assign other users to 'Customer' category*/
            ICollection <ApplicationUser> appUsers = context.ApplicationUsers.ToList();

            if (appUsers.Count > 0)
            {
                foreach (var user in appUsers)
                {
                    var roleCount = userManager.GetRolesAsync(user).Result.Count();
                    if (roleCount < 1)//If user doesn't have a role
                    {
                        await userManager.AddToRoleAsync(user, "Customer");
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private async Task RunAsync()
        {
            var services = ConfigureServices();

            var provider = services.BuildServiceProvider();

            var dbContext = provider.GetRequiredService <CraigBotDbContext>();
            await DbInitialiser.Initialise(dbContext);

            provider.GetRequiredService <ILoggingService>();
            provider.GetRequiredService <ICommandHandler>();

            await provider.GetRequiredService <IStartupService>().StartClient();

            await Task.Delay(-1);
        }
 private static void CreateDbIfNotExists(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var context = services.GetRequiredService <ApplicationDbContext>();
             DbInitialiser.Initialise(context);
         }
         catch (Exception ex)
         {
             var logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(ex, "An error occurred creating the DB.");
         }
     }
 }
Ejemplo n.º 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ZipCoContext context)
        {
            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();
            }

            RewriteOptions option = new RewriteOptions();

            option.AddRedirect("^$", "swagger");
            app.UseRewriter(option);

            app.UseHttpsRedirection();

            app.UseStaticFiles();

            app.UseCookiePolicy();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();
            });

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(q =>
            {
                q.SwaggerEndpoint("/swagger/v1/swagger.json", "ZipCo API v1");
            });

            DbInitialiser.Initialise(context);
        }
Ejemplo n.º 9
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 <PaymentContext>();
                    DbInitialiser.Initialise(context);
                }
                catch (Exception e)
                { }
            }

            host.Run();
        }
Ejemplo n.º 10
0
        private static void MigrateAndSeedDatabase(IHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var context = services.GetRequiredService <BlimpBotContext>();
                    DbInitialiser.Initialise(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred creating the DB.");
                }
            }
        }
        public void Initialise_When_Users_Is_Not_Empty_Does_Not_Populate_Users()
        {
            // Arrange
            _quizManagerContext.Users.Add(new User()
            {
                Username = "******", Password = "******", Role = "TestRole"
            });
            _quizManagerContext.SaveChanges();
            _quizManagerContext.Quizzes.Add(new Quiz()
            {
                Title = "The Software Development Lifecycle"
            });
            _quizManagerContext.SaveChanges();
            _quizManagerContext.Questions.Add(new Question()
            {
                QuizId = _quizManagerContext.Quizzes.Single(x => x.Title == "The Software Development Lifecycle").Id, Text = "At which point in the software development lifecycle is a system design document produced?"
            });
            _quizManagerContext.SaveChanges();
            _quizManagerContext.Answers.Add(new Answer()
            {
                QuestionId = _quizManagerContext.Questions.Single(x => x.Text == "At which point in the software development lifecycle is a system design document produced?").Id, Text = "Deployment/implementation."
            });
            _quizManagerContext.SaveChanges();

            var expectedNumberOfUsers     = 1;
            var expectedNumberOfQuizzes   = 1;
            var expectedNumberOfQuestions = 1;
            var expectedNumberOfAnswers   = 1;

            // Act
            DbInitialiser.Initialise(_quizManagerContext);

            var actualNumberOfUsers     = _quizManagerContext.Users.Count();
            var actualNumberOfQuizzes   = _quizManagerContext.Quizzes.Count();
            var actualNumberOfQuestions = _quizManagerContext.Questions.Count();
            var actualNumberOfAnswers   = _quizManagerContext.Answers.Count();

            // Assert
            Assert.AreEqual(expectedNumberOfUsers, actualNumberOfUsers);
            Assert.AreEqual(expectedNumberOfQuizzes, actualNumberOfQuizzes);
            Assert.AreEqual(expectedNumberOfQuestions, actualNumberOfQuestions);
            Assert.AreEqual(expectedNumberOfAnswers, actualNumberOfAnswers);
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            var webHost = BuildWebHost(args);

            using (var scope = webHost.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <QuestionGeneratorContext>();
                    DbInitialiser.Initialise(context);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }

            webHost.Run();
        }
Ejemplo n.º 13
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 <ApplicationDbContext>();
                    DbInitialiser.Initialise(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Ejemplo n.º 14
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 <SchoolDbContext>();
                    DbInitialiser.Initialise(context);
                }
                catch (Exception e)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e.Message, "初始化系统测试数据时出错,请联系管理员!");
                }
            }

            host.Run();
        }
        public void Initialise_When_Database_Is_Empty_Populates_Database()
        {
            // Arrange
            var expectedNumberOfUsers     = 3;
            var expectedNumberOfQuizzes   = 3;
            var expectedNumberOfQuestions = 12;
            var expectedNumberOfAnswers   = 48;

            // Act
            DbInitialiser.Initialise(_quizManagerContext);
            var actualNumberOfUsers     = _quizManagerContext.Users.Count();
            var actualNumberOfQuizzes   = _quizManagerContext.Quizzes.Count();
            var actualNumberOfQuestions = _quizManagerContext.Questions.Count();
            var actualNumberOfAnswers   = _quizManagerContext.Answers.Count();

            // Assert
            Assert.AreEqual(expectedNumberOfUsers, actualNumberOfUsers);
            Assert.AreEqual(expectedNumberOfQuizzes, actualNumberOfQuizzes);
            Assert.AreEqual(expectedNumberOfQuestions, actualNumberOfQuestions);
            Assert.AreEqual(expectedNumberOfAnswers, actualNumberOfAnswers);
        }
Ejemplo n.º 16
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

                try
                {
                    DbInitialiser.Initialise(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
Ejemplo n.º 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, WebshopDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, AddressService addressService, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddAzureWebAppDiagnostics();
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

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

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseSession();

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

            if (_hostingEnvironment.IsProduction() ||
                _hostingEnvironment.IsStaging() ||
                _hostingEnvironment.EnvironmentName == "IntegratedDb" ||
                _hostingEnvironment.EnvironmentName == "LocalSql")
            {
                context.Database.Migrate();
            }

            DbInitialiser.Initialise(context, userManager, roleManager, addressService);
        }
Ejemplo n.º 18
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                Logger = services.GetRequiredService <ILogger <Program> >();

                try
                {
                    var context = services.GetRequiredService <NbaDbContext>();
                    context.Database.Migrate();
                    var initialiser = new DbInitialiser(context);
                    initialiser.Initialise();
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, "An error occured creating the database.");
                }
            }

            host.Run();
        }