Beispiel #1
0
        private static bool TestConection(TenantInfo tenantInfo, string connectionString)
        {
            var builder = new DbContextOptionsBuilder <NextAppContext>();

            builder.UseNpgsql(connectionString);
            using (var db = new NextAppContext(tenantInfo, builder.Options))
            {
                if (db.Database.CanConnect() == false)
                {
                    return(false);
                }
            }
            return(true);
        }
        public async Task Consume(ConsumeContext <TenantCreatedNotDefault> context)
        {
            //TODO exceptions
            log.LogInformation($"NonDefault Tenant created with id: '{context.Message.Id}' on: '{context.Message.CreationTime.ToString()}'");
            // throw new NotImplementedException();
            var tenantInfo = await store.TryGetAsync(context.Message.Id);

            if (tenantInfo is null)
            {
                log.LogInformation($"Failed to prepare database for Tenant with id: '{context.Message.Id}' on: '{context.Message.CreationTime.ToString()}'");
                return;
            }
            var builder = new DbContextOptionsBuilder <NextAppContext>().UseNpgsql(tenantInfo.ConnectionString);

            using (var db = new NextAppContext(tenantInfo, builder.Options))
            {
                db.Database.EnsureCreated();
                db.Database.Migrate();
            }
            log.LogInformation($"Prepared database for Tenant with id: '{context.Message.Id}' on: '{context.Message.CreationTime.ToString()}'");
        }