Ejemplo n.º 1
0
        /// <summary>
        /// Inserts or merges the embedded YAML data.
        /// </summary>
        private bool InsertOrMergeYamlData()
        {
            // Get all the database table schema information.
            Logger.Default.Info($"Querying database for all existing table and column configurations...");
            SqlDataUpdater.RegisterDatabase(_db, "Ref");

            // 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));
                    sdm.GenerateSql((a) =>
                    {
                        Logger.Default.Info($"Executing: {a.OutputFileName} ->");
                        Logger.Default.Info(a.Content);
                        _db.SqlStatement(a.Content).NonQuery();
                    });
                }
            }

            return(true);
        }