public void DirectoryTree_NotFoundFiles()
 {
     DirectoryTree tree = new DirectoryTree(baseDirName, "fi444444le*");
     List<String> files = new List<string>();
     tree.OnFoundFile += x => files.Add(x.Name);
     tree.run();
     Assert.IsTrue(files.Count == 0);
 }
 public void DirectoryTree_TestWithFileSearch()
 {
     DirectoryTree tree = new DirectoryTree(baseDirName, "file*");
     List<String> files = new List<string>();
     tree.OnFoundFile +=
         file => {
             var ff = File.OpenRead(file.FullName);
             if (FileSearch.searchInFile(ff, Encoding.UTF8.GetBytes("словоо")))
                 files.Add(file.Name);
         };
     tree.run();
     Assert.IsFalse(files.TrueForAll(x => x != file1Name));
     Assert.IsFalse(files.TrueForAll(x => x != file4Name));
     Assert.IsTrue(files.TrueForAll(x => x != file2Name));
     Assert.IsTrue(files.TrueForAll(x => x != file3Name));
 }
 public void DirectoryTree_Test2()
 {
     DirectoryTree tree = new DirectoryTree(baseDirName, "file*");
     List<String> files = new List<string>();
     tree.OnFoundFile += x => files.Add(x.Name);
     tree.run();
     Assert.IsTrue(!files.TrueForAll(x => x != file1Name));
     Assert.IsTrue(!files.TrueForAll(x => x != file2Name));
     Assert.IsTrue(!files.TrueForAll(x => x != file3Name));
     Assert.IsTrue(!files.TrueForAll(x => x != file4Name));
 }
 public void DirectoryTree_Test1()
 {
     DirectoryTree tree = new DirectoryTree(baseDirName, "file*");
     tree.run();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Search function
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="fileTemplate"></param>
        /// <param name="fileText"></param>
        private void runSearch(string folderName, string fileTemplate, string fileText)
        {
            var fileTextB = Encoding.UTF8.GetBytes(fileText);

            DirectoryTree tree = new DirectoryTree(folderName, fileTemplate);
            tree.OnFoundFile +=
                file => {
                    try
                    {
                        using (var ff = File.OpenRead(file.FullName))
                        {
                            // Show processing file
                            /*
                            BeginInvoke(new Action<string>
                                    ((text) => LabelFileProcessing.Text = text)
                                , file.FullName);
                            */
                            processingFileName = file.FullName;
                            // Search fileText in file
                            if (FileSearch.searchInFile(ff, fileTextB))
                            {
                                // Add file to tree
                                // BeginInvoke(new Action<FileInfo>(addFileToTree), file);
                                addFileToTree(file);
                            }
                            // Hide processing file
                            // processingFileName = "--";
                        }
                    }
                    catch (UnauthorizedAccessException e)
                    { }
                    catch (IOException e)
                    { }
                };
            tree.run();

            stopTimer();

            // Change LabelFileProcessing to "Done"
            BeginInvoke(new Action<string>
                    ((text) => LabelFileProcessing.Text = text)
                , "Done");

            MessageBox.Show("Поиск завершен");
        }