Example #1
0
        public static void ServicesCollection(this IServiceCollection services)
        {
            services.AddTransient <ISyroeshkaRu, SyroeshkaRuService>();

            services.AddTransient <IAdmin, AdminService>();

            services.AddDbContext <ModelContext>();

            services.AddTransient <UserManager <Users> >();

            services.AddTransient <FormHiddenTagHelpers>();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddTransient <IEdit, EditService>();

            services.AddAntiforgery(t => t.HeaderName = "X-XSRF-TOKEN");

            services.AddIdentity <Users, Roles>(option =>
            {
                option.Password.RequiredLength         = 5;
                option.Password.RequireNonAlphanumeric = false;
                option.Password.RequireLowercase       = false;
                option.Password.RequireDigit           = false;
                option.User.AllowedUserNameCharacters  = "";
            })
            .AddEntityFrameworkStores <ModelContext>();

            using (var serviceScope = services.BuildServiceProvider().GetRequiredService <IServiceScopeFactory>()
                                      .CreateScope())
            {
                DbInitialize.InitRoot(serviceScope.ServiceProvider.GetRequiredService <UserManager <Users> >(),
                                      serviceScope.ServiceProvider.GetRequiredService <RoleManager <Roles> >()).Wait();
            }
        }
        // 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, CoreContext DbContext, AdminServices adminServ)
        {
            app.UseCors("AllowAll");
            app.UseCors("localHost3000");
            app.UseCors("localHost19001");
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.Use(async(routecontext, next) =>
            {
                await next();
                if (routecontext.Response.StatusCode == 404 && !Path.HasExtension(routecontext.Request.Path.Value))
                {
                    routecontext.Request.Path = "/index.html";
                    await next();
                }
            });

            app.UseDefaultFiles(new DefaultFilesOptions {
                DefaultFileNames = new List <string> {
                    "index.html"
                }
            })
            .UseStaticFiles()
            .UseMvc();

            DbInitialize.Initialize(DbContext, adminServ);
        }
Example #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, ILoggerFactory loggerFactory, ApplicationDbContext 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 https://go.microsoft.com/fwlink/?LinkID=532715

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

            DbInitialize.Initialize(context);
        }
Example #4
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();
                app.UseDatabaseErrorPage();
            }
            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.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

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

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

            DbInitialize.Initialize(app);
        }
Example #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)
        {
            //app.Run(async context =>
            //{
            //    await context.Response.WriteAsync("Run extension method");
            //});


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

            app.UseStaticFiles();

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

            DbInitialize.Seed(app);
        }
Example #6
0
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseUrls("http://*:5000")
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <SensorContext>();
                    DbInitialize.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Example #7
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                var host = CreateWebHostBuilder(args).Build();
                using (var scope = host.Services.GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    DbInitialize.EnsureSeedData(scope.ServiceProvider);
                    DbInitialize.EnsureIdentityServerDatabase(scope.ServiceProvider);
                }
                host.Run();
            }
            catch (Exception ex)
            {
                //NLog: catch setup errors
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                NLog.LogManager.Shutdown();
            }
        }
Example #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, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

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

            app.UseStaticFiles();

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

            DbInitialize.EnsureCreated(app.ApplicationServices);
            SeedData.Initialize(app.ApplicationServices);
        }
Example #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            IsSessionAvailable = false;

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

            app.UseSession();

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            DbInitialize.Seed(app);
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Example #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            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.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

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

            DbInitialize.Seed(app);
        }
Example #11
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 <AppUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            DbInitialize.SeedData(userManager, roleManager);

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();

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

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            app.UseCookiePolicy();
        }
Example #12
0
        /// <summary>
        /// The main entry point of the application.
        /// </summary>
        /// <param name="args">Any command-line arguments passed to the application on launch.</param>
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    // Seed the database
                    Core.Data.DbInitialize.Initialize(
                        services,
                        services.GetRequiredService <ApplicationDbContext>());

                    // Add sample data
                    DbInitialize.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while migrating the database.");
                }
            }

            host.Run();
        }
Example #13
0
        //请求管道配置
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            //开发环境与生产环境异常处理
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Shared/Error");
            }

            //使用静态文件
            app.UseStaticFiles();
            //启用Session
            app.UseSession();
            //使用MVC,设置默认路由
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
            using (var scope = ApplicationContainer.BeginLifetimeScope())
            {
                var iService = scope.Resolve <ISqlLocalContext>();
                DbInitialize.Seed(iService);
            }
        }
Example #14
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)
        {
            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?}");
            });
            DbInitialize.Initilaize(context);
        }
 public Task Invoke(HttpContext httpContext, kindergartenContext db)
 {
     if (!(httpContext.Session.Keys.Contains("starting")))
     {
         DbInitialize.Initialize(db);
         httpContext.Session.SetString("starting", "Yes");
     }
     return(_next.Invoke(httpContext));
 }
Example #16
0
        public TeamsController(MyProjectContext context)
        {
            _context = context;

            if (!_context.Team.Any() || !_context.Player.Any())
            {
                DbInitialize.Initialize(_context);
            }
        }
Example #17
0
 private void Seed()
 {
     using (var LaeContext = new LmsContext(_connectionString))
     {
         Console.WriteLine("Seeding test data into database");
         DbInitialize.Seed(_connectionString);
         Console.WriteLine("Seeding test data is complete");
     }
 }
        public ConsumerDealServiceTests()
        {
            var options = new DbContextOptionsBuilder <DealLocator.API.Models.DealLocatorDbContext>()
                          .UseInMemoryDatabase(databaseName: "LocationDatabase")
                          .Options;
            var context = new DealLocatorDbContext(options);

            sut = new ConsumerDealService(context);
            DbInitialize.Initialize(context);
        }
Example #19
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            DbInitialize db = new DbInitialize();

            Database.SetInitializer(db);
        }
Example #20
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     app.UseSession();
     app.UseMvcWithDefaultRoute();
     app.UseStaticFiles();
     app.UseFileServer(enableDirectoryBrowsing: true);
     DbInitialize.InitializeDb(app);
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
 }
Example #21
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var context     = scope.ServiceProvider.GetRequiredService <DataContext>();
                var usermanger  = scope.ServiceProvider.GetRequiredService <UserManager <IdentityUser> >();
                var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                var env         = scope.ServiceProvider.GetRequiredService <IConfiguration>();
                DbInitialize.Intialize(context, usermanger, roleManager, env);
            }
            host.Run();
        }
        private static void CreateDbIfNoExist(IHost host)
        {
            using var create = host.Services.CreateScope();
            var serviceProv = create.ServiceProvider;
            var context     = serviceProv.GetRequiredService <AuthContext>();

            context.Database.EnsureCreated();
            if (!context.Users.Any())
            {
                DbInitialize.Initialize(context);
            }
            else
            {
            }
        }
Example #23
0
 private static void CreateDbIfNotExists(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var context = services.GetRequiredService <DataContext>();
             DbInitialize.Initialize(context);
         }
         catch (Exception ex)
         {
             var logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(ex, "An error occurred creating the DB.");
         }
     }
 }
Example #24
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

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

            DbInitialize.Initialize(serviceProvider);
        }
Example #25
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 <UserModelContext>();
                    DbInitialize.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured while seeding the database");
                }
            }
            host.Run();
        }
Example #26
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <Context>();
                    DbInitialize.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, GeneralMessages.MSG0006);
                }
            }
            host.Run();
        }
Example #27
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var serviceScope = host.Services.CreateScope())
            {
                var services = serviceScope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <PostContext>();
                    DbInitialize.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, ex.Message);
                    throw;
                }
            }
            host.Run();
        }
Example #28
0
        public static void Main(string[] args)
        {
            _host = CreateHostBuilder(args).Build();

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

                try
                {
                    DbInitialize.Initialize(services.GetService <AppDbContext>());
                }
                catch (Exception e)
                {
                    var log = services.GetService <ILogger <Program> >();

                    log.LogError(e, "Can't initialize DB.");
                }
            }

            _host.Run();
        }
Example #29
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions <JenkinsSettings> jenkinSetting)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

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

            DbInitialize.Seed(app, jenkinSetting);
        }
Example #30
0
        public static void Main(string[] args)
        {
            var builder = BuildWebHost(args);

            using (var scope = builder.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <FeatureContext>();
                    if (!context.Institutions.Any())
                    {
                        DbInitialize.Initialize(context);
                    }
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            builder.Run();
        }