public virtual void InitializeDatabase() { var scriptReplacements = new Dictionary <string, string>() { { "pref", _connectionSettings.Schema } }; var scriptInitializer = new ScriptInitializer(typeof(InstallScripts), scriptReplacements); scriptInitializer.ScriptManager.ThrowOnUnknownScriptTypes = false; using (SenderDbContext context = GetDbContext()) { var creator = (RelationalDatabaseCreator)context.Database.GetService <IDatabaseCreator>(); bool dbExists = creator.Exists(); if (dbExists) { bool tableExists = CheckTableExists(context); if (tableExists == false) { ScriptExtractor.ExtractFromDbContext(context); scriptInitializer.ExecuteScripts(context); } } else { context.Database.EnsureCreated(); scriptInitializer.ExecuteScripts(context); } } }
public async Task Initialize() { try { var isScript = await IsScript(); if (isScript) { var scriptInitializer = new ScriptInitializer(_code, _options); _assembly = await scriptInitializer.CreateAssembly(_options.CustomAssemblyLoadContext); } else { var regularInitializer = new RegularInitializer(_code, _options); _assembly = await regularInitializer.CreateAssembly(_options.CustomAssemblyLoadContext); } var options = new AssemblyPluginCatalogOptions { PluginNameOptions = _options.PluginNameOptions }; _catalog = new AssemblyPluginCatalog(_assembly, options); await _catalog.Initialize(); IsInitialized = true; } catch (Exception e) { throw new InvalidCodeException($"Failed to initialize catalog with code: {Environment.NewLine}{_code}", e); } }
public void then_it_executes_scripts_from_resources() { var strategy = new ScriptInitializer(typeof(ScriptsRes)); using (var context = new TestInitializerDbContext()) { strategy.InitializeDatabase(context); } }
public static async Task <List <Type> > CompileScript(string code, RoslynPluginCatalogOptions options = null) { var catalog = new ScriptInitializer(code, options); var assembly = await catalog.CreateAssembly(); var result = assembly.GetTypes().Where(x => x.GetCustomAttribute(typeof(CompilerGeneratedAttribute), true) == null).ToList(); return(result); }
public void then_it_executes_scripts_from_files() { var scriptsDirectory = new DirectoryInfo("Resources/Scripts"); var strategy = new ScriptInitializer(scriptsDirectory); using (var context = new TestInitializerDbContext()) { strategy.InitializeDatabase(context); } }
public void then_it_executes_scripts_from_resources() { AppDomain.CurrentDomain.SetData("DataDirectory", Directory.GetCurrentDirectory()); var strategy = new ScriptInitializer <TestInitializerDbContext>(typeof(ScriptRes)); System.Data.Entity.Database.SetInitializer <TestInitializerDbContext>(strategy); using (var context = new TestInitializerDbContext()) { context.Database.Initialize(force: true); } }
public async Task Initialize() { try { var isScript = await IsScript(); if (isScript) { var scriptInitializer = new ScriptInitializer(_code, _options); _assembly = await scriptInitializer.CreateAssembly(); } else { var regularInitializer = new RegularInitializer(_code, _options); _assembly = await regularInitializer.CreateAssembly(); } var assemblyCatalogOptions = new AssemblyPluginCatalogOptions { PluginNameOptions = _options.PluginNameOptions }; if (_options.Tags?.Any() == true) { assemblyCatalogOptions.TypeFinderOptions = new TypeFinderOptions() { TypeFinderCriterias = new List <TypeFinderCriteria>() { new TypeFinderCriteria() { Query = (context, type) => true, Tags = _options.Tags } } }; } _catalog = new AssemblyPluginCatalog(_assembly, assemblyCatalogOptions); await _catalog.Initialize(); IsInitialized = true; } catch (Exception e) { throw new InvalidCodeException($"Failed to initialize catalog with code: {Environment.NewLine}{_code}", e); } }