Exemplo n.º 1
0
        protected override bool Process(IInteraction parameters)
        {
            bool success = true;
            // FileSystemInfo[] infos = rootDirectory.GetFileSystemInfos ("*", SearchOption.AllDirectories);

            IEnumerable <FileSystemInfo> infos = rootDirectory.EnumerateFileSystemInfos("*", SearchOption.AllDirectories);

            IEnumerator <FileSystemInfo> infoEnumerator = infos.GetEnumerator();

            while (infoEnumerator.MoveNext())
            {
                try {
                    FileSystemInfo info = infoEnumerator.Current;
                    if (info is FileInfo)
                    {
                        success &= FileFound.TryProcess(new FileInteraction(info, this.RootPath, parameters));
                    }
                    else if (info is DirectoryInfo)
                    {
                        success &= DirectoryFound.TryProcess(new DirectoryInteraction(info, this.RootPath, parameters));
                    }
                } catch (Exception ex) {
                    Secretary.Report(5, "Inclusion of new file failed; ", ex.Message);
                }
            }

            return(success);
        }
Exemplo n.º 2
0
 public void Search(string directory, string searchPattern)
 {
     foreach (var file in Directory.EnumerateFiles(directory, searchPattern))
     {
         FileFound?.Invoke(this, new FileFoundArgs(file));
     }
 }
Exemplo n.º 3
0
        protected override bool Process(IInteraction parameters)
        {
            string fullPath = "";
            bool   success  = true;

            while (Changes.Count > 0)
            {
                fullPath = Changes.Dequeue();

                if (Directory.Exists(fullPath))
                {
                    success &= DirectoryFound.TryProcess(new DirectoryInteraction(new DirectoryInfo(fullPath), RootPath, parameters));
                }
                else if (File.Exists(fullPath))
                {
                    success &= FileFound.TryProcess(new FileInteraction(new FileInfo(fullPath), RootPath, parameters));
                }
                else
                {
                    success &= Gone.TryProcess(new FSInteraction(new FileInfo(fullPath), RootPath, parameters));
                }
            }

            return(success);
        }
        public bool FindFileByName(string name, string currentPath)
        {
            var files = GetFiles(currentPath);

            if (files != null)
            {
                foreach (var file in files)
                {
                    if (file.Name.ToLower().Contains(name))
                    {
                        var folderContent = GetFolderContent(currentPath).ToList();
                        FileFound?.Invoke(folderContent.FindIndex(s => s.FullName.ToLower().Contains(name.ToLower())), currentPath, folderContent.Count);
                        return(true);
                    }
                }
            }

            var folders = GetFolders(currentPath);

            if (folders != null)
            {
                foreach (var folder in folders)
                {
                    var result = FindFileByName(name, folder.FullName);

                    if (result)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        static void AddRow(FileFound found)
        {
            var file = new FileInfo("pictures.xlsx");
            var newFile = !file.Exists;

            try
            {
                using (var package = newFile ? new ExcelPackage() : new ExcelPackage(file))
                {
                    // get the first worksheet in the workbook
                    if (package.Workbook.Worksheets.Count == 0)
                        package.Workbook.Worksheets.Add("Pics");

                    var worksheet = package.Workbook.Worksheets[1];

                    var start = int.Parse( Convert.ToString(worksheet.Cells[1, 1].Value ?? "2") );
                    worksheet.Cells[1, 1].Value = start + 1;

                    worksheet.Cells[start, 1].Value = found.Location;

                    if (newFile) package.SaveAs(file);
                    else package.Save();
                } // the using statement automatically calls Dispose() which closes the package.
            }
            catch (Exception e)
            {
                _logger.ErrorException("Could not add to excel sheet", e);
            }
        }
Exemplo n.º 6
0
        private void AddNewRow(FileFound file)
        {
            var row = new DataGridViewRow
            {
                Tag = file
            };

            foreach (DataGridViewColumn col in gridFiles.Columns)
            {
                switch (col.Name)
                {
                case "colSequence":
                    row.Cells.Add(GetCell(file.Sequence));
                    break;

                case "colFilePath":
                    row.Cells.Add(GetCell(file.Path));
                    break;

                case "colContent":
                    row.Cells.Add(GetCell(file.Content));
                    break;
                }
            }

            this.gridFiles.Rows.Add(row);
        }
Exemplo n.º 7
0
 private void _watcher_Created(FileSystemEventArgs e)
 {
     if (e.Name.ToUpper().StartsWith("QUERY_DATA"))
     {
         _log.Info("File found via file '" + e.ChangeType + "; importing.");
         Application.Current.Dispatcher.BeginInvoke(new Action(() => { FileFound?.Invoke(e.FullPath); }));
     }
 }
Exemplo n.º 8
0
        public void on_found_handler_arg_is_the_file_found_instance_passed_to_the_on_found_method()
        {
            FileFound handlerArg = null;

            ClassUnderTest.AddHandler(x => handlerArg = x);
            ClassUnderTest.OnFound(_ff);
            handlerArg.ShouldEqual(_ff);
        }
Exemplo n.º 9
0
 void OnFileFound(string filename)
 {
     Application.Current.Dispatcher.Invoke
     (
         () => FileFound?.Invoke(this, new ExplorerEventArgs {
         FileName = filename
     })
     );
 }
Exemplo n.º 10
0
        private void SearchFiles(string path, string searchValue, int searchId)
        {
            searchValue = searchValue.ToLower();

            // Search Files
            #region SearchFiles
            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                try
                {
                    // Get file Info
                    #region GetFileInfo
                    string fileName      = Path.GetFileNameWithoutExtension(file);
                    string filePath      = Path.GetFullPath(file);
                    string fileExtension = Path.GetExtension(file);
                    #endregion
                    FileCounter++;
                    if (fileName.ToLower().Contains(searchValue))
                    {
                        // Add Result to DB and Notify File Found
                        using (ResultLogic logic = new ResultLogic())
                        {
                            FileFoundCounter++;
                            logic.AddResult(fileName, filePath, searchId);
                            FileFound?.Invoke(this, new FileEventArgs(fileName, fileExtension, filePath));
                        }
                    }
                }
                #region Exceptions
                catch (PathTooLongException ex)
                {
                    UnreachableCounter++;
                    TotalErrorCounter++;
                }
                catch (Exception ex)
                {
                    UnhandledErrors++;
                    TotalErrorCounter++;
                    ErrorLog.Add(ex.Message);
                }
                #endregion
            }
            #endregion

            // Search Directories
            #region SearchDirectories
            string[] directories = Directory.GetDirectories(path);
            foreach (string d in directories)
            {
                try
                {
                    SearchFiles(d, searchValue, searchId);
                }
            }
Exemplo n.º 11
0
        protected virtual void OnFileFound(ContentFindedEventArgs e)
        {
            if (ReferenceEquals(e, null))
            {
                throw new ArgumentNullException();
            }

            FileFound?.Invoke(this, e);

            _searchStopped = e.StopSearch;
        }
Exemplo n.º 12
0
        IEnumerable <FileSystemInfo> GetFileSystemInfo(DirectoryInfo directoryInfo)
        {
            var allElements = directoryInfo.GetFileSystemInfos();

            foreach (var fileSystemInfo in allElements)
            {
                var itemFoundEventArgs    = new FileSystemInfoEventArgs(fileSystemInfo.FullName);
                var itemFilteredEventArgs = new FilteredFileSystemInfoEventArgs(fileSystemInfo.FullName);
                if (fileSystemInfo is FileInfo)
                {
                    FileFound?.Invoke(this, itemFoundEventArgs);
                    if (itemFoundEventArgs.StopSearch)
                    {
                        yield break;
                    }
                    if (_matchPredicate(fileSystemInfo) && !itemFoundEventArgs.Exclude)
                    {
                        FileFiltered?.Invoke(this, itemFilteredEventArgs);
                        if (itemFilteredEventArgs.StopSearch)
                        {
                            yield break;
                        }
                        if (!itemFilteredEventArgs.Exclude)
                        {
                            yield return(fileSystemInfo);
                        }
                    }
                }
                else if (fileSystemInfo is DirectoryInfo nextDirectory)
                {
                    DirectoryFound?.Invoke(this, itemFoundEventArgs);
                    if (itemFoundEventArgs.StopSearch)
                    {
                        yield break;
                    }
                    if (_matchPredicate(fileSystemInfo) && !itemFoundEventArgs.Exclude)
                    {
                        foreach (var nextFileSystemInfo in GetFileSystemInfo(nextDirectory))
                        {
                            yield return(nextFileSystemInfo);
                        }
                        DirectoryFiltered?.Invoke(this, itemFilteredEventArgs);
                        if (itemFilteredEventArgs.StopSearch)
                        {
                            yield break;
                        }
                        if (!itemFilteredEventArgs.Exclude)
                        {
                            yield return(fileSystemInfo);
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
 private void SearchDirectory(string directory, string searchPattern)
 {
     foreach (var file in Directory.EnumerateFiles(directory, searchPattern))
     {
         var args = new FileFoundArgs(file);
         FileFound?.Invoke(this, args);
         if (args.CancelRequested)
         {
             break;
         }
     }
 }
Exemplo n.º 14
0
 internal void SearchFilesInDirectory(string directory, string searchPattern)
 {
     foreach (var file in Directory.EnumerateFiles(directory, searchPattern))
     {
         PathDecomposition pathDecomp = new PathDecomposition(file, CurrentDirectory);
         pathDecomp.PuttingItTogether();
         var args = new FileFoundArgs(file);
         FileFound?.Invoke(this, args);
         //if (args.CancelRequested)
         //  break;
     }
 }
Exemplo n.º 15
0
        private void ProcessFoundEntry(FileSystemInfoBase systemInfoBase)
        {
            var isDirectory = systemInfoBase.Attributes.HasFlag(FileAttributes.Directory);

            if (isDirectory)
            {
                DirectoryFound?.Invoke(systemInfoBase, EventArgs.Empty);
            }
            else
            {
                FileFound?.Invoke(systemInfoBase, EventArgs.Empty);
            }
        }
Exemplo n.º 16
0
 private void FileSearch(string path)
 {
     foreach (string file in Directory.GetFiles(path))
     {
         if (!_subscription)
         {
             return;
         }
         FileFound?.Invoke(this, new FileArgs(file));
         Thread.Sleep(1000);
     }
     CatalogSearch(path);
 }
Exemplo n.º 17
0
 void _worker_DoWork(object sender, DoWorkEventArgs e)
 {
     foreach (var directory in GetPartiallyFlatDirectories(_searchPath, 4))
     {
         if (_worker.CancellationPending)
         {
             break;
         }
         foreach (var file in directory.GetFiles(_template, SearchOption.AllDirectories))
         {
             FileFound.Raise(file);
         }
     }
 }
Exemplo n.º 18
0
        private void ScanFile(string file)
        {
            try
            {
                if (CheckForValidHeader && !DicomFile.HasValidHeader(file))
                {
                    return;
                }

                var df = DicomFile.Open(file);

                FileFound?.Invoke(this, df, file);
            }
            catch
            {
                // ignore exceptions?
            }
        }
Exemplo n.º 19
0
        private void GetFiles(string path, string pattern, string searchKey) //searches the directories for targeted files
        {
            var File = new List <string>();

            try
            {
                if (searchTrigger)
                {
                    Console.WriteLine("search stopped, press any key to return.");
                    if (Console.KeyAvailable)
                    {
                        Console.ReadKey();
                    }
                    Console.ReadKey();
                    Console.Clear();
                    SearchHandler handler = new SearchHandler();
                    handler.Start();
                }

                //get all files directly within a certain directory and checking them for out search input
                // displaying matches in real time, and adding them to the list for transfer to database.
                File.AddRange(Directory.GetFiles(path, pattern, SearchOption.TopDirectoryOnly));

                foreach (var item in File)
                {
                    if (Path.GetFileNameWithoutExtension(item).ToLower().Contains(searchKey.ToLower()))
                    {
                        Counter++;
                        FileFound?.Invoke(this, new SearchResultEvent(item, Counter));
                    }
                }
                //

                //performing the same action on every directoy in our path
                foreach (var directory in Directory.GetDirectories(path))
                {
                    GetFiles(directory, pattern, searchKey);
                }
                //
            }
            catch (UnauthorizedAccessException) { }
            catch (PathTooLongException) { }
        }
Exemplo n.º 20
0
        private bool VisitFile(FileInfo fileInfo, FolderNode rootNode)
        {
            if (_searchIsStopped)
            {
                return(false);
            }

            var file         = Map(fileInfo, rootNode);
            var filterResult = _filterBy == null ? true : _filterBy.Invoke(file);

            if (filterResult)
            {
                var fEvent = new FileNodeFindEvent(file);
                FileFound?.Invoke(this, fEvent);

                ProcessEvent(rootNode, file, fEvent);
                return(fEvent.ShouldBeAdd);
            }

            return(false);
        }
Exemplo n.º 21
0
        private void TestFile(FileInfo file, FileQueryFilterList filters)
        {
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug("Testing file: " + file);
            }

            bool accept = true;

            foreach (var filter in filters)
            {
                if (abortSearch || accept == false)
                {
                    // No need to continue
                    break;
                }

                // Apply the filter
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug("Checking filter: " + filter.ToString());
                }
                accept = filter.Accept(file);
            }

            if (accept)
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug("File passed all filters: " + file);
                }
                Results.Add(file);
                FileFound?.Invoke(this, new FileFoundEventArgs()
                {
                    fileInfo = file
                });
            }
        }
Exemplo n.º 22
0
 protected virtual void OnFileFound(HyperFileCheckEventArgs e)
 {
     FileFound?.Invoke(this, e);
 }
Exemplo n.º 23
0
 protected override void beforeEach()
 {
     _ff = new FileFound("a.spark", "a", "");
 }
 private void OnFileFound(VisitArgs args)
 {
     FileFound.Run(this, args);
 }
Exemplo n.º 25
0
 protected virtual void OnFileFound(SystemVisitorEventArgs e) => FileFound?.Invoke(this, e);
Exemplo n.º 26
0
 public async Task <List <string> > Found([FromRoute] FileFound fileFound)
 {
     return(await _nodesService.FoundNode(fileFound.NodeId, SpisumNames.NodeTypes.File));
 }
 protected virtual void OnFileFound(ItemFoundInfoEventArgs e)
 {
     FileFound?.Invoke(this, e);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Executed when a file is found.
 /// </summary>
 /// <param name="file">The found file.</param>
 protected virtual void OnFileFound(string file)
 {
     FileFound?.Invoke(file);
 }
Exemplo n.º 29
0
        private FileSystemInfoCustomCollection <CustomFileItem> GetItemsRecursively(string directoryPath, FilterMask filterMask)
        {
            var directoryInfo = (CustomDirectoryInfo)customDirectoryInfoFactory.CreateInstance(directoryPath);

            var output = new FileSystemInfoCustomCollection <CustomFileItem>();

            if (isFirstFilteredFileFound && filterMask.HasFlag(FilterMask.FirstOnly))
            {
                return(output);
            }

            if (!filterMask.HasFlag(FilterMask.NoFolders))
            {
                DirectoryFound?.Invoke(this, new ItemFoundArgs {
                    Item = directoryInfo
                });
                if (filterMask.HasFlag(FilterMask.IgnoreFilterFunction) || FileFilterDelegate.Invoke(directoryInfo))
                {
                    FilteredDirectoryFound?.Invoke(this, new ItemFoundArgs {
                        Item = directoryInfo
                    });
                    output.Add(directoryInfo);
                    isFirstFilteredFileFound = true;
                    if (isFirstFilteredFileFound && filterMask.HasFlag(FilterMask.FirstOnly))
                    {
                        return(output);
                    }
                }
            }

            var files = directoryInfo.GetFiles();

            foreach (var file in files)
            {
                FileFound?.Invoke(this, new ItemFoundArgs {
                    Item = file
                });
                if (filterMask.HasFlag(FilterMask.IgnoreFilterFunction) || FileFilterDelegate.Invoke(file))
                {
                    FilteredFileFound?.Invoke(this, new ItemFoundArgs {
                        Item = file
                    });
                    output.Add(file);
                    isFirstFilteredFileFound = true;
                    if (isFirstFilteredFileFound && filterMask.HasFlag(FilterMask.FirstOnly))
                    {
                        return(output);
                    }
                }
            }

            var directories = directoryInfo.GetDirectories();

            foreach (var directory in directories)
            {
                var result = GetItemsRecursively(directory.FullName, filterMask);
                foreach (var item in result)
                {
                    output.Add(item);
                }
            }

            return(output);
        }
 protected virtual void OnRaiseFileFoundEvent(FileEventArgs fileEventArgs)
 {
     FileFound?.Invoke(this, fileEventArgs);
 }
Exemplo n.º 31
0
 protected virtual void OnFileFound(string fileName)
 {
     FileFound?.Invoke(this, fileName);
 }