public void TestWildcardWithDataSuite2()
        {
            Wildcard wildcard = new Wildcard("*");

            Assert.IsTrue(wildcard.CheckStringForMatch("AB"));
            Assert.IsTrue(wildcard.CheckStringForMatch("<>"));
            Assert.IsTrue(wildcard.CheckStringForMatch(";!"));
            Assert.IsTrue(wildcard.CheckStringForMatch(""));
            Assert.IsTrue(wildcard.CheckStringForMatch(Guid.NewGuid().ToString("N")));
            Assert.IsTrue(wildcard.CheckStringForMatch("kesmfou~!@#$%^&*()_+"));
        }
        public void TestWildcardWithDataSuite3()
        {
            Wildcard wildcard = new Wildcard("*.*");

            Assert.IsTrue(wildcard.CheckStringForMatch("A.B"));
            Assert.IsTrue(wildcard.CheckStringForMatch("<>.!!"));
            Assert.IsTrue(wildcard.CheckStringForMatch("readme.txt"));
            Assert.IsTrue(wildcard.CheckStringForMatch("io.sys"));

            Assert.IsFalse(wildcard.CheckStringForMatch(Guid.NewGuid().ToString("N")));
            Assert.IsFalse(wildcard.CheckStringForMatch("kesmfou~!@#$%^&*()_+"));
        }
        public void TestWildcardWithDataSuite1()
        {
            Wildcard wildcard = new Wildcard("??");

            Assert.IsTrue(wildcard.CheckStringForMatch("AB"));
            Assert.IsTrue(wildcard.CheckStringForMatch("<>"));
            Assert.IsTrue(wildcard.CheckStringForMatch(";!"));

            Assert.IsFalse(wildcard.CheckStringForMatch("ABC"));
            Assert.IsFalse(wildcard.CheckStringForMatch("A"));
            Assert.IsFalse(wildcard.CheckStringForMatch("&&?"));

            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>(
                delegate
            {
                wildcard.CheckStringForMatch(null);
            });
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="folderToSearchIn"></param>
        /// <returns></returns>
        /// <exception cref="FolderNotFoundException"></exception>
        /// <exception cref="InvalidPathException"></exception>
        /// <exception cref="ObjectDisposedException"></exception>
        private FileInfo SearchFileInFolderRecursively(FolderInfo folderToSearchIn)
        {
            try
            {
                RefreshCurrentFolder(folderToSearchIn);

                if (!_idsOfFilesAndFoldersSeenSoFar.Contains(folderToSearchIn.Id))
                {
                    foreach (FileInfo fileInfo in _filesOfCurrentFolder)
                    {
                        if (!_idsOfFilesAndFoldersSeenSoFar.Contains(fileInfo.Id))
                        {
                            _idsOfFilesAndFoldersSeenSoFar.Add(fileInfo.Id);

                            if (_wildcardForMatchingNamesOfFiles.CheckStringForMatch(fileInfo.Name))
                            {
                                return(fileInfo);
                            }
                        }
                    }

                    foreach (FolderInfo folder in _subfoldersOfCurrentFolder)
                    {
                        if (!_idsOfFilesAndFoldersSeenSoFar.Contains(folder.Id))
                        {
                            FileInfo fileFromFolder = SearchFileInFolderRecursively(folder);

                            if (fileFromFolder != null)
                            {
                                return(fileFromFolder);
                            }
                        }
                    }

                    _idsOfFilesAndFoldersSeenSoFar.Add(folderToSearchIn.Id);

                    // пошли к parent-y
                    if (_folderToEnumerateFilesIn.Id != folderToSearchIn.Id)
                    {
                        try
                        {
                            FolderInfo parent = _filesAndFoldersProvider.GetParentOf(folderToSearchIn.FullPath);

                            FileInfo fileFromFolder = this.SearchFileInFolderRecursively(parent);

                            if (fileFromFolder != null)
                            {
                                return(fileFromFolder);
                            }
                        }
                        catch (InvalidPathException)
                        {
                            return(null);
                        }
                        catch (CannotResolvePathException)
                        {
                            throw new InvalidPathException();
                        }
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                this.Dispose();
                throw new ObjectDisposedException("Продолжение перебора файлов невозможно: файловая система уже была принудительно закрыта (путем вызова метода Dispose()).");
            }
            catch (FolderNotFoundException)
            {
                _enumeratedStructureHasChanged = true;
                throw CreateEnumerationNotPossibleException();
            }
            catch (InvalidPathException)
            {
                _enumeratedStructureHasChanged = true;
                throw CreateEnumerationNotPossibleException();
            }

            return(null);
        }