public static void AddMongoDB <TMongoSeeder>(this IServiceCollection services, IConfiguration configuration) where TMongoSeeder : class, IDatabaseSeeder
        {
            IConfigurationSection mongoConfigurationSection = configuration.GetSection("mongo");

            services.Configure <MongoOptions>(mongoConfigurationSection);
            services.AddSingleton(serviceProvider =>
            {
                IOptions <MongoOptions> options = serviceProvider.GetService <IOptions <MongoOptions> >();
                return(new MongoClient(options.Value.ConnectionString));
            });

            services.AddScoped(serviceProvider =>
            {
                IOptions <MongoOptions> options = serviceProvider.GetService <IOptions <MongoOptions> >();
                MongoClient client = serviceProvider.GetService <MongoClient>();

                return(client.GetDatabase(options.Value.Database));
            });

            services.AddScoped <IDatabaseSeeder, TMongoSeeder>();

            services.AddScoped <IDatabaseInitializer>(serviceProvider =>
            {
                IOptions <MongoOptions> options = serviceProvider.GetService <IOptions <MongoOptions> >();
                IMongoDatabase database         = serviceProvider.GetService <IMongoDatabase>();
                IDatabaseSeeder seeder          = serviceProvider.GetService <IDatabaseSeeder>();
                return(new MongoInitializer(database, seeder, options));
            });
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              IIdentitySeeder identitySeeder,
                              IDatabaseSeeder databaseSeeder)
        {
            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?}");
                endpoints.MapRazorPages();
            });

            identitySeeder.Seed();
            //Identity seeder needs to be run first so roles and admin are seeded
            databaseSeeder.Seed();
        }
Exemplo n.º 3
0
        public void Configure(
            IApplicationBuilder applicationBuilder,
            IHostingEnvironment hostingEnvironment,
            IDatabaseInitializer databaseInitializer,
            IDatabaseSeeder databaseSeeder)
        {
            if (hostingEnvironment.IsDevelopment())
            {
                applicationBuilder.UseDeveloperExceptionPage();
            }

            applicationBuilder.UseStaticFiles();

            applicationBuilder.UseHttpsRedirection();

            applicationBuilder.UseCors(AllowAnyOriginPolicyName);

            applicationBuilder.UseMvc(routes =>
            {
                routes.MapRoute("default", "api/{controller}/{action}/{id?}");
            });

            databaseInitializer.Initialize();
            databaseSeeder.Seed();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Construct an <see cref="InstanceManager"/>
        /// </summary>
        /// <param name="instanceFactory">The value of <see cref="instanceFactory"/></param>
        /// <param name="ioManager">The value of <paramref name="ioManager"/></param>
        /// <param name="databaseContextFactory">The value of <paramref name="databaseContextFactory"/></param>
        /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
        /// <param name="jobManager">The value of <see cref="jobManager"/></param>
        /// <param name="serverControl">The value of <see cref="serverControl"/></param>
        /// <param name="systemIdentityFactory">The value of <see cref="systemIdentityFactory"/>.</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
        /// <param name="databaseSeeder">The value of <see cref="databaseSeeder"/>.</param>
        /// <param name="serverPortProvider">The value of <see cref="serverPortProvider"/>.</param>
        /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        public InstanceManager(
            IInstanceFactory instanceFactory,
            IIOManager ioManager,
            IDatabaseContextFactory databaseContextFactory,
            IAssemblyInformationProvider assemblyInformationProvider,
            IJobManager jobManager,
            IServerControl serverControl,
            ISystemIdentityFactory systemIdentityFactory,
            IAsyncDelayer asyncDelayer,
            IDatabaseSeeder databaseSeeder,
            IServerPortProvider serverPortProvider,
            IOptions <GeneralConfiguration> generalConfigurationOptions,
            ILogger <InstanceManager> logger)
        {
            this.instanceFactory             = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
            this.ioManager                   = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.databaseContextFactory      = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
            this.jobManager                  = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
            this.serverControl               = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
            this.systemIdentityFactory       = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory));
            this.asyncDelayer                = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            this.databaseSeeder              = databaseSeeder ?? throw new ArgumentNullException(nameof(databaseSeeder));
            this.serverPortProvider          = serverPortProvider ?? throw new ArgumentNullException(nameof(serverPortProvider));
            generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            lazyRestartRegistration = new Lazy <IRestartRegistration>(() => serverControl.RegisterForRestart(this));

            instances      = new Dictionary <long, InstanceContainer>();
            bridgeHandlers = new Dictionary <string, IBridgeHandler>();
            readyTcs       = new TaskCompletionSource <object>();
            instanceStateChangeSemaphore = new SemaphoreSlim(1);
        }
 public MongoInitializer(IMongoDatabase database,
                         IDatabaseSeeder seeder,
                         IOptions <MongoOptions> options)
 {
     _database = database;
     _seeder   = seeder;
     _seed     = options.Value.Seed;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Construct a <see cref="SqlServerDatabaseContext"/>
 /// </summary>
 /// <param name="dbContextOptions">The <see cref="DbContextOptions{TContext}"/> for the <see cref="DatabaseContext"/></param>
 /// <param name="databaseConfiguration">The <see cref="IOptions{TOptions}"/> of <see cref="DatabaseConfiguration"/> for the <see cref="DatabaseContext"/></param>
 /// <param name="databaseSeeder">The <see cref="IDatabaseSeeder"/> for the <see cref="DatabaseContext"/></param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="DatabaseContext"/></param>
 public PostgresSqlDatabaseContext(
     DbContextOptions <PostgresSqlDatabaseContext> dbContextOptions,
     IOptions <DatabaseConfiguration> databaseConfiguration,
     IDatabaseSeeder databaseSeeder,
     ILogger <PostgresSqlDatabaseContext> logger)
     : base(dbContextOptions, databaseConfiguration, databaseSeeder, logger)
 {
 }
 //Ioption helps us to know if we should seed the database or not
 public DatabaseInitialiser(IMongoDatabase database,
                            IDatabaseSeeder seeder,
                            IOptions <MongoOption> options)
 {
     this._database = database;
     this.seed      = options.Value.Seed;
     this._seeder   = seeder;
 }
Exemplo n.º 8
0
 public MongoInitializer(
     IOptions <MongoOptions> options,
     IDatabaseSeeder databaseSeeder,
     IMongoDatabase database)
 {
     _seed           = options.Value.Seed;
     _databaseSeeder = databaseSeeder;
     _database       = database;
 }
Exemplo n.º 9
0
        public void InitializeDatabase(IDatabaseSeeder databaseSeeder, bool seed)
        {
            Database.EnsureCreated(); // Migrate() to use migration

            CreateTypes();
            CreateStoredProcedures();

            if (seed)
            {
                databaseSeeder.Seed(this);
            }
        }
Exemplo n.º 10
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.UseEnvironment("Test");

            builder.ConfigureServices(services =>
            {
                // Create a new service provider.
                var serviceProvider = new ServiceCollection()
                                      .AddEntityFrameworkInMemoryDatabase()
                                      .BuildServiceProvider();

                // Add a database context (AppDbContext) using an in-memory database for testing.
                services.AddDbContext <DeployManagerContext>(options =>
                {
                    options.UseInMemoryDatabase(options.GetType().Name);
                    options.UseInternalServiceProvider(serviceProvider);
                });

                // Build the service provider.
                Service = services.BuildServiceProvider();

                // Create a scope to obtain a reference to the database contexts
                using (var scope = Service.CreateScope())
                {
                    var scopedServices = scope.ServiceProvider;
                    var db             = scopedServices.GetRequiredService <DeployManagerContext>();
                    var logger         = scopedServices.GetRequiredService <ILogger <DeployManagerWebApiFactory <TStartup> > >();

                    // Ensure the database is created.
                    db.Database.EnsureCreated();

                    try
                    {
                        // Seed the database with some specific test data.
                        var seeders = new IDatabaseSeeder[] {
                            new DeployTypeSeeder(),
                            new ServerTypeSeeder(),
                            new ServerInstanceSeeder(),
                        };
                        foreach (var seeder in seeders)
                        {
                            seeder.SeedAsync(db).Wait();
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, "An error occurred seeding the " +
                                        "database. Error: {ex.Message}");
                    }
                }
            });
        }
Exemplo n.º 11
0
        // ctor
        public MainViewModel(
            IDataImporterClass dataImporter,
            IDatabaseChecker databaseChecker,
            IDatabaseSeeder databaseSeeder, IDataLoader dataLoader)
        {
            _dataImporter = dataImporter;
            _databaseChecker = databaseChecker;
            _databaseSeeder = databaseSeeder;
            _dataLoader = dataLoader;

            ImportCommand = new RelayCommand(Import);
            LoadedCommand = new RelayCommand(Loaded);

            Games = new ObservableCollection<Game>();
        }
Exemplo n.º 12
0
        // public async Task InitializeAsync()
        // {
        //     if(this._initialized){
        //         return;
        //     }

        //     RegisterConventions();
        //     this._initialized=true;
        //     if(!this._seed){
        //         return;
        //     }


        //     await this.seeder.SeedAsync();
        // }

        public async Task InitializeAsync(IDatabaseSeeder seeder)
        {
            if (this._initialized)
            {
                return;
            }

            RegisterConventions();
            this._initialized = true;
            if (!this._seed)
            {
                return;
            }


            await seeder.SeedAsync();
        }
Exemplo n.º 13
0
        private static IServiceCollection AddAspNetIdentitySeedServices(this IServiceCollection services, IHostingEnvironment environment)
        {
            services.AddScoped <ISeedDataProvider <UserDbContext> >(opts =>
                                                                    new SeedDataProvider <UserDbContext>(
                                                                        opts.GetService <ILogger <SeedDataProvider <UserDbContext> > >(),
                                                                        "NLIP.iShare.AuthorizationRegistry.IdentityServer.Migrations.Seed.AspNetIdentity",
                                                                        typeof(IdentityServerConfiguration).GetTypeInfo().Assembly)
                                                                    );

            services.AddScoped <Migrations.Seed.AspNetIdentity.Seeders.ProdDatabaseSeeder>();
            services.AddScoped <Migrations.Seed.AspNetIdentity.Seeders.QaDatabaseSeeder>();
            services.AddScoped <Migrations.Seed.AspNetIdentity.Seeders.DevelopmentDatabaseSeeder>();
            services.AddScoped <Migrations.Seed.AspNetIdentity.Seeders.AccDatabaseSeeder>();

            services.AddScoped(opts =>
            {
                var environmentName = environment.EnvironmentName;
                IDatabaseSeeder <UserDbContext> databaseSeeder = null;
                switch (environmentName)
                {
                case Environments.Qa:
                    databaseSeeder = opts.GetService <Migrations.Seed.AspNetIdentity.Seeders.QaDatabaseSeeder>();
                    break;

                case Environments.Prod:
                    databaseSeeder = opts.GetService <Migrations.Seed.AspNetIdentity.Seeders.ProdDatabaseSeeder>();
                    break;

                case Environments.Acc:
                    databaseSeeder = opts.GetService <Migrations.Seed.AspNetIdentity.Seeders.AccDatabaseSeeder>();
                    break;

                case Environments.Development:
                    databaseSeeder = opts.GetService <Migrations.Seed.AspNetIdentity.Seeders.DevelopmentDatabaseSeeder>();
                    break;

                default:
                    throw new DatabaseSeedException($"{environmentName} is not registered.");
                }

                return(databaseSeeder);
            });

            return(services);
        }
Exemplo n.º 14
0
        public void Configure(
            IApplicationBuilder applicationBuilder,
            IDatabaseInitializer databaseInitializer,
            IDatabaseSeeder databaseSeeder)
        {
            applicationBuilder.UseDeveloperExceptionPage();
            applicationBuilder.UseStaticFiles();

            databaseInitializer.Initialize();
            applicationBuilder.UseCors(AllowAnyOriginPolicyName);

            applicationBuilder.UseMvc(routes =>
            {
                routes.MapRoute("default", "api/{controller}/{action}/{id?}");
            });

            applicationBuilder.UseAuthentication();

            databaseSeeder.Seed();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Construct a <see cref="DatabaseContext"/>
        /// </summary>
        /// <param name="dbContextOptions">The <see cref="DbContextOptions"/> for the <see cref="DatabaseContext"/>.</param>
        /// <param name="databaseConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="DatabaseConfiguration"/></param>
        /// <param name="databaseSeeder">The value of <see cref="databaseSeeder"/></param>
        /// <param name="logger">The value of <see cref="Logger"/></param>
        public DatabaseContext(DbContextOptions dbContextOptions, IOptions <DatabaseConfiguration> databaseConfigurationOptions, IDatabaseSeeder databaseSeeder, ILogger logger) : base(dbContextOptions)
        {
            DatabaseConfiguration = databaseConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(databaseConfigurationOptions));
            this.databaseSeeder   = databaseSeeder ?? throw new ArgumentNullException(nameof(databaseSeeder));
            Logger = logger ?? throw new ArgumentNullException(nameof(logger));

            usersCollection                = new DatabaseCollection <User>(Users);
            instancesCollection            = new DatabaseCollection <Instance>(Instances);
            instanceUsersCollection        = new DatabaseCollection <InstanceUser>(InstanceUsers);
            compileJobsCollection          = new DatabaseCollection <CompileJob>(CompileJobs);
            repositorySettingsCollection   = new DatabaseCollection <RepositorySettings>(RepositorySettings);
            dreamMakerSettingsCollection   = new DatabaseCollection <DreamMakerSettings>(DreamMakerSettings);
            dreamDaemonSettingsCollection  = new DatabaseCollection <DreamDaemonSettings>(DreamDaemonSettings);
            chatBotsCollection             = new DatabaseCollection <ChatBot>(ChatBots);
            chatChannelsCollection         = new DatabaseCollection <ChatChannel>(ChatChannels);
            revisionInformationsCollection = new DatabaseCollection <RevisionInformation>(RevisionInformations);
            jobsCollection = new DatabaseCollection <Job>(Jobs);
            reattachInformationsCollection         = new DatabaseCollection <ReattachInformation>(ReattachInformations);
            watchdogReattachInformationsCollection = new DatabaseCollection <DualReattachInformation>(WatchdogReattachInformations);
        }
Exemplo n.º 16
0
 public InstallController(
     UserManager <ApplicationUser> userManager,
     RoleManager <ApplicationRole> roleManager,
     ICompanyWorkData companyWorkData,
     ISchedulerWorkData schedulerWorkData,
     IAccountingWorkData accountingWorkData,
     IMapper mapper,
     ILoggerFactory loggerFactory,
     IDatabaseSeeder dataSeeder,
     IRolesSeder rolesSeeder,
     IServiceScopeFactory services,
     IEventsFactory eventsFactory)
     : base(companyWorkData, schedulerWorkData, accountingWorkData, mapper)
 {
     this.userManager   = userManager;
     this.roleManager   = roleManager;
     this.dataSeeder    = dataSeeder;
     this.rolesSeeder   = rolesSeeder;
     this.services      = services;
     this.eventsFactory = eventsFactory;
     this.logger        = loggerFactory.CreateLogger <InstallController>();
 }
Exemplo n.º 17
0
 public MongoInitializer(IDatabaseSeeder databaseSeeder, IOptions <MongoOptions> options)
 {
     this.databaseSeeder = databaseSeeder;
     this.seed           = options.Value.Seed;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Construct a <see cref="SqlServerDatabaseContext"/>
 /// </summary>
 /// <param name="dbContextOptions">The <see cref="DbContextOptions{TContext}"/> for the <see cref="DatabaseContext"/></param>
 /// <param name="databaseConfiguration">The <see cref="IOptions{TOptions}"/> of <see cref="DatabaseConfiguration"/> for the <see cref="DatabaseContext"/></param>
 /// <param name="databaseSeeder">The <see cref="IDatabaseSeeder"/> for the <see cref="DatabaseContext"/></param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="DatabaseContext"/></param>
 public SqlServerDatabaseContext(DbContextOptions <SqlServerDatabaseContext> dbContextOptions, IOptions <DatabaseConfiguration> databaseConfiguration, IDatabaseSeeder databaseSeeder, ILogger <SqlServerDatabaseContext> logger) : base(dbContextOptions, databaseConfiguration, databaseSeeder, logger)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoInitializer"/> class.
 /// </summary>
 /// <param name="options">Options for initilzation</param>
 /// <param name="seeder">the database seeder</param>
 public MongoInitializer(IOptions <MongoOptions> options, IDatabaseSeeder seeder)
 {
     this._seeder = seeder;
     this._seed   = options.Value.Seed;
 }
Exemplo n.º 20
0
 /// <summary>MySqlInitializer
 /// Constructor
 /// </summary>
 /// <param name="database">Database connection</param>
 /// <param name="seeder">Database seeder</param>
 /// <param name="options">MySqlOptions object</param>
 public MySqlInitializer(MySqlConnection database, IDatabaseSeeder seeder, IOptions <MySqlOptions> options)
 {
     Connection = database;
     _seeder    = seeder;
     _seed      = options.Value.Seed;
 }
 /// <summary>
 /// Construct a <see cref="DatabaseContext{TParentContext}"/>
 /// </summary>
 /// <param name="dbContextOptions">The <see cref="DbContextOptions{TParentContext}"/> for the <see cref="DatabaseContext{TParentContext}"/></param>
 /// <param name="databaseConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="DatabaseConfiguration"/></param>
 /// <param name="databaseSeeder">The value of <see cref="databaseSeeder"/></param>
 /// <param name="logger">The value of <see cref="Logger"/></param>
 public DatabaseContext(DbContextOptions <TParentContext> dbContextOptions, IOptions <DatabaseConfiguration> databaseConfigurationOptions, IDatabaseSeeder databaseSeeder, ILogger logger) : base(dbContextOptions)
 {
     DatabaseConfiguration = databaseConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(databaseConfigurationOptions));
     this.databaseSeeder   = databaseSeeder ?? throw new ArgumentNullException(nameof(databaseSeeder));
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Exemplo n.º 22
0
 public MongoInitializer(IOptions <MongoOptions> options, IMongoDatabase database, IDatabaseSeeder databaseSeeder)
 {
     this.database       = database;
     seed                = options.Value.Seed;
     this.databaseSeeder = databaseSeeder;
 }
 public MongoIntializer(IMongoDatabase mongoDatabase, IOptions <MongoOptions> options, IDatabaseSeeder seeder)
 {
     _seeder        = seeder;
     _mongoDatabase = mongoDatabase;
     _seed          = options.Value.Seed;
 }
Exemplo n.º 24
0
 private void SeedDatabase(IDatabaseSeeder databaseSeeder)
 {
     databaseSeeder.Seed();
 }
Exemplo n.º 25
0
 public MongoDatabaseInitializer(IDatabaseSeeder seeder, IOptions <MongoOptions> options)
 {
     _seeder = seeder;
     _seed   = options.Value.Seed;
 }
 public SeedDatabaseCommandHandler(IUnitOfWork unitOfWork, IDatabaseSeeder databaseSeeder)
 {
     _unitOfWork     = unitOfWork;
     _databaseSeeder = databaseSeeder;
 }
Exemplo n.º 27
0
 public DatabaseInitializer(IMongoDatabase db, IDatabaseSeeder seeder, IOptions <MongoOptions> opts)
 {
     _database = db;
     _seeder   = seeder;
     _seed     = opts.Value.Seed;
 }