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, IWebHostEnvironment env, UserManager <AppUser> userManager, RoleManager <AppRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseStatusCodePagesWithReExecute("/Home/StatusCode", "?code={0}");

            app.UseRouting();

            app.UseAuthentication();

            app.UseAuthorization();

            IdentityInitializer.SeedData(userManager, roleManager).Wait();

            app.UseStaticFiles();

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

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}"
                    );
            });
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager, RoleManager <Role> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            IdentityInitializer.SeedData(userManager, roleManager).Wait();
            app.UseStaticFiles();
            app.UseNToastNotify();

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

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Login}/{id?}");
            });
        }
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;

                var userManager = services.GetRequiredService <UserManager <Consumer> >();
                var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();

                IdentityInitializer.SeedData(userManager, roleManager, services.GetRequiredService <IConfiguration>());
            }

            host.Run();
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                config = new ConfigurationBuilder()
                         .AddInMemoryCollection(defaults)
                         .AddEnvironmentVariables("ASPNETCORE_")
                         .AddCommandLine(args)
                         .Build();
                var host = BuildWebHost();

                using (var scope = host.Services.CreateScope())
                {
                    var services = scope.ServiceProvider;
                    try
                    {
                        logger.Info(config.ToString());
                        var dbContext = services.GetService <ApplicationDbContext>();
                        dbContext.Database.Migrate();
                        // Seed Roles and Admin User
                        var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                        var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                        IdentityInitializer.SeedData(userManager, roleManager, dbContext);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "An error occurred validating DB creation.");
                    }
                }

                host.Run();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                LogManager.Shutdown();
            }
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <AppUser> userManager, RoleManager <AppRole> roleManager, IBlogService blogService, ICategoryService categoryService, ICategoryBlogService categoryBlogService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/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.UseStatusCodePagesWithReExecute("/Home/StatusCode", "?code={0}");

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseStaticFiles();

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

            app.UseRequestLocalization(locOptions.Value);

            app.UseAuthentication();

            app.UseAuthorization();

            IdentityInitializer.SeedData(userManager, roleManager).Wait();
            BlogInitializer.SeedData(blogService, categoryService, categoryBlogService).Wait();

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

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              ApplicationDbContext context,
                              UserManager <ApplicationUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            IdentityInitializer.SeedData(userManager, roleManager);

            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 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, UserManager <User> userManager, RoleManager <Role> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            // Initialize minimum configs for database (roles, SuperAdmin user, etc ... ) case not exists
            IdentityInitializer.SeedData(userManager, roleManager, AdminEmail, AdminPassword);

            app.ConfigureCustomExceptionMiddleware();

            //app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseCors(c => c.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            app.UseMvc();
        }
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,
            IHostingEnvironment env,
            RoleManager <IdentityRole> roleManager,
            UserManager <User> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <DbCtx>();
                context.Database.EnsureCreated();
            }
            app.UseAuthentication();

            IdentityInitializer.SeedData(userManager, roleManager);

            app.UseMvc()
            .UseSwagger()
            .UseSwaggerUI(opt => opt.SwaggerEndpoint("/swagger/v1/swagger.json", "Info Flow API V1.0"));
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <ApplicationRole> >();
                    var context     = services.GetRequiredService <ApplicationDbContext>();
                    IdentityInitializer.SeedData(userManager, roleManager, context);
                    DbInitializer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()) {
                CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
                var services    = scope.ServiceProvider;
                var userManager = services.GetService <UserManager <IdentityUserDefaultPwd> >();
                var roleManager = services.GetService <RoleManager <IdentityRole> >();
                var context     = services.GetRequiredService <ApplicationDbContext>();
                context.Database.Migrate();

                // requires using Microsoft.Extensions.Configuration;
                var config = host.Services.GetRequiredService <IConfiguration>();
                // Set password with the Secret Manager tool.
                // dotnet user-secrets set SeedUserPW <pw>


                #region Seed DB

                var logger     = services.GetRequiredService <ILogger <Program> >();
                var testUserPw = config["SeedUserPW"];
                try {
                    UserDataInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the UserData DB.");
                }

                try {
                    IdentityInitializer.SeedData(userManager, roleManager).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the Identity DB.");
                }

                try {
                    PromsKeyboardShortcutInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the PromsKeyboardShortcut DB.");
                }

                try {
                    SystemParametersInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the SystemParameters DB.");
                }

                try {
                    ProductsInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the ProductsInitializer DB.");
                }

                try {
                    TransactionHistoryInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the TransactionHistory DB.");
                }

                #endregion
            }

            host.Run();
            CreateWebHostBuilder(args)
            .Build().Run();
        }