public static async Task Main(string[] args) { //AUTO //CreateWebHostBuilder(args).Build().Run(); var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
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 rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var context = services.GetRequiredService <ApplicationDbContext>(); RoleInitializer.InitializeAsync(userManager, rolesManager, context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } JobManager.JobFactory = new JobFactory(host.Services); JobManager.Initialize(new FluentSchedulerRegistry()); JobManager.JobException += info => { var logger = host.Services.GetRequiredService <ILogger <Program> >(); logger.LogError(info.Exception, "Unhandled exception in email job"); }; host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); var userManager = services.GetRequiredService <UserManager <AppUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var configuration = services.GetRequiredService <IConfiguration>(); try { var context = services.GetRequiredService <RepositoryContext>(); await context.Database.MigrateAsync(); await ContextSeeder.SeedAsync(context, loggerFactory, userManager); await RoleInitializer.InitializeAsync(userManager, rolesManager, configuration); var logger = loggerFactory.CreateLogger <Program>(); logger.LogInformation("Ok"); } catch (Exception ex) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError($"An error occurred during migration: {ex.Message}, {ex.StackTrace}"); } } await host.RunAsync(); }
public static async Task Main(string[] args) { //BuildWebHost(args).Run(); var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <AspNetUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } //GlobalConfiguration.Configuration.UseSqlServerStorage(@"Server=.\SQLEXPRESS; Database=Hangfire.Sample; Integrated Security=True"); host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <User> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, roleManager); var context = services.GetRequiredService <ComicsDbContext>(); context.Database.Migrate(); //https://docs.microsoft.com/ru-ru/aspnet/core/tutorials/first-mvc-app/working-with-sql?view=aspnetcore-3.1&tabs=visual-studio SeedData.Initialize(services); } catch (Exception e) { } } host.Run(); }
public static async Task Main(string[] args) { Localization.SetRU(); var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); await SeedData.SeedUsers(userManager); await SeedData.SeedAll(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public static async Task Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; //try //{ var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); var context = services.GetRequiredService <ApplicationDbContext>(); var init = services.GetRequiredService <IDBInitializer>(); init.Initialize(); /* * } * catch (Exception ex) * { * var logger = services.GetRequiredService<ILogger<Program>>(); * logger.LogError(ex, "An error occurred while seeding the database."); * throw new Exception(ex.Message); * }*/ } host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <AppUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var configuration = services.GetRequiredService <IConfiguration>(); await RoleInitializer.InitializeAsync(userManager, rolesManager, configuration["AdminSettings:Login"], configuration["AdminSettings:Password"], configuration["AdminSettings:Phone"]); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.File("Logs/log.txt") // .WriteTo.Seq("http://localhost:6001") .CreateLogger(); var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { Log.Information("Starting Fiscal"); var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { Log.Error(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <Profile> >(); var config = services.GetRequiredService <IConfiguration>(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.File(config["all-logs"]) .WriteTo.Logger(lc => lc .Filter.ByIncludingOnly(le => le.Level == LogEventLevel.Error) .WriteTo.File(config["error-logs"])) .WriteTo.Logger(lc => lc .Filter.ByIncludingOnly(le => le.Level == LogEventLevel.Error) .WriteTo.Console()) .CreateLogger(); await RoleInitializer.InitializeAsync(userManager, rolesManager, config); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static async Task Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); SampleData.Initialize(context); var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public static async Task Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { await InitializeDb(services); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var rolesManager = services.GetRequiredService <RoleManager <ApplicationRole> >(); var configuration = services.GetRequiredService <IConfiguration>(); await RoleInitializer.InitializeAsync(configuration, userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
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 <WebContext>(); DataBaseInitializer.Initialize(context); var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); Task t = RoleInitializer.InitializeAsync(userManager, rolesManager, context); t.Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static async Task Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var host = CreateHostBuilder(args).Build(); // Начальная инициализация Базы Данных // Пользователи и Роли using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } // Запуск программы host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var path = Directory.GetCurrentDirectory(); var loggerFactory = host.Services.GetRequiredService <ILoggerFactory>(); loggerFactory.AddFile($"{path}/Logs/mylog-All.txt", minimumLevel: LogLevel.Trace); loggerFactory.AddFile($"{path}/Logs/mylog-Error.txt", minimumLevel: LogLevel.Error); var services = scope.ServiceProvider; try { //check if exists is inside methods var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); RoleInitializer roleInitializer = new RoleInitializer(); await roleInitializer.InitializeAsync(userManager, rolesManager); //DataInitializer dataInitializer = new DataInitializer(); //await dataInitializer.InitData(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { //CreateWebHostBuilder(args).Build().Run(); Task t; var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <AppDbContext>(); DbInitializer.Seed(context); var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); t = RoleInitializer.InitializeAsync(userManager, rolesManager); t.Wait(); } catch (Exception e) { } } host.Run(); }
public async Task InvokeAsync(HttpContext context, IServiceProvider serviceProvider, UserManager <User> userManager, RoleManager <IdentityRole> roleManager) { if (!(context.Session.Keys.Contains("roleStarting"))) { await RoleInitializer.InitializeAsync(userManager, roleManager); context.Session.SetString("roleStarting", "Yes"); } await _next(context); }
public static async Task Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(rolesManager); } host.Run(); }
public async Task <IActionResult> Seed() { JsonModelReturnViewUser json = new JsonModelReturnViewUser(); try { await RoleInitializer.InitializeAsync(_userManager, _rolesManager); } catch (Exception ex) { json.messages = ex.Message; return(Json(json)); } return(View()); }
/// <summary> /// App entry point. /// </summary> public static async Task Main(string[] args) { IWebHost host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { IServiceProvider serviceProvider = scope.ServiceProvider; UserManager <User> userManager = serviceProvider.GetRequiredService <UserManager <User> >(); RoleManager <IdentityRole> roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, roleManager); } host.Run(); }
public static async Task SeedData(IHost host) { using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; try { var rolesManager = services.GetRequiredService <RoleManager <Role> >(); await RoleInitializer.InitializeAsync(rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } }
public static void Main(string[] args) { //BuildWebHost(args).Run(); var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManger = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var dbContext = services.GetRequiredService <ApplicationDbContext>(); //var uowService = services.GetRequiredService<IUnitOfWork>(); RoleInitializer.InitializeAsync(userManger, rolesManager); //var context = services.GetRequiredService<ApplicationDbContext>(); //new InitialFlights().CreateFlightsEveryWednsday(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } try { var uowService = services.GetRequiredService <ApplicationUnitOfWork>(); //FlightsInitalizer.InitializeAsync(uowService); var context = services.GetRequiredService <ApplicationDbContext>(); //new InitialFlights().CreateFlightsEveryWednsday(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } host.Run(); } }
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 <LOLHUBIdentityDbContext>(); RoleInitializer.InitializeAsync(context, services).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while seeding the database."); } } host.Run(); }
public BaseController(UserManager <User> userManager, SignInManager <User> signInManager, PhdContext context, RoleManager <IdentityRole> roleManager = null) { _context = context; _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; // RoleInitializer.InitializeAsync(_userManager, _roleManager, _context).Wait(); try { RoleInitializer.InitializeAsync(_userManager, _roleManager, _context).Wait(); } catch (Exception e) { // Console.WriteLine("Возникло исключение!"); // throw e; // если разкомментировать выдаст ошибку-исключение. Нужно разобраться } }
public static async Task Main(string[] args) { //Default: CreateWebHostBuilder(args).Build().Run(); var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services?.GetRequiredService <UserManager <User> >(); var rolesManager = services?.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger?.LogError(ex, "Ошибка при начальном заполнении БД"); } // try-catch } // using await host.RunAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IWebHostEnvironment 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.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); var scopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>(); var scope = scopeFactory.CreateScope(); // Добавление админа и библиотекаря, если их нет. var userManager = scope.ServiceProvider.GetRequiredService <UserManager <User> >(); var rolesManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); // Фоновая задача. DataScheduler.Start(scope.ServiceProvider); }
public static async Task Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var photoOptions = services.GetRequiredService <IOptions <PhotoConfig> >(); var usersOptions = services.GetRequiredService <IOptions <UsersConfig> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager, photoOptions, usersOptions); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } try { var repository = services.GetRequiredService <IBalanceManager>(); var balanceChecker = new FreelancingPlatformBalanceChecker(repository); await balanceChecker.CheckAsync(); } catch (DbNotInitializedBalanceException e) { Console.WriteLine(e); var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, e.Message); ExceptionDispatchInfo.Capture(e).Throw(); } } await host.RunAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); RoleInitializer.InitializeAsync(serviceProvider).GetAwaiter().GetResult(); }
public async Task <IActionResult> Index() { await RoleInitializer.InitializeAsync(); return(View()); }
public async Task InvokeAsync(HttpContext context, IServiceProvider serviceProvider, UserManager <User> userManager, RoleManager <IdentityRole> roleManager) { await RoleInitializer.InitializeAsync(userManager, roleManager); await _next(context); }