예제 #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, ApplicationDbContext context,
                              RoleManager <ApplicationRole> rManager, UserManager <ApplicationUser> uManager)
        {
            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: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            DatabaseSeeder.Seed(context, uManager, rManager).Wait();
        }
예제 #2
0
파일: Program.cs 프로젝트: plyschik/AMS
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

                try
                {
                    var databaseContext = services.GetRequiredService <DatabaseContext>();
                    var roleManager     = services.GetRequiredService <RoleManager <IdentityRole> >();
                    var userManager     = services.GetRequiredService <UserManager <ApplicationUser> >();

                    await DatabaseSeeder.Seed(databaseContext, roleManager, userManager);
                }
                catch (Exception exception)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();

                    logger.LogError(exception, "An error occurred while seeding the database.");
                }
            }

            await host.RunAsync();
        }
예제 #3
0
        protected override void Seed(DatabaseContext context)
        {
            //  This method will be called after migrating to the latest version.
            DatabaseSeeder seeder = new DatabaseSeeder();

            seeder.Seed(context);
        }
예제 #4
0
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     base.OnModelCreating(modelBuilder);
     modelBuilder.Entity <Beverage>().ToTable("Beverage").HasIndex(e => e.Name).IsUnique()
     ;
     modelBuilder.Entity <BeverageCategory>().ToTable("BeverageCategory");
     modelBuilder.Entity <Sale>().ToTable("Sale");
     modelBuilder.Entity <Customer>().ToTable("Customer");
     modelBuilder.Entity <Supplier>().ToTable("Supplier");
     modelBuilder.Entity <Purchase>().ToTable("Purchase");
     modelBuilder.Entity <DuePay>().ToTable("DuePay");
     modelBuilder.Entity <SalesReturn>().ToTable("SalesReturn");
     modelBuilder.Entity <Vat>().ToTable("Vat");
     modelBuilder.Entity <Invoice>().ToTable("Invoice");
     modelBuilder.Entity <BeverageCategory>().ToTable("BeverageCategory");
     modelBuilder.Entity <LedgerTransaction>().ToTable("LedgerTransaction");
     modelBuilder.Entity <LedgerAccount>().ToTable("LedgerAccount");
     modelBuilder.Entity <LedgerTransactionDetail>().ToTable("LedgerTransactionDetail");
     modelBuilder.Entity <LedgerAccountBalance>().ToTable("LedgerAccountBalance");
     modelBuilder.Entity <Company>().ToTable("Company");
     modelBuilder.Entity <FiscalYear>().ToTable("FiscalYear");
     modelBuilder.Entity <UserRole>().ToTable("UserRole");
     modelBuilder.Entity <SaleOrder>().ToTable("SaleOrder");
     modelBuilder.Entity <Administration>().ToTable("Administration");
     DatabaseSeeder.Seed(modelBuilder);
 }
    static void Main(string[] args)
    {
        var collection = new Database().GetCollection();

        var databaseSeeder = new DatabaseSeeder(collection);

        databaseSeeder.Seed();
    }
예제 #6
0
        static BaseDAL()
        {
            var factory = new DatabaseConnectionFactory();

            DbConnection = factory.Create();
            var seeder = new DatabaseSeeder(DbConnection);

            seeder.Seed();
        }
예제 #7
0
        public ProductsControllerTest()
        {
            _databaseContext    = new DatabaseContext(Globals.DbContextInMemoryConfig);
            _productsController = new ProductsController(_databaseContext);

            if (!_databaseContext.Products.Any())
            {
                DatabaseSeeder.Seed(_databaseContext);
            }
        }
예제 #8
0
        protected override void InitializeDatabaseSchema()
        {
            Context.Database.OpenConnection();
            Context.Database.EnsureCreated();
            var seeder = new DatabaseSeeder(Context);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            seeder.Seed();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
예제 #9
0
 private static void UpdateDatabase(IApplicationBuilder app)
 {
     using (var serviceScope = app.ApplicationServices
                               .GetRequiredService <IServiceScopeFactory>()
                               .CreateScope())
     {
         using (var context = serviceScope.ServiceProvider.GetService <DatabaseContext>())
         {
             DatabaseSeeder.Setup(context);
             DatabaseSeeder.Seed(context);
         }
     }
 }
예제 #10
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            // First-run DB initialization
            using (var scope = host.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetService <SimpleStoreContext>();
                DatabaseSeeder.Seed(context);
            }

            host.Run();
        }
예제 #11
0
        public static void InitDatabaseSeeder(IWebHost host)
        {
            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;

                try {
                    DatabaseSeeder.Seed(services).Wait();
                } catch (Exception ex) {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the database.");
                }
            }
        }
        public static async Task Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            if (Initializer != null)
            {
                using (var scope = host.Services.CreateScope())
                {
                    await Initializer.Seed(scope.ServiceProvider);
                }
            }

            host.Run();
        }
예제 #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, PetClinicDbContext dbContext, ILogger <Startup> logger)
        {
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Pet Clinic V1");
            });

            if (env.IsDevelopment())
            {
                var seeder = new DatabaseSeeder(dbContext, logger);
                seeder.Seed();
            }

            app.UseMvc();
        }
예제 #14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RandomUserContext 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();
            }

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

            app.UseRouting();

            DatabaseSeeder.Seed(
                context,
                env.WebRootPath,
                Configuration.GetValue <string>("SeedPath:Users"));

            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");
                }
            });
        }
예제 #15
0
 public bool DeleteAndRefreshDatabase()
 {
     try
     {
         Context.Database.Connection.Close();
         Context.Database.Delete();
         Context.Database.Initialize(false);
         DatabaseSeeder.Seed(Context);
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
         // throw ex;
         // false;
     }
 }
예제 #16
0
파일: Startup.cs 프로젝트: Kriez/dashboard
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DatabaseContext _context)
        {
            _context.Database.Migrate();

            var databaseSeeder = new DatabaseSeeder(_context);

            databaseSeeder.Seed();

            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();
            app.UseSpaStaticFiles();

            app.UseRouting();

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

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }
        /// <summary>
        /// This method gets called by the runtime.
        /// Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app">Application builder injected in by the Dependency Injection container</param>
        /// <param name="context">Database connection injected in by the Dependency Injection container</param>
        public void Configure(IApplicationBuilder app, DatabaseContext context)
        {
            // Database
            if (Configuration.GetSection("DatabaseSeeding").GetValue <Boolean>("SeedDatabase"))
            {
                if (Configuration.GetSection("DatabaseSeeding").GetValue <Boolean>("DeleteDatabaseBeforeSeed"))
                {
                    Console.WriteLine("Deleting database...");
                    context.Database.EnsureDeleted();
                }
                Console.WriteLine("Seeding database...");
                DatabaseSeeder.Seed(context);
                Console.WriteLine($"Database seeded!");
            }
            else
            {
                context.Database.EnsureCreated();
            }
            ;
            // HTTP Pipeline
            if (Environment.IsDevelopment())
            {
                // Error pages
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                // Debug middleware
                app.UseMiddleware <DebugMiddleware>();
                // Enable Swagger
                app.UseSwagger();
                app.UseSwaggerUI(
                    (options) =>
                {
                    options.SwaggerEndpoint("/swagger/v1/swagger.json", "API");
                }
                    );
                // Allow all origins, methods and headers in development
                app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            }

            // MVC
            app.UseMvc();
        }
예제 #18
0
        public static async Task Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <ApplicationContext>();
                try
                {
                    await DatabaseSeeder.Seed(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
예제 #19
0
        /// <summary>
        ///     This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="authenticationOptions"></param>
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IOptions <AadAuthenticationConfiguration> authenticationOptions, IConfiguration configuration)
        {
            bool isDevEnv = env.IsDevelopment() || env.EnvironmentName.StartsWith("Development");

            if (isDevEnv)
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();
            app.UseSwagger();
            app.UseSwaggerUI(o =>
            {
                o.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
                o.OAuthClientId(authenticationOptions.Value.ClientId);
                o.DisplayRequestDuration();
                o.InjectStylesheet($"/css/{configuration.GetSection("SwaggerConfiguration")["CssFile"]}");
            });

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();
            app.UseStaticFiles();

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

            var syncDataOnStartup = configuration.GetValue <bool>("syncDataOnStartup");

            DatabaseSeeder.Seed(app, migrate: true, seedDevData: false, syncDataOnStartup);


            //app.UseCors(policy => policy
            //    .AllowAnyOrigin()
            //    .AllowAnyMethod()
            //    .AllowAnyHeader()
            //    .AllowCredentials());
        }
예제 #20
0
        // TODO: HTTP ONLY cookie flag

        //	services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        //	.AddJwtBearer(options => {
        //	options.Events = new JwtBearerEvents
        //	{
        //		OnMessageReceived = context =>
        //		{
        //			context.Token = context.Request.Cookies["CookieName"];
        //			return Task.CompletedTask;
        //		}
        //	};
        //});


        public void Configure(IApplicationBuilder app, IHostingEnvironment env, VideoGamerDbContext context)
        {
            var DbSeeder = new DatabaseSeeder(context);

            DbSeeder.Seed();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseCors(policy =>
                {
                    policy.AllowAnyHeader();
                    policy.AllowAnyMethod();
                    policy.AllowAnyOrigin();
                });
            }
            else
            {
                app.UseHsts();
            }

            app.UseAuthentication();

            app.UseHttpsRedirection();
            app.UseMvc();

            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "VideoGamerAPI V1");
                c.RoutePrefix = string.Empty;
            });
        }
예제 #21
0
 protected override void Seed(TescoWineShopSql.WineContext context)
 {
     DatabaseSeeder.Seed(context);
 }
예제 #22
0
 protected override void Configure()
 {
     Log.Debug("Seeding database");
     DatabaseSeeder.Seed(database);
 }
예제 #23
0
 void IAdministrationService.ResetAdministration()
 {
     DatabaseSeeder.Seed(GetCurrentContext());
 }