Exemple #1
0
        /// <summary>
        /// Fill the stash with all files that has one of the given file patterns under the given directory folder.
        /// Example: <br />
        /// @code
        ///     var patterns = new List<string>() { "*.T01", "*.T02", "*.T03" };
        ///     Stash stash = new Stash();
        ///     stash.FillStash("C:\tax_files", patterns, Stash.FillStachMode.APPEND);
        /// @endcode
        /// </summary>
        /// <param name="scriptsFolder">The scripts files location.</param>
        /// <param name="patterns">Scripts file patterns list (e.g. '*.vbs', '*.sql', ...).</param>
        /// <param name="mode" cref="FillStachMode">APPEND - adds only new files to stash. REFRESH - adds all files to stash (existing files are reloaded from disk).</param>
        public void FillStash(string scriptsFolder, List <string> patterns, FillStachMode mode)
        {
            if ((scriptsFolder == null) || (scriptsFolder.Equals(string.Empty)))
            {
                throw new ArgumentException("Stash.FillStash operation has failed. Scripts folder missing.", "scriptsFolder");
            }

            if ((patterns == null) || (patterns.Count == 0))
            {
                throw new ArgumentException("Stash.FillStash operation has failed. Patterns missing.", "patterns");
            }

            foreach (string pattern in patterns)
            {
                this.FillStash(scriptsFolder, pattern, mode);
            }
        }
Exemple #2
0
        /// <summary>
        /// Fill the stash with all files that has given pattern, found under one of the given directories list.
        /// Duplicate file names will be ignored. In such case, only first file is loaded on APPEND mode, and only last file is loaded on REFRESH mode.
        /// Example: <br />
        /// @code
        ///     var folders = new List<string>() { "C:\tax_files1", "C:\tax_files2" };
        ///     Stash stash = new Stash();
        ///     stash.FillStash(folders, "*.T??", Stash.FillStachMode.APPEND);
        /// @endcode
        /// </summary>
        /// <param name="scriptsFolders">The scripts files locations list.</param>
        /// <param name="pattern">The scripts files pattern (e.g. '*.sql').</param>
        /// <param name="mode" cref="FillStachMode">APPEND - adds only new files to stash. REFRESH - adds all files to stash (existing files are reloaded from disk).</param>
        public void FillStash(List <string> scriptsFolders, string pattern, FillStachMode mode)
        {
            if ((scriptsFolders == null) || (scriptsFolders.Count == 0))
            {
                throw new ArgumentException("Stash.FillStash operation has failed. Scripts folder missing.", "scriptsFolders");
            }

            if ((pattern == null) || (pattern.Equals(string.Empty)))
            {
                throw new ArgumentException("Stash.FillStash operation has failed. Pattern missing.", "pattern");
            }

            foreach (string folder in scriptsFolders)
            {
                this.FillStash(folder, pattern, mode);
            }
        }
Exemple #3
0
        /// <summary>
        /// Fill the stash with all files from fixed file pattern (e.g. '*.sql') that can be found under given directory folder. <br />
        /// Example: <br />
        /// @code
        ///     Stash stash = new Stash();
        ///     stash.FillStash("C:\sql_scripts", "*.sql", Stash.FillStachMode.APPEND);
        /// @endcode
        /// </summary>
        /// <param name="scriptsFolder">The scripts files location.</param>
        /// <param name="pattern">The scripts files pattern (e.g. '*.vbs').</param>
        /// <param name="mode" cref="FillStachMode">APPEND - adds only new files to stash. REFRESH - adds all files to stash (existing files are reloaded from disk).</param>
        public void FillStash(string scriptsFolder, string pattern, FillStachMode mode)
        {
            if ((scriptsFolder == null) || (scriptsFolder.Equals(string.Empty)))
            {
                throw new ArgumentException("Stash.FillStash operation has failed. Scripts folder missing.", "scriptsFolder");
            }

            if ((pattern == null) || (pattern.Equals(string.Empty)))
            {
                throw new ArgumentException("Stash.FillStash operation has failed. Pattern missing.", "pattern");
            }

            try
            {
                string[]      filePaths    = Directory.GetFiles(scriptsFolder, pattern, SearchOption.AllDirectories);
                List <string> fileNameKeys = null;

                if (filePaths.Length > 0)
                {
                    fileNameKeys = filePaths.Select(name => Path.GetFileName(name)).ToList();
                }

                foreach (var fileLoc in filePaths)
                {
                    string fileNameKey = Path.GetFileName(fileLoc);

                    switch (mode)
                    {
                    case FillStachMode.APPEND:
                        if (_scripts.ContainsKey(fileNameKey) == false)
                        {
                            _scripts.Add(fileNameKey, new Script(fileLoc, ref _tokens));
                        }
                        break;

                    case FillStachMode.REFRESH:
                        if (_scripts.ContainsKey(fileNameKey) == true)
                        {
                            _scripts[fileNameKey].Reload(Path.GetDirectoryName(fileLoc));
                        }
                        else
                        {
                            _scripts.Add(fileNameKey, new Script(fileLoc, ref _tokens));
                        }
                        break;

                    default:
                        break;
                    }
                }

                // check for removed files no longer at scripts-folder location (only on refresh mode).
                if ((mode == FillStachMode.REFRESH) && (fileNameKeys != null))
                {
                    foreach (var scriptName in _scripts.Keys)
                    {
                        if (fileNameKeys.Contains(scriptName) == false)
                        {
                            _scripts.Remove(scriptName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Fill ScriptStash failed. Using folder location : '{scriptsFolder}', and pattern file : '{pattern}'. Fill mode set to '{mode.ToString()}'.", ex);
            }
        }