public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            connectionString = connectionString;
            if (connectionString.ToLower().Contains("convert zero datetime"))
            {
                services.AddDbContext <CaseTemplatePnDbContext>(o => o.UseMySql(connectionString,
                                                                                b => b.MigrationsAssembly(PluginAssembly().FullName)));
            }
            else
            {
                services.AddDbContext <CaseTemplatePnDbContext>(o => o.UseSqlServer(connectionString,
                                                                                    b => b.MigrationsAssembly(PluginAssembly().FullName)));
            }

            CaseTemplatePnContextFactory contextFactory = new CaseTemplatePnContextFactory();
            var context = contextFactory.CreateDbContext(new[] { connectionString });

            context.Database.Migrate();

            // Seed database
            SeedDatabase(connectionString);

            string temp = context.PluginConfigurationValues
                          .SingleOrDefault(x => x.Name == "BaneDanmarkLaBaseSettings:MaxParallelism")?.Value;

            _maxParallelism = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);

            temp = context.PluginConfigurationValues
                   .SingleOrDefault(x => x.Name == "BaneDanmarkLaBaseSettings:NumberOfWorkers")?.Value;
            _numberOfWorkers = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);
        }
Exemple #2
0
        private void GetContext(string connectionStr)
        {
            CaseTemplatePnContextFactory contextFactory = new CaseTemplatePnContextFactory();

            DbContext = contextFactory.CreateDbContext(new[] { connectionStr });

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
Exemple #3
0
        public void AddPluginConfig(IConfigurationBuilder builder, string connectionString)
        {
            var seedData       = new BaneDanmarkLaConfigurationSeedData();
            var contextFactory = new CaseTemplatePnContextFactory();

            builder.AddPluginConfiguration(
                connectionString,
                seedData,
                contextFactory);
        }
Exemple #4
0
        public void SeedDatabase(string connectionString)
        {
            // Get DbContext
            var contextFactory = new CaseTemplatePnContextFactory();

            using (var context = contextFactory.CreateDbContext(new[] { connectionString }))
            {
                // Seed configuration
                BaneDanmarkLaPluginSeed.SeedData(context);
            }
        }
Exemple #5
0
        public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            _connectionString = connectionString;
            if (connectionString.ToLower().Contains("convert zero datetime"))
            {
                services.AddDbContext <CaseTemplatePnDbContext>(o => o.UseMySql(connectionString,
                                                                                b => b.MigrationsAssembly(PluginAssembly().FullName)));
            }
            else
            {
                services.AddDbContext <CaseTemplatePnDbContext>(o => o.UseSqlServer(connectionString,
                                                                                    b => b.MigrationsAssembly(PluginAssembly().FullName)));
            }

            CaseTemplatePnContextFactory contextFactory = new CaseTemplatePnContextFactory();
            var context = contextFactory.CreateDbContext(new[] { connectionString });

            context.Database.Migrate();

            //Seed Database
            SeedDatabase(connectionString);
        }
        private CaseTemplatePnDbContext GetContext()
        {
            CaseTemplatePnContextFactory contextFactory = new CaseTemplatePnContextFactory();

            return(contextFactory.CreateDbContext(new[] { _connectionString }));
        }