Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("START");

            try
            {
                var arguments = new Arguments().Parse(args);

                Console.WriteLine("Datasource: {0}", arguments.Datasource);
                Console.WriteLine("Catalog: {0}", arguments.Catalog);

                if (arguments.ForceReseeding)
                {
                    Console.WriteLine("Forcing the reseeding of the system accounts");
                }

                using (var dbContext = new DatabaseContextFactory().Create(arguments.Datasource, arguments.Catalog))
                {
                    Console.WriteLine("Seeding the database with data...");
                    var seedManager = new SeedManager(dbContext, arguments.ForceReseeding);
                    seedManager.Seed();
                }

                Console.WriteLine("Database seeded.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToDetail());
            }
            finally
            {
                Console.WriteLine("END");
            }
        }
Ejemplo n.º 2
0
        public static void RegisterPersistence(this IServiceCollection services, string connectionString)
        {
            services.AddSingleton <IDataBaseServiceOptions>(provider => new DataBaseServiceOptions()
            {
                ConnectionString = connectionString, Provider = services.BuildServiceProvider()
            });

            services.AddDbContext <DatabaseService>();
            services.AddScoped <IDatabaseService, DatabaseService>();
            services.AddTransient <SeedManager, SeedManager>();
            services.AddScoped(typeof(IRepository <>), typeof(Repository <>));

            // ======================================Seed Management==========================
            SeedManager seedManager = services.BuildServiceProvider().GetService <SeedManager>();

            seedManager.Seed();
        }
Ejemplo n.º 3
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              SeedManager seedManager,
                              MigrationManager migrationManager)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                loggerFactory.AddSerilog();
                Log.Logger().Information("Application is starting...");
                Log.Logger().Information("Configuration:");

                ConfigurationProvider.GetType().GetProperties().ToList().ForEach(prop =>
                {
                    Log.Logger().Information("[{name}] = '{value}'", prop.Name, prop.GetValue(ConfigurationProvider));
                });

                DateTimeContext.Initialize(ConfigurationProvider.TimeZone);

                Log.Logger().Information("Configure EF Mappings...");
                MappingConfig.RegisterMappings();

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseDatabaseErrorPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error"); //todo IS incorrect page diesnt exist yet!!
                    app.UseHsts();
                    app.UseHttpsRedirection();
                }

                app.UseStaticFiles(new StaticFileOptions {
                    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot"))
                });
                app.UseSession();
                app.UseAuthentication();

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

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

                //migrationManager.EnsureCreated(ConfigurationProvider);
                //migrationManager.ApplyMigrations(ConfigurationProvider);
                seedManager.Seed(ConfigurationProvider);
            }
            catch (Exception e)
            {
                Log.Logger().Error(e, "Application failed to start");

                throw;
            }
            finally
            {
                stopwatch.Stop();
                Log.Logger().Information("Startup time: {Seconds}s", stopwatch.Elapsed.Seconds);
            }
        }