Ejemplo n.º 1
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 <ApplicationDbContext>();
                    var dpContext     = services.GetRequiredService <DataProtectionKeysContext>();
                    var functionalSvc = services.GetRequiredService <IFunctionalSvc>();
                    var countrySvc    = services.GetRequiredService <ICountrySvc>();

                    DbContextInitializer.Initialize(dpContext, context, functionalSvc, countrySvc).Wait();
                }
                catch (Exception ex)
                {
                    Log.Error("An error occured while seeding the database {Error} {StackTrace} {InnerException} {Source}",
                              ex.Message, ex.StackTrace, ex.InnerException, ex.Source);
                }
            }

            host.Run();
        }
Ejemplo n.º 2
0
        public static void PrepareDatabase(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context = services.GetRequiredService <AppDataContext>();
                DbContextInitializer.Initialize(context);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occurred while seeding the database.");
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            var env = new HostingEnvironment
            {
                ContentRootPath = Directory.GetCurrentDirectory()
            };

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Error()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Error)
                         .Enrich.FromLogContext()
                         .Enrich.WithProperty("Application", "CMS_APP")
                         .Enrich.WithProperty("MachineName", Environment.MachineName)
                         .Enrich.WithProperty("CurrentManagedThreadId", Environment.CurrentManagedThreadId)
                         .Enrich.WithProperty("OSVersion", Environment.OSVersion)
                         .Enrich.WithProperty("Version", Environment.Version)
                         .Enrich.WithProperty("UserName", Environment.UserName)
                         .Enrich.WithProperty("ProcessId", Process.GetCurrentProcess().Id)
                         .Enrich.WithProperty("ProcessName", Process.GetCurrentProcess().ProcessName)
                         .WriteTo.File(formatter: new CompactJsonFormatter(),
                                       path: Path.Combine(env.ContentRootPath + $"{Path.DirectorySeparatorChar}Logs{Path.DirectorySeparatorChar}", $"load_error_{DateTime.Now:yyyyMMdd}.json"))
                         .CreateLogger();

            var host = CreateWebHostBuilder(args).Build();

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

                try
                {
                    var logger          = Log.Logger;
                    var context         = services.GetRequiredService <ApplicationDbContext>();
                    var quartzDbContext = services.GetRequiredService <QuartzDbContext>();
                    var functional      = services.GetRequiredService <IFunctionalService>();
                    DbContextInitializer.Initialize(context, quartzDbContext, functional, logger).Wait();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }
Ejemplo 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 <GameItemsContext>();
                    DbContextInitializer.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.º 5
0
        public static void Main(string[] args)
        {
            DbContextInitializer.Initialize();

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