示例#1
0
        /// <summary>
        ///     Creates a search path for given pattern and variable.
        /// </summary>
        /// <remarks>
        ///     Sample for pattern:
        ///     <![CDATA[
        /// "<Namespace>/<Package>/<Task>.sql"
        /// "<Package>/<Task>.sql",
        /// "<Namespace>/<Task>.sql"
        /// "<Task>.sql"
        /// "<ProjectParam:Variant>/<Package>/<Task>.sql"
        /// ]]>
        /// </remarks>
        /// <returns>Absolute path to sql file.</returns>
        private string BuildSearchPath(string pattern, VariableContext context)
        {
            Trace.TraceInformation("BuildSearchPath - BEGIN");

            pattern = pattern.Replace("<Namespace>", context.Variable.Namespace);
            pattern = pattern.Replace("<Package>", context.Package.Name);
            pattern = pattern.Replace("<Task>", context.TaskHost.Name);
            foreach (var param in context.ProjectParams)
            {
                pattern = pattern.Replace($"<ProjectParam:{param.Name}>", param.Value);
            }

            var path = Path.Combine(_config.Settings.SqlRootDirectory, pattern);

            Trace.TraceInformation("BuildSearchPath - END");
            return(new FileInfo(path).FullName);
        }
示例#2
0
        /// <summary>
        ///     Searches for mapping sql file for variable.
        /// </summary>
        /// <param name="sqlScripts">Found sql file.</param>
        /// <param name="context">Context of variable.</param>
        /// <returns>
        ///     Path to sql file or null.
        /// </returns>
        private string SearchSqlScriptPath(Dictionary <string, string> sqlScripts, VariableContext context)
        {
            Trace.TraceInformation("SearchSqlScriptPath - BEGIN");

            foreach (var pattern in _config.Settings.SqlMappingPatterns)
            {
                var searchPath = BuildSearchPath(pattern, context);
                foreach (var scriptPath in sqlScripts.Keys)
                {
                    if (string.Equals(scriptPath, searchPath, StringComparison.CurrentCultureIgnoreCase))
                    {
                        _log.Debug(
                            $"SQL Datei {scriptPath} für Variable '{context.Variable.Namespace}::{context.Variable.Name}' über Pattern {pattern} gefunden.");
                        return(scriptPath);
                    }
                }
            }

            Trace.TraceInformation("SearchSqlScriptPath - END");
            return(null);
        }