Example #1
0
 protected virtual void OnNewItemArrived(FileSystemInfoEventArgs fileSystemInfoEventArgs)
 {
     if (NewItemArrived != null)
     {
         NewItemArrived(this, fileSystemInfoEventArgs);
     }
 }
Example #2
0
 // Invoked when new scanner has new item
 public void OnNewItemArrived(object sender, FileSystemInfoEventArgs e)
 {
     if (e != null && e.Item != null)
     {
         _processingQueue.Enqueue(e.Item);
     }
 }
Example #3
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);
                        }
                    }
                }
            }
        }
Example #4
0
        private void NotifyNewItemArrived(FileSystemInfo fileSystemInfo)
        {
            if (fileSystemInfo == null)
            {
                return;
            }

            FileSystemInfoEventArgs fileSystemInfoEventArgs = new FileSystemInfoEventArgs();

            fileSystemInfoEventArgs.Item = fileSystemInfo;

            OnNewItemArrived(fileSystemInfoEventArgs);
        }
        /// <summary>
        /// Identicate what should be done with current file system item.
        /// </summary>
        /// <typeparam name="T">FileSystemInfo type.</typeparam>
        /// <param name="fileSystemInfoItem">File System Info object that needs to be validated.</param>
        /// <param name="filter">Filter Delegate.</param>
        /// <param name="itemFound">Event on File System Item Finded.</param>
        /// <param name="itemFiltered">Event on File System Item Filtered.</param>
        /// <returns>Action that needs to be performed.</returns>
        private bool Validate <T>(T fileSystemInfoItem,
                                  Func <T, bool> filter,
                                  EventHandler <FileSystemInfoEventArgs <T> > itemFound,
                                  EventHandler <FileSystemInfoEventArgs <T> > itemFiltered) where T : FileSystemInfo
        {
            FileSystemInfoEventArgs <T> eventArgs = new FileSystemInfoEventArgs <T>(fileSystemInfoItem, false);

            OnItemFindedEvent(itemFound, eventArgs);

            if (filter == null || eventArgs.Skip)
            {
                return(eventArgs.Skip);
            }

            if (filter(fileSystemInfoItem))
            {
                eventArgs = new FileSystemInfoEventArgs <T>(fileSystemInfoItem, false);
                OnItemFindedEvent(itemFiltered, eventArgs);
                return(eventArgs.Skip);
            }

            return(false);
        }
        protected virtual void OnFilteredItemFindedEvent <T>(EventHandler <FileSystemInfoEventArgs <T> > eventHandler, FileSystemInfoEventArgs <T> eventArgs) where T : FileSystemInfo
        {
            var x = eventHandler;

            if (x != null)
            {
                x(this, eventArgs);
            }
        }