Exemplo n.º 1
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 <DataContext>();
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()){
                var services = scope.ServiceProvider;
                try{
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager =
                        services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex) {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    System.Console.WriteLine(ex.Message);
                    logger.LogError(ex, "Error occurs during migration");
                }
            }

            host.Run();
        }
Exemplo n.º 3
0
        public static IWebHost BuildWebHost(string[] args)
        {
            var host = WebHost.CreateDefaultBuilder(args).UseStartup <Startup>().Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            return(host);
        }
Exemplo n.º 4
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>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception e)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "An error has occured during Database Scaffolding!");
                }
            }
            host.Run();
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var Services = scope.ServiceProvider;
                try
                {
                    var context = Services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = Services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An Error Happened during Migration Please Contact With SOHEIL");
                }
            }

            host.Run();
        }
Exemplo n.º 6
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

            try
            {
                var context = services.GetRequiredService <DataContext>();
                await context.Database.MigrateAsync();

                await Seed.SeedData(context);
            }
            catch (System.Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occured during migration");
            }

            await host.RunAsync();
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "Ocurrió un problema durante la migración");
                }
            }
            host.Run();
        }
Exemplo n.º 8
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            // Setup the scope and obtain the DI container for injection
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context = services.GetRequiredService <DataContext>();
                await context.Database.MigrateAsync();

                await Seed.SeedData(context);
            }
            catch (Exception ef)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ef, "And error occured during migration");
            }

            await host.RunAsync();
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            using (var scope = CreateHostBuilder(args).Build().Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    //if database exists, entities will be added
                    //if database doesn't exist, a new database will be created

                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

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

            using (var scope = host.Services.CreateScope())
            { //using calls Dispose() after the using-block is left, even if the code throws an exception.
                var services = scope.ServiceProvider;

                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate(); //checking if the db is existing when we run the app. If not, it will migrate and create one for us.
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            host.Run();
        }
Exemplo n.º 11
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            // using keyword ensures that the variable is disposed once the method has completed.
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            // Checks if there are any pending migrations, and performs them.
            try
            {
                var context = services.GetRequiredService <DataContext>();
                await context.Database.MigrateAsync();

                await Seed.SeedData(context);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occured during migration!");
            }
            await host.RunAsync();
        }
Exemplo n.º 12
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

                try {
                    // Attempt to apply db migrations when starting app
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();

                    await context.Database.MigrateAsync();

                    await Seed.SeedData(context, userManager);
                }catch (Exception ex) {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during database migration");
                }
            }

            await host.RunAsync();
        }
Exemplo n.º 13
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            //the using statement cleans up after it is run
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            //if no errors occur it will run the application with the db migrated.
            host.Run();
        }
Exemplo n.º 14
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scop = host.Services.CreateScope())
            {
                var services = scop.ServiceProvider;
                try
                {
                    // her  seferide database control edip eğer yen bir modül var ise oluşturacak
                    var context     = services.GetRequiredService <Datacontext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            host.Run();
        }
Exemplo n.º 15
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 <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    context.Database.Migrate();           //Migrates Database each time Application runs
                    Seed.SeedData(context, userManager, roleManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An Error Occured while migration. !!&&!!");
                }
                host.Run();
            }
        }
Exemplo n.º 16
0
        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>();

                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    await Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError($"An error occurred during migration: {ex.Message}");
                }
            }
            host.Run();
        }
Exemplo n.º 17
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                // Migrate DB before running app
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    // Seed logic (currently activities)
                    Seed.SeedData(context);
                }
                catch (System.Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            host.Run();
        }
Exemplo n.º 18
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            //var host = new WebHostBuilder().UseKestrel().UseContentRoot(Directory.GetCurrentDirectory()).UseUrls("http://localhost:5000").UseIISIntegration().UseStartup<Startup>().Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            host.Run();
        }
Exemplo n.º 19
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();

                    // Programatically seed database by invoking the static method SeedData on the public Persistence Seed class.
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex.Message);
                }
            }
            host.Run();
        }
Exemplo n.º 20
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            ValidatorOptions.LanguageManager.Enabled = false;
            host.Run();
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            IHost host = CreateHostBuilder(args).Build();

            using (IServiceScope scope = host.Services.CreateScope())
            {
                IServiceProvider services = scope.ServiceProvider;
                try
                {
                    DataContext           context = services.GetRequiredService <DataContext>();
                    UserManager <AppUser> manager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, manager).Wait();
                }
                catch (Exception e)
                {
                    ILogger logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "An error occured during migration.");
                }
            }

            host.Run();
        }
Exemplo n.º 22
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context     = services.GetRequiredService <CoopUpContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "Une erreur est survenue pendant la migration des données");
                }
            }

            host.Run();
        }
Exemplo n.º 23
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            //Dispose whats inside after done.
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    //Will create the database if not already created.
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            host.Run();
        }
Exemplo n.º 24
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var Services = scope.ServiceProvider;
                try
                {
                    var context = Services.GetRequiredService <DataContext>();

                    // Will create the database if it does not already exist
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = Services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured while Migration");
                }
            }
            host.Run();
        }
Exemplo n.º 25
0
        //method that executes when we start our application
        public static void Main(string[] args)
        {   //arguments that are supplied from the command line
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    //checks to see if we got a database and if not one will be created base on our migrations
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }
Exemplo n.º 26
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()) // Dependecy injection
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();                 // tworzy baze denych jezeli nie istnieje
                    Seed.SeedData(context, userManager).Wait(); // dodanie poczatkowych wartosci do bazy danych
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }
Exemplo n.º 27
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    //call the seed db in Persistence
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred during migration");
                }
            }
            host.Run();
        }
Exemplo n.º 28
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

            // check for database existence and create if it doesn't
            try
            {
                //look for DataContext as defined in Persistence
                var context = services.GetRequiredService <DataContext>();
                context.Database.Migrate();
                Seed.SeedData(context);
            }
            catch (Exception e)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(e, "An error occurred during migration");
            }

            host.Run();
        }
Exemplo n.º 29
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager);
                }
                catch (Exception e)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "Failed to Migrate Database");
                }
            }

            host.Run();
        }
Exemplo n.º 30
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 <DataContext>();
                    // UserManager is returning async, so we should wait before seeding.
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration.");
                }
            }
            host.Run();
        }