public MainWindow() { InitializeComponent(); data = new DataModeler(); //cityStats = new Statistics("Canadacities-JSON.json", "json"); }
public void CreateSource() { var Source = DataModeler.CreateSource("MyTestDatabase"); Assert.Empty(Source.Functions); Assert.Equal("MyTestDatabase", Source.Name); Assert.Empty(Source.StoredProcedures); Assert.Empty(Source.Tables); Assert.Empty(Source.Views); }
/// <summary> /// Initializes a new instance of the <see cref="DataModel"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="config">The configuration.</param> /// <param name="logger">The logger.</param> /// <param name="dataModeler">The data modeler.</param> /// <param name="sherlock">The sherlock.</param> /// <param name="batch">The batch.</param> /// <exception cref="ArgumentNullException">source or config or logger</exception> public DataModel(IMappingSource source, IConfiguration config, ILogger logger, DataModeler dataModeler, Sherlock sherlock, SQLHelper batch) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (source is null) { throw new ArgumentNullException(nameof(source)); } logger ??= Log.Logger ?? new LoggerConfiguration().CreateLogger() ?? throw new ArgumentNullException(nameof(logger)); var sourceConnection = new Connection(config, source.Source.Provider, source.Source.Name); var sourceSpec = DataModeler.CreateSource(sourceConnection.DatabaseName ?? string.Empty); SourceSpec = sourceSpec; GeneratedSchemaChanges = Task.Run(async() => await GenerateSchemaAsync(source, logger, dataModeler, sourceConnection, sourceSpec).ConfigureAwait(false)).GetAwaiter().GetResult(); Task.Run(async() => await AnalyzeSchemaAsync(sherlock, logger, source, sourceConnection, batch).ConfigureAwait(false)).GetAwaiter().GetResult(); }
/// <summary> /// Initializes a new instance of the <see cref="SchemaManager"/> class. /// </summary> /// <param name="mappings">The mappings.</param> /// <param name="config">The configuration.</param> /// <param name="logger">The logger.</param> /// <param name="dataModeler">The data modeler.</param> /// <param name="sherlock">The sherlock analyzer.</param> /// <param name="sQLHelper">The s ql helper.</param> /// <exception cref="ArgumentNullException">logger</exception> public SchemaManager(MappingManager mappings, IConfiguration config, ILogger logger, DataModeler dataModeler, Sherlock sherlock, SQLHelper sQLHelper) { Models = mappings.Sources.ToList(x => new DataModel(x, config, logger !, dataModeler, sherlock, sQLHelper)); }
/// <summary> /// Generates the schema. /// </summary> /// <param name="source">The source.</param> /// <param name="logger">The logger.</param> /// <param name="dataModeler">The data modeler.</param> /// <param name="sourceConnection">The source connection.</param> /// <param name="sourceSpec">The source spec.</param> /// <returns>The generated schema changes.</returns> private static async Task <string[]> GenerateSchemaAsync(IMappingSource source, ILogger logger, DataModeler dataModeler, IConnection sourceConnection, ISource sourceSpec) { if (!source.UpdateSchema && !source.GenerateSchema) { return(Array.Empty <string>()); } var Debug = logger.IsEnabled(LogEventLevel.Debug); var Generator = dataModeler.GetSchemaGenerator(source.Source.Provider); if (Generator is null) { return(Array.Empty <string>()); } logger.Information("Getting structure for {Info:l}", sourceConnection.DatabaseName); var OriginalSource = !string.IsNullOrEmpty(sourceConnection.DatabaseName) ? (await Generator.GetSourceStructureAsync(sourceConnection).ConfigureAwait(false)) : null; SetupTableStructures(logger, sourceConnection, source, sourceSpec); logger.Information("Generating schema changes for {Info:l}", sourceConnection.DatabaseName); var GeneratedSchemaChanges = Generator.GenerateSchema(sourceSpec, OriginalSource !) ?? Array.Empty <string>(); if (Debug) { logger.Debug("Schema changes generated: {GeneratedSchemaChanges}", GeneratedSchemaChanges); } if (!source.UpdateSchema) { return(GeneratedSchemaChanges); } logger.Information("Applying schema changes for {Info:l}", sourceConnection.DatabaseName); await Generator.SetupAsync(GeneratedSchemaChanges, sourceConnection).ConfigureAwait(false); return(GeneratedSchemaChanges); }