예제 #1
0
 public void AddSearchFolder(ResolveFileMode mode, string folder)
 {
     if (!_additionalSearchFolders.ContainsKey(mode))
     {
         _additionalSearchFolders[mode] = new List <string>();
     }
     _additionalSearchFolders[mode].Add(folder);
 }
예제 #2
0
        private string SearchExistingFile(string file, ResolveFileMode mode, params string[] folders)
        {
            foreach (string folder in folders)
            {
                if (folder == null)
                {
                    continue;
                }
                string fn = Path.Combine(folder, file);
                if (System.IO.File.Exists(fn))
                {
                    return(fn);
                }
            }
            var additionalFoldersCtx = this;

            while (additionalFoldersCtx != null)
            {
                if (additionalFoldersCtx._additionalSearchFolders.ContainsKey(mode))
                {
                    foreach (string folder in additionalFoldersCtx._additionalSearchFolders[mode])
                    {
                        string fn = Path.Combine(folder, file);
                        if (System.IO.File.Exists(fn))
                        {
                            return(fn);
                        }
                    }
                }
                additionalFoldersCtx = additionalFoldersCtx._parent;
            }
            if (System.IO.File.Exists(file))
            {
                return(file);
            }

            var allFolders = new List <string>(folders);

            if (_additionalSearchFolders.ContainsKey(mode))
            {
                allFolders.AddRange(_additionalSearchFolders[mode]);
            }
            throw new Exception(String.Format("DBSH-00063 Could not find file {0}, searched in folders {1}", file, allFolders.CreateDelimitedText(";")));
        }
예제 #3
0
        public string ResolveFile(string file, ResolveFileMode mode)
        {
            switch (mode)
            {
            case ResolveFileMode.DbShell:
                return(SearchExistingFile(file, mode, GetExecutingFolder()));

            case ResolveFileMode.Template:
                return(SearchExistingFile(file, mode, GetTemplatesFolder(), GetExecutingFolder()));

            case ResolveFileMode.Input:
                return(SearchExistingFile(file, mode, GetExecutingFolder()));

            case ResolveFileMode.Output:
                var outputFolder = GetDefaultOutputFolder();
                if (outputFolder != null)
                {
                    return(Path.Combine(outputFolder, file));
                }
                return(file);
            }
            return(file);
        }
예제 #4
0
 public void AddSearchFolder(ResolveFileMode mode, string folder)
 {
     if (!_additionalSearchFolders.ContainsKey(mode))
     {
         _additionalSearchFolders[mode] = new List<string>();
     }
     _additionalSearchFolders[mode].Add(folder);
 }
예제 #5
0
 public string ResolveFile(string file, ResolveFileMode mode)
 {
     switch (mode)
     {
         case ResolveFileMode.DbShell:
             return SearchExistingFile(file, mode, GetExecutingFolder());
         case ResolveFileMode.Template:
             return SearchExistingFile(file, mode, GetTemplatesFolder(), GetExecutingFolder());
         case ResolveFileMode.Input:
             return SearchExistingFile(file, mode, GetExecutingFolder());
         case ResolveFileMode.Output:
             var outputFolder = GetDefaultOutputFolder();
             if (outputFolder != null) return Path.Combine(outputFolder, file);
             return file;
     }
     return file;
 }
예제 #6
0
        private string SearchExistingFile(string file, ResolveFileMode mode, params string[] folders)
        {
            foreach (string folder in folders)
            {
                if (folder == null) continue;
                string fn = Path.Combine(folder, file);
                if (System.IO.File.Exists(fn)) return fn;
            }
            var additionalFoldersCtx = this;
            while (additionalFoldersCtx != null)
            {
                if (additionalFoldersCtx._additionalSearchFolders.ContainsKey(mode))
                {
                    foreach (string folder in additionalFoldersCtx._additionalSearchFolders[mode])
                    {
                        string fn = Path.Combine(folder, file);
                        if (System.IO.File.Exists(fn)) return fn;
                    }
                }
                additionalFoldersCtx = additionalFoldersCtx._parent;
            }
            if (System.IO.File.Exists(file)) return file;

            var allFolders = new List<string>(folders);
            if (_additionalSearchFolders.ContainsKey(mode))
            {
                allFolders.AddRange(_additionalSearchFolders[mode]);
            }
            throw new Exception(String.Format("DBSH-00063 Could not find file {0}, searched in folders {1}", file, allFolders.CreateDelimitedText(";")));
        }