static IServiceCollection ConfigureCompilerOptions(this IServiceCollection services, IConfiguration config) { // App Db Connection services.Configure <AppDbOptions>(opts => { opts.ConnectionString = config.GetByProxy(Config.Db.App.Connection); opts.DefaultTimeout = config.GetValue <int>(Config.Db.App.DefaultTimeout); }); // Clin Db Connection services.Configure <ClinDbOptions>(opts => { opts.ConnectionString = config.GetByProxy(Config.Db.Clin.Connection); opts.DefaultTimeout = config.GetValue <int>(Config.Db.Clin.DefaultTimeout); }); var extractor = new DatabaseExtractor(); var sp = services.BuildServiceProvider(); // SQL Compiler Options config.TryBind <CompilerOptions>(Config.Compiler.Section, out var compilerOptions); services.Configure <CompilerOptions>(opts => { opts.Alias = compilerOptions.Alias; opts.FieldPersonId = compilerOptions.FieldPersonId; opts.FieldEncounterId = compilerOptions.FieldEncounterId; opts.AppDb = extractor.ExtractDatabase(sp.GetService <IOptions <AppDbOptions> >().Value); opts.ClinDb = extractor.ExtractDatabase(sp.GetService <IOptions <ClinDbOptions> >().Value); }); return(services); }
static IServiceCollection ConfigureCompilerOptions(this IServiceCollection services, IConfiguration config) { // App Db Connection services.Configure <AppDbOptions>(opts => { opts.ConnectionString = config.GetByProxy(Config.Db.App.Connection); opts.DefaultTimeout = config.GetValue <int>(Config.Db.App.DefaultTimeout); }); // Clin Db Connection services.Configure <ClinDbOptions>(opts => { opts.ConnectionString = config.GetByProxy(Config.Db.Clin.Connection); opts.DefaultTimeout = config.GetValue <int>(Config.Db.Clin.DefaultTimeout); opts.Cohort.WithQueryStrategy(config.GetValue <string>(Config.Db.Clin.Cohort.QueryStrategy)); if (opts.Cohort.QueryStrategy == ClinDbOptions.ClinDbCohortOptions.QueryStrategyOptions.Parallel) { if (!config.TryGetValue <int>(Config.Db.Clin.Cohort.MaxParallelThreads, out var maxThreads)) { opts.Cohort.MaxParallelThreads = 5; } else { opts.Cohort.MaxParallelThreads = maxThreads; } if (opts.Cohort.MaxParallelThreads <= 0) { throw new LeafConfigurationException($"ClinDb Cohort MaxParallelThreads must be greater than zero, but is set to {maxThreads}"); } } }); var extractor = new DatabaseExtractor(); var sp = services.BuildServiceProvider(); // SQL Compiler Options config.TryBind <CompilerOptions>(Config.Compiler.Section, out var compilerOptions); services.Configure <CompilerOptions>(opts => { opts.Alias = compilerOptions.Alias; opts.FieldPersonId = compilerOptions.FieldPersonId; opts.FieldEncounterId = compilerOptions.FieldEncounterId; opts.AppDb = extractor.ExtractDatabase(sp.GetService <IOptions <AppDbOptions> >().Value); opts.ClinDb = extractor.ExtractDatabase(sp.GetService <IOptions <ClinDbOptions> >().Value); }); return(services); }
public void SetDatabaseReader(Project project) { if (project.DatabaseType == DatabaseTypes.SQLServer && databaseSchemaReader == null) { databaseSchemaReader = new SQLServerDatabaseExtractor(); conn = new System.Data.SqlClient.SqlConnection(connectionString); } else if (project.DatabaseType == DatabaseTypes.Access && databaseSchemaReader == null) { databaseSchemaReader = null; } else if (project.DatabaseType == DatabaseTypes.Oracle && databaseSchemaReader == null) { databaseSchemaReader = null; } else if (project.DatabaseType == DatabaseTypes.MySQL && databaseSchemaReader == null) { databaseSchemaReader = null; } }
public static void Main(string[] args) { var showHelp = false; string accessDbPath = null; bool update = false; bool generate = false; bool generateSearchDocuments = false; string searchIndex = null; bool view = false; string root = null; GeneratorConfig generatorConfig = new GeneratorConfig(); var options = new OptionSet { { "u|update=", "run data update from Database and generate outputs", u => { update = true; accessDbPath = u; } }, { "g|generate", "generate web pages from extracted data", g => generate = true }, { "c|cookiecontrol", "cookie consent control", c => generatorConfig.CookieConsentControl = true }, { "t|tag=", "google tag manager id", t => generatorConfig.GoogleTagMangerId = t }, { "v|view", "view the static web site", v => view = true }, { "r|root=", "the root path on which to run the generate and view processes", r => root = r }, { "s|search=", "the search index to generate index documents for", s => { generateSearchDocuments = true; searchIndex = s; } }, { "h|help", "show this message and exit", h => showHelp = h != null } }; try { options.Parse(args); } catch (OptionException ex) { Console.Write("JNCC.Micosite.SAC: "); Console.Write(ex.Message); Console.Write("Try `dotnet run -- -h` for more information"); } if (string.IsNullOrEmpty(root)) { root = Environment.CurrentDirectory; } Console.WriteLine("Root path set to {0}", root); if (showHelp) { ShowHelp(options); return; } if (update) { if (String.IsNullOrWhiteSpace(accessDbPath)) { Console.Write("-u | --update option must have a non blank value"); } else { DatabaseExtractor.ExtractData(accessDbPath, root); } } if (generate || generateSearchDocuments) { if (!String.IsNullOrEmpty(generatorConfig.GoogleTagMangerId)) { Console.WriteLine("Enabling google tag manager with ID {0}", generatorConfig.GoogleTagMangerId); } if (generatorConfig.CookieConsentControl) { Console.WriteLine("Enabling Cookie consent control"); } Generator.MakeSite(generatorConfig, root, generateSearchDocuments, searchIndex); } if (view) { Console.WriteLine("Starting Webserver:"); string webRoot = Path.Combine(root, "output/html"); CreateWebHostBuilder(args) .UseWebRoot(webRoot) .UseContentRoot(webRoot) .ConfigureLogging((hostingContext, logging) => { logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); logging.AddDebug(); }) .UseStartup <Startup>() .Build() .Run(); } }
public override bool Execute() { List <DBObjectType> dataToExtract = GetDataToExtractEnum(); List <DBObjectType> dataToGenerateOutput = GetDataToGenerateOutputEnum(); ExtractionType exType; if (this.extractiontype.ToLower() == "database") { exType = ExtractionType.Database; } else if (this.extractiontype == "script") { exType = ExtractionType.Script; } else { throw new Exception(String.Format("Invalid extraction type: {0}", this.extractiontype)); } Database db = null; List <BaseStatement> statementCol = null; if (exType == ExtractionType.Database) { if (String.IsNullOrEmpty(_DBExtractorClass)) { throw new Exception("For database extraction type, dbextractorclass is required"); } Type dbExtractorClass = Type.GetType(_DBExtractorClass); if (dbExtractorClass == null) { throw new Exception(String.Format("Couldn't create instance for type {0}", _DBExtractorClass)); } IDatabaseExtractor dbExtractor = (IDatabaseExtractor)Activator.CreateInstance(dbExtractorClass); DatabaseExtractor extractor = new DatabaseExtractor(); extractor.Extractor = dbExtractor; extractor.InputConnectionString = _InputConnectionString; db = extractor.Extract(dataToExtract); } else { if (String.IsNullOrEmpty(ScriptExtractorClass)) { throw new Exception("For script extraction type, scriptextractorclass is required"); } Type scriptExtractorClass = Type.GetType(ScriptExtractorClass); if (scriptExtractorClass == null) { throw new Exception(String.Format("Couldn't create instance for type {0}", scriptExtractorClass)); } IScriptExtractor scriptExtractor = (IScriptExtractor)Activator.CreateInstance(scriptExtractorClass); if (_InputFiles == null) { throw new Exception("InputFiles must be specified."); } foreach (ITaskItem file in _InputFiles) { scriptExtractor.InputFiles.Add(file.ItemSpec); } statementCol = scriptExtractor.Extract(dataToExtract); } Type outputGenClass = Type.GetType(_OutputGeneratorClass); if (outputGenClass == null) { throw new Exception(String.Format("Couldn't create instance for type {0}", _OutputGeneratorClass)); } IOutputGenerator gen = (IOutputGenerator)Activator.CreateInstance(outputGenClass); if (gen.ExpectedInputType == ExpectedInputType.StatementCollection) { if (statementCol == null) { DatabaseToStatementCollectionConverter conv = new DatabaseToStatementCollectionConverter(); statementCol = conv.Convert(db); } Type scriptOutputGenClass = Type.GetType(_ScriptOutputGeneratorClass); if (((IStatementCollectionOutputGenerator)gen).RequiresScriptOutputHandler) { if (scriptOutputGenClass == null) { throw new Exception(String.Format("Couldn't create instance for type {0}", _ScriptOutputGeneratorClass)); } IScriptOutputHandler scriptOutputGen = (IScriptOutputHandler)Activator.CreateInstance(scriptOutputGenClass); ((IStatementCollectionOutputGenerator)gen).ScriptOutputGen = scriptOutputGen; } if (String.IsNullOrEmpty(ScriptFileOutputGenerator)) { throw new Exception(String.Format("For output file type you must specify ScriptFileOutputGenerator")); } Type scriptFileOutputGeneratorType = Type.GetType(ScriptFileOutputGenerator); if (scriptFileOutputGeneratorType == null) { throw new Exception(String.Format("Couldn't create instance for type {0}", ScriptFileOutputGenerator)); } ((IStatementCollectionOutputGenerator)gen).ScriptFileOutputGenerator = (IScriptFileOutputGenerator)Activator.CreateInstance(scriptFileOutputGeneratorType); gen.OutputDir = OutputDir; ((IStatementCollectionOutputGenerator)gen).GenerateOutput(statementCol, dataToGenerateOutput); } else { StatementCollectionToDatabaseConverter conv = new StatementCollectionToDatabaseConverter(); db = conv.Convert(statementCol); gen.OutputDir = OutputDir; ((IDBSchemaOutputGenerator)gen).GenerateOutput(db, dataToGenerateOutput); } return(true); }
private void DoProcessAnalyze() { if (cbVersions.SelectedItem == null || !(cbVersions.SelectedItem is VersionObjectCounter version)) { return; } lblConfirmVersion.Text = $"Sélectionnez les objets à importer dans la version {version}"; progressBar1.Maximum = lstTypeObject.CheckedItems.Count + 1; progressBar1.Minimum = 0; // Charger le référentiel utile lblProgression.Text = $"Chargement du référentiel..."; progressBar1.Value = progressBar1.Minimum; using var vdbCnn = new DatabaseConnection(); var where = string.Join(", ", lstTypeObject.CheckedItems.Cast <TypeObject>().Select(x => x.TypeObjectId.ToString())); var lstObjects = vdbCnn.Query <Object>(Object.SQLSelect + $" AND typeObjectId IN ({where});", new { version.VersionId }); // charger des infos deppuis la base client lblProgression.Text = $"Analyse de la base client..."; ListViewItem itx; ListViewGroup grp; lstResume.Items.Clear(); lstChoice.Items.Clear(); int counter = 0; using var cnn = new DatabaseConnection(baseClient.BaseConnectionString); foreach (TypeObject typOb in lstTypeObject.CheckedItems) { lblProgression.Text = $"Analyse {typOb.TypeObjectPlurial.ToLower()}..."; progressBar1.PerformStep(); Application.DoEvents(); bool withColumn = typOb.TypeObjectNeedColumnDefinition; var lst = cnn.Query <ObjectToImport>(DatabaseExtractor.SQLImportObject(typOb.TypeObjectId), new { version.VersionId }); itx = new ListViewItem(typOb.TypeObjectPlurial); itx.SubItems.Add(lst.Count().Counter("Aucun objet", "Un seul objet trouvé", "{0} objets trouvés")); lstResume.Items.Add(itx); grp = new ListViewGroup(typOb.ToString()); lstChoice.Groups.Add(grp); foreach (ObjectToImport x in lst) { if (withColumn) { x.Columns = cnn.Query <ColumnDefinition>(DatabaseExtractor.SQLImportColumns(typOb.TypeObjectId), x).ToList(); } counter++; x.ReferencedObject = lstObjects.FirstOrDefault(o => x.IsMatch(o)); itx = new ListViewItem(x.ToString()) { Group = grp, Tag = x }; if (x.Status.IsChoice()) { itx.ForeColor = Color.Red; } itx.SubItems.Add(x.Status.Libelle()); lstChoice.Items.Add(itx); } } lblProgression.Text = "Fin d'analyse"; lstResume.Items.Add(string.Empty); itx = new ListViewItem("Total") { Font = new Font(lstResume.Font, FontStyle.Bold) }; itx.SubItems.Add(counter.Counter("Aucun objet", "Un seul objet trouvé", "{0} objets trouvés")); lstResume.Items.Add(itx); lstResume.Columns[1].Width = -1; lstResume.Columns[0].Width = Math.Max(lstResume.ClientSize.Width - lstResume.Columns[1].Width - 20, 100); lstChoice.Columns[1].Width = -1; lstChoice.Columns[0].Width = Math.Max(lstChoice.ClientSize.Width - lstChoice.Columns[1].Width - 20, 100); EnableButtons(); }