예제 #1
0
        private async Task MigrateHostDatabaseAsync()
        {
            Logger.LogInformation("Migrating host database schema...");
            await _dbSchemaMigrator.MigrateAsync();

            Logger.LogInformation("Executing host database seed...");
            await _dataSeeder.SeedAsync();

            Logger.LogInformation("Successfully completed host database migrations.");
        }
        public async Task FooAsync()
        {
            // 内部调用所有IDataSeedContributor实现以完成数据播种
            // 可以在这里设置租户
            await _dataSeeder.SeedAsync(new Guid());


            // 将命名的配置参数发送到SeedAsync方法
            await _dataSeeder.SeedAsync(
                new DataSeedContext()
                .WithProperty("MyProperty1", "MyValue1")
                .WithProperty("MyProperty2", 42)
                );
        }
예제 #3
0
        public async Task BuildInternalAsync()
        {
            await _dataSeeder.SeedAsync();

            await _bookRepository.InsertAsync(
                new Book
            {
                Id          = Guid.NewGuid(),
                Name        = "Test book 1",
                Type        = BookType.Fantastic,
                PublishDate = new DateTime(2015, 05, 24),
                Price       = 21
            }
                );

            await _bookRepository.InsertAsync(
                new Book
            {
                Id          = Guid.NewGuid(),
                Name        = "Test book 2",
                Type        = BookType.Science,
                PublishDate = new DateTime(2014, 02, 11),
                Price       = 15
            }
                );
        }
        private async Task SeedDataAsync(Tenant tenant = null)
        {
            Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");

            await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
                                        .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue)
                                        .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue)
                                        );
        }
예제 #5
0
        private Task SeedHostDataAsync()
        {
            _logger.LogInformation($"Executing database seed...");

            return(_dataSeeder.SeedAsync(new DataSeedContext()
                                         .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue)
                                         .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue)
                                         ));
        }
        public async Task HandleEventAsync(EntityCreatedEto <TenantEto> eventData)
        {
            Logger.LogInformation($"Handled distributed event for a new tenant creation. TenantId: {eventData.Entity.Id}");

            using (_currentTenant.Change(eventData.Entity.Id, eventData.Entity.Name))
            {
                await _dataSeeder.SeedAsync(tenantId : eventData.Entity.Id);
            }
        }
        public async Task MigrateAsync()
        {
            foreach (var migrator in _dbSchemaMigrators)
            {
                await migrator.MigrateAsync();
            }

            await _dataSeeder.SeedAsync();
        }
        private async Task SeedDataAsync(Tenant? tenant = null)
        {
            Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");

            var adminEmail = _configuration["Admin:Email"] ?? "*****@*****.**";
            var adminPassword = _configuration["Admin:Password"] ?? "1q2w3E*";
            var context = new DataSeedContext(tenant?.Id)
                .WithProperty("AdminEmail", adminEmail)
                .WithProperty("AdminPassword", adminPassword);
            await _dataSeeder.SeedAsync(context);
        }
예제 #9
0
        public async Task MigrateAsync()
        {
            Logger.LogInformation($"Started {AbpIdentityDbProperties.ConnectionStringName} database migrations...");

            Logger.LogInformation("Migrating database schema...");
            await _dbSchemaMigrator.MigrateAsync();

            Logger.LogInformation("Executing database seed...");
            await _dataSeeder.SeedAsync();

            Logger.LogInformation("Successfully completed database migrations.");
        }
        public async Task MigrateAsync()
        {
            Logger.LogInformation("Started database migrations...");

            Logger.LogInformation("Migrating database schema...");
            await _dbSchemaMigrator.MigrateAsync();

            Logger.LogInformation("Executing database seed...");
            await _dataSeeder.SeedAsync();

            Logger.LogInformation("Successfully completed database migrations.");
        }
예제 #11
0
        public async Task MigrateAsync()
        {
            // Logger.LogInformation("Started database migrations...");

            foreach (var migrator in _dbSchemaMigrators)
            {
                await migrator.MigrateAsync();
            }

            await _dataSeeder.SeedAsync();

            // Logger.LogInformation("Started database migrations...");
        }
예제 #12
0
        private async Task SeedDataAsync(Tenant tenant = null)
        {
            Logger.LogInformation($"Migrating schema for {tenant?.Name} database...");

            foreach (var migrator in _dbSchemaMigrators)
            {
                await migrator.MigrateAsync();
            }

            Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");

            await _dataSeeder.SeedAsync(tenant?.Id);
        }
예제 #13
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              IApplicationLifetime lifetime, IDataSeeder dataSeeder)
        {
            if (env.IsDevelopment() || env.IsEnvironment("local"))
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseErrorHandler();
            app.UseMvc();

            lifetime.ApplicationStopped.Register(() => Container.Dispose());
            dataSeeder.SeedAsync().Wait();
        }
        private async Task MigrateAndSeedForTenantAsync(
            Guid tenantId,
            string adminEmail,
            string adminPassword)
        {
            try
            {
                using (_currentTenant.Change(tenantId))
                {
                    // Create database tables if needed
                    using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false))
                    {
                        var tenantConfiguration = await _tenantStore.FindAsync(tenantId);

                        if (tenantConfiguration?.ConnectionStrings != null &&
                            !tenantConfiguration.ConnectionStrings.Default.IsNullOrWhiteSpace())
                        {
                            foreach (var migrator in _dbSchemaMigrators)
                            {
                                await migrator.MigrateAsync();
                            }
                        }

                        await uow.CompleteAsync();
                    }

                    // Seed data
                    using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
                    {
                        await _dataSeeder.SeedAsync(
                            new DataSeedContext(tenantId)
                            .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, adminEmail)
                            .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, adminPassword)
                            );

                        await uow.CompleteAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }
        }
예제 #15
0
 public async Task BuildInternalAsync()
 {
     await _dataSeeder.SeedAsync();
 }
예제 #16
0
        //[Authorize(Policy = "HasAdminRole")]
        public async Task <IActionResult> Get()
        {
            await _dataSeeder.SeedAsync();

            return(NoContent());
        }
예제 #17
0
 public static Task SeedAsync(this IDataSeeder seeder, Guid?tenantId = null)
 {
     return(seeder.SeedAsync(new DataSeedContext(tenantId)));
 }
예제 #18
0
 private async Task SeedDataAsync()
 {
     await dataSeeder.SeedAsync(new DataSeedContext());
 }
예제 #19
0
        private async Task SeedDataAsync()
        {
            Logger.LogInformation("Executing database seed...");

            await _dataSeeder.SeedAsync();
        }
예제 #20
0
        private async Task SeedDataAsync()
        {
            Logger.LogInformation($"Executing host database seed...");

            await _dataSeeder.SeedAsync(new DataSeedContext());
        }
예제 #21
0
        private async Task SeedDataAsync(Tenant tenant = null)
        {
            Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");

            await _dataSeeder.SeedAsync(tenant?.Id);
        }
예제 #22
0
        private static async Task ResetDataAsync(OperationContext context, IDataSeeder dataSeeder, SeedData seedData, IServiceHttpClientFactory serviceClientFactory)
        {
            await dataSeeder.SeedAsync(seedData);

            await ClearCacheAsync(context, serviceClientFactory);
        }