Beispiel #1
0
 public WatcherExEventArgs(FileSystemWatcherEx watcher,
                           object arguments,
                           ArgumentType argType)
 {
     Watcher   = watcher;
     Arguments = arguments;
     ArgType   = argType;
     Filter    = NotifyFilters.Attributes;
 }
Beispiel #2
0
 public WatcherExEventArgs(FileSystemWatcherEx watcher,
                           object arguments,
                           ArgumentType argType,
                           NotifyFilters filter)
 {
     Watcher   = watcher;
     Arguments = arguments;
     ArgType   = argType;
     Filter    = filter;
 }
Beispiel #3
0
        //--------------------------------------------------------------------------------
        /// <summary>
        /// Actually creates the necessary FileSystemWatcher objects, depending oin which
        /// notify filters and change types the user specified.
        /// </summary>
        /// <param name="changeType"></param>
        /// <param name="filter"></param>
        private void CreateWatcher(bool changedWatcher, NotifyFilters filter)
        {
            lock (thisLock)
            {
                Debug.WriteLine(string.Format("WatcherEx.CreateWatcher({0}, {1})", changedWatcher.ToString(), filter.ToString()));

                FileSystemWatcherEx watcher = null;
                int bufferSize = (int)this.watcherInfo.BufferKBytes * 1024;
                // Each "Change" filter gets its own watcher so we can determine *what*
                // actually changed. This will allow us to react only to the change events
                // that we actually want.  The reason I do this is because some programs
                // fire TWO events for  certain changes. For example, Notepad sends two
                // events when a file is created. One for CreationTime, and one for
                // Attributes.
                if (changedWatcher)
                {
                    // if we're not handling the currently specified filter, get out
                    if (HandleNotifyFilter(filter))
                    {
                        watcher = new FileSystemWatcherEx(this.watcherInfo.WatchPath, this.watcherInfo.MonitorPathInterval);
                        watcher.IncludeSubdirectories = this.watcherInfo.IncludeSubFolders;
                        watcher.Filter             = this.watcherInfo.FileFilter;
                        watcher.NotifyFilter       = filter;
                        watcher.InternalBufferSize = bufferSize;
                        switch (filter)
                        {
                        case NotifyFilters.Attributes:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedAttribute);
                            break;

                        case NotifyFilters.CreationTime:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedCreationTime);
                            break;

                        case NotifyFilters.DirectoryName:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedDirectoryName);
                            break;

                        case NotifyFilters.FileName:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedFileName);
                            break;

                        case NotifyFilters.LastAccess:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedLastAccess);
                            break;

                        case NotifyFilters.LastWrite:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedLastWrite);
                            break;

                        case NotifyFilters.Security:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedSecurity);
                            break;

                        case NotifyFilters.Size:
                            watcher.Changed += new FileSystemEventHandler(watcher_ChangedSize);
                            break;
                        }
                    }
                }
                // All other FileSystemWatcher events are handled through a single "main"
                // watcher.
                else
                {
                    if (HandleWatchesFilter(WatcherChangeTypes.Created) ||
                        HandleWatchesFilter(WatcherChangeTypes.Deleted) ||
                        HandleWatchesFilter(WatcherChangeTypes.Renamed) ||
                        this.watcherInfo.WatchForError ||
                        this.watcherInfo.WatchForDisposed)
                    {
                        watcher = new FileSystemWatcherEx(this.watcherInfo.WatchPath, this.watcherInfo.MonitorPathInterval);
                        watcher.IncludeSubdirectories = this.watcherInfo.IncludeSubFolders;
                        watcher.Filter             = this.watcherInfo.FileFilter;
                        watcher.InternalBufferSize = bufferSize;
                    }

                    if (HandleWatchesFilter(WatcherChangeTypes.Created))
                    {
                        watcher.Created += new FileSystemEventHandler(watcher_CreatedDeleted);
                    }
                    if (HandleWatchesFilter(WatcherChangeTypes.Deleted))
                    {
                        watcher.Deleted += new FileSystemEventHandler(watcher_CreatedDeleted);
                    }
                    if (HandleWatchesFilter(WatcherChangeTypes.Renamed))
                    {
                        watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
                    }
                    if (watcherInfo.MonitorPathInterval > 0)
                    {
                        watcher.EventPathAvailability += new PathAvailabilityHandler(watcher_EventPathAvailability);
                    }
                }
                if (watcher != null)
                {
                    if (this.watcherInfo.WatchForError)
                    {
                        watcher.Error += new ErrorEventHandler(watcher_Error);
                    }
                    if (this.watcherInfo.WatchForDisposed)
                    {
                        watcher.Disposed += new EventHandler(watcher_Disposed);
                    }
                    WatcherEx.watchers.Add(watcher);
                }
            }
        }