Example #1
0
        internal FileSystemEnumerableIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler)
        {
            this.oldMode     = Win32Native.SetErrorMode(1);
            this.searchStack = new List <Directory.SearchData>();
            string str = FileSystemEnumerableIterator <TSource> .NormalizeSearchPattern(searchPattern);

            if (str.Length == 0)
            {
                this.empty = true;
            }
            else
            {
                this._resultHandler = resultHandler;
                this.searchOption   = searchOption;
                this.fullPath       = Path.GetFullPathInternal(path);
                string fullSearchString = FileSystemEnumerableIterator <TSource> .GetFullSearchString(this.fullPath, str);

                this.normalizedSearchPath = Path.GetDirectoryName(fullSearchString);
                string[] pathList = new string[] { Directory.GetDemandDir(this.fullPath, true), Directory.GetDemandDir(this.normalizedSearchPath, true) };
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, pathList, false, false).Demand();
                this.searchCriteria = FileSystemEnumerableIterator <TSource> .GetNormalizedSearchCriteria(fullSearchString, this.normalizedSearchPath);

                string directoryName = Path.GetDirectoryName(str);
                string str4          = originalUserPath;
                if ((directoryName != null) && (directoryName.Length != 0))
                {
                    str4 = Path.Combine(str4, directoryName);
                }
                this.userPath   = str4;
                this.searchData = new Directory.SearchData(this.normalizedSearchPath, this.userPath, searchOption);
                this.CommonInit();
            }
        }
        internal FileSystemEnumerableIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler, bool checkHost)
        {
            this.oldMode     = Win32Native.SetErrorMode(1);
            this.searchStack = new List <Directory.SearchData>();
            string text = FileSystemEnumerableIterator <TSource> .NormalizeSearchPattern(searchPattern);

            if (text.Length == 0)
            {
                this.empty = true;
                return;
            }
            this._resultHandler = resultHandler;
            this.searchOption   = searchOption;
            this.fullPath       = Path.GetFullPathInternal(path);
            string fullSearchString = FileSystemEnumerableIterator <TSource> .GetFullSearchString(this.fullPath, text);

            this.normalizedSearchPath = Path.GetDirectoryName(fullSearchString);
            if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
            {
                FileIOPermission.EmulateFileIOPermissionChecks(this.fullPath);
                FileIOPermission.EmulateFileIOPermissionChecks(this.normalizedSearchPath);
            }
            else
            {
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[]
                {
                    Directory.GetDemandDir(this.fullPath, true),
                    Directory.GetDemandDir(this.normalizedSearchPath, true)
                }, false, false).Demand();
            }
            this._checkHost     = checkHost;
            this.searchCriteria = FileSystemEnumerableIterator <TSource> .GetNormalizedSearchCriteria(fullSearchString, this.normalizedSearchPath);

            string directoryName = Path.GetDirectoryName(text);
            string path2         = originalUserPath;

            if (directoryName != null && directoryName.Length != 0)
            {
                path2 = Path.CombineNoChecks(path2, directoryName);
            }
            this.userPath   = path2;
            this.searchData = new Directory.SearchData(this.normalizedSearchPath, this.userPath, searchOption);
            this.CommonInit();
        }