Exemple #1
0
        public void GetSubFolders_ForEmptyFolder_ReturnsThisFolder()
        {
            List <FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(1));
            Assert.That(subfolders[0].FullPath, Is.EqualTo(Path.GetFullPath(Folder)));
        }
        private void ParseFileSystem()
        {
            //Don't set any restrictions on this parsing, as want to grab the entire system.
            List <FileSystemItem> fileSystemItems = _fileSystemParser.GetSubFolders();

            _fileSystem = new FileSystemCache(fileSystemItems, DateTime.Now);
        }
        public void GetSubFolders_FileCreatedWhileOperation_FileNotIncludedInOutput()
        {
            DirectoryUtility.EnsureClearFolder(SubFolder);
            _parser = new FileSystemParserWithAction(new FileSystemListener(), () => File.WriteAllText(SubFolder + "\\temp.txt", "text"));
            _parser.FoldersToParse = new List<string> { Folder };

            List<FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(2));
        }
Exemple #4
0
        public void GetSubFolders_FolderMadeHiddenWhileOperation_FolderIsNotAdded()
        {
            Directory.CreateDirectory(SubFolder);
            _parser = new FileSystemParserWithAction(new FileSystemListener(), MakeSubFolderHidden);
            _parser.FoldersToParse = new List <string> {
                Folder
            };

            List <FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(2));
        }
Exemple #5
0
        public void GetSubFolders_FolderCreatedWhileOperation_FolderIncludedInOutput()
        {
            _parser = new FileSystemParserWithAction(new FileSystemListener(), () => Directory.CreateDirectory(SubFolder));
            _parser.FoldersToParse = new List <string> {
                Folder
            };

            List <FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(2));
            Assert.That(subfolders[1].FullPath, Is.EqualTo(Path.GetFullPath(SubFolder)));
        }
Exemple #6
0
        public void GetSubFolders_FileCreatedWhileOperation_FileNotIncludedInOutput()
        {
            DirectoryUtility.EnsureClearFolder(SubFolder);
            _parser = new FileSystemParserWithAction(new FileSystemListener(), () => File.WriteAllText(SubFolder + "\\temp.txt", "text"));
            _parser.FoldersToParse = new List <string> {
                Folder
            };

            List <FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(2));
        }
        public List <MatchedFileSystemItem> GetFolderMatches(string searchText)
        {
            if (string.IsNullOrEmpty(searchText))
            {
                return(new List <MatchedFileSystemItem>());
            }

            List <FileSystemItem>        folders        = _fileSystemParser.GetSubFolders();
            List <MatchedFileSystemItem> matchedFolders = _matchSearcher.GetMatches(folders, searchText);

            return(matchedFolders);
        }
        public void GetSubFolders_FileMadeHiddenWhileOperation_FileNotIncludedInOutput()
        {
            DirectoryUtility.EnsureClearFolder(SubFolder);
            File.WriteAllText(SubFolder + "\\temp.txt", "text");
            _parser = new FileSystemParserWithAction(new FileSystemListener(),
                                                     () =>
                                                         {
                                                             FileInfo fileInfo = new FileInfo(SubFolder + "\\temp.txt");
                                                             fileInfo.Attributes = fileInfo.Attributes | FileAttributes.Hidden;
                                                         });
            _parser.FoldersToParse = new List<string> { Folder };

            List<FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(2));
        }
Exemple #9
0
        public void GetSubFolders_FileMadeHiddenWhileOperation_FileNotIncludedInOutput()
        {
            DirectoryUtility.EnsureClearFolder(SubFolder);
            File.WriteAllText(SubFolder + "\\temp.txt", "text");
            _parser = new FileSystemParserWithAction(new FileSystemListener(),
                                                     () =>
            {
                FileInfo fileInfo   = new FileInfo(SubFolder + "\\temp.txt");
                fileInfo.Attributes = fileInfo.Attributes | FileAttributes.Hidden;
            });
            _parser.FoldersToParse = new List <string> {
                Folder
            };

            List <FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(2));
        }
Exemple #10
0
        private List <FileSystemItem> ReadCache(bool appRunOnStartup, out bool fullCacheUpToDate, out bool cacheFolderCreated, out DateTime lastFullScanTime)
        {
            cacheFolderCreated = false;

            //Parse file system
            FileSystemCache fullCache = _cacheSerializer.DeserializeCache();

            if (fullCache != null)
            {
                //The cache file can be up to date only if the current Navigation Assistant has been run on startup
                //and if it had been closed just on system shutdown and the current parser is created at application start.
                //In this case no additional folders can be created during NavAssistant being inactive.
                fullCacheUpToDate = CacheUpToDate(fullCache) && appRunOnStartup;
            }
            else
            {
                //The application is loaded for the first time (no cache stored on disk).
                string cacheFolder        = GetCacheFolder();
                bool   cacheFolderExisted = Directory.Exists(cacheFolder);

                //Run this method in the main thread, thus freezing it.
                //Don't set any restrictions on this parsing, as want to grab the entire system.
                fullCache = new FileSystemCache(_fileSystemParser.GetSubFolders(), DateTime.Now);
                _cacheSerializer.SerializeCache(fullCache);

                //Updating the cache if cache folder has been created
                bool cacheFolderExists = Directory.Exists(cacheFolder);
                cacheFolderCreated = !cacheFolderExisted && cacheFolderExists;

                fullCacheUpToDate = true;
            }

            List <FileSystemItem> filteredCache = FilterCache(fullCache);

            lastFullScanTime = fullCache.LastFullScanTime;
            fullCache        = null;
            GC.Collect();

            return(filteredCache);
        }
        public void GetSubFolders_FolderDeletedWhileOperation_FolderDeletedInOutput()
        {
            Directory.CreateDirectory(SubFolder);

            _parser = new FileSystemParserWithAction(new FileSystemListener(), () => Directory.Delete(SubFolder, true));
            _parser.FoldersToParse = new List<string> { Folder };

            List<FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(1));
            Assert.That(subfolders[0].FullPath, Is.EqualTo(Path.GetFullPath(Folder)));
        }
        public void GetSubFolders_FolderMadeVisibleWhileOperation_FolderIsNotAdded()
        {
            Directory.CreateDirectory(SubFolder);
            MakeSubFolderHidden();

            _parser = new FileSystemParserWithAction(new FileSystemListener(), MakeSubFolderVisible);
            _parser.FoldersToParse = new List<string> { Folder };

            List<FileSystemItem> subfolders = _parser.GetSubFolders();

            Assert.That(subfolders.Count, Is.EqualTo(2));
        }