예제 #1
0
        /// <summary>
        /// Inserts or merges the embedded YAML data.
        /// </summary>
        private async Task <bool> InsertOrMergeYamlDataAsync()
        {
            // Get all the database table schema information.
            Logger.Default.Info($"Querying database for all existing table and column configurations...");
            await SqlDataUpdater.RegisterDatabaseAsync(_db, "Ref").ConfigureAwait(false);

            // Parse all resources and get ready for the SQL code gen.
            Logger.Default.Info($"Probing for embedded resources: {(string.Join(", ", GetNamespacesWithSuffix($"{DataNamespace}.*.yaml")))}");
            foreach (var ass in _assemblies)
            {
                foreach (var name in ass.GetManifestResourceNames())
                {
                    if (!_namespaces.Any(x => name.StartsWith(x + $".{DataNamespace}.", StringComparison.InvariantCulture) && name.EndsWith(".yaml", StringComparison.InvariantCulture)))
                    {
                        continue;
                    }

                    Logger.Default.Info($"Parsing and executing: {name}");
                    var sdm = SqlDataUpdater.ReadYaml(ass.GetManifestResourceStream(name) !);
                    await sdm.GenerateSqlAsync(async (a) =>
                    {
                        Logger.Default.Info($"Executing: {a.OutputFileName} ->");
                        Logger.Default.Info(a.Content);
                        if (a.Content != null)
                        {
                            await _db.SqlStatement(a.Content).NonQueryAsync().ConfigureAwait(false);
                        }
                    }).ConfigureAwait(false);
                }
            }

            return(true);
        }