Exemplo n.º 1
0
 void OnChange(string filename, FileSystemEvent @event)
 {
     if (Change != null)
     {
         Change(filename, @event);
     }
 }
Exemplo n.º 2
0
 private void PostponeEventDelivery(FileSystemEvent fileEvent)
 {
     if (!postponedEvents.ContainsKey(fileEvent.Filename))
     {
         postponedEvents.Add(fileEvent.Filename, fileEvent);
     }
 }
        public void OnEvent(FileSystemEvent e)
        {
            var path = e.Path;

            switch (e.ChangeType)
            {
            case ChangeType.Created:
                _createEventHandler.Handle(path);
                break;

            case ChangeType.Changed:
                _changeEventHandler.Handle(path);
                break;

            case ChangeType.Deleted:
                _deleteEventHandler.Handle(path);
                break;

            case ChangeType.Rename:
                _renameEventHandler.Handle(e.OldPath, path);
                break;

            case ChangeType.Log:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 4
0
 public FileSystemEventData(
     AbsoluteFilePath file,
     FileSystemEvent evt,
     Optional <AbsoluteFilePath> oldFile = default(Optional <AbsoluteFilePath>))
 {
     File    = file;
     Event   = evt;
     OldFile = oldFile;
 }
Exemplo n.º 5
0
        private void FireEvent(string path)
        {
            FileSystemEvent evt = this.Change;

            if (evt != null)
            {
                evt(path);
            }
        }
Exemplo n.º 6
0
        void OnFSeventClose(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            this.callbackCount++;

            if (this.callbackCount == 3)
            {
                fsEvent.CloseHandle(this.OnClose);
            }
        }
Exemplo n.º 7
0
 private void FlushPostponedEvents(FileSystemEvent fileEvent)
 {
     if (postponedEvents.ContainsKey(fileEvent.Filename))
     {
         var postponedEvent = postponedEvents[fileEvent.Filename];
         postponedEvents.Remove(fileEvent.Filename);
         DeliverEvent(postponedEvent, false);
     }
 }
Exemplo n.º 8
0
        private bool EventShouldBeIgnored(FileSystemEvent fileEvent)
        {
            if (fileEvent is RenameOrMoveEvent)
            {
                return(fileEvent.Filename.StartsWith(RECYCLE_BIN_PREFIX, StringComparison.CurrentCultureIgnoreCase));
            }

            return(false);
        }
Exemplo n.º 9
0
        void OnFSEventFile(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            if (fileSystemEvent.EventType == FSEventType.Change)
            {
                this.callbackCount++;
            }

            fsEvent.Stop();
            fsEvent.CloseHandle(this.OnClose);
        }
Exemplo n.º 10
0
        void OnFSEventDirectory(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            if (fileSystemEvent.EventType == FSEventType.Rename)
            {
                this.callbackCount++;
            }

            fsEvent.Stop();
            fsEvent.CloseHandle(this.OnClose);
        }
Exemplo n.º 11
0
        private void FireEvent(string path)
        {
            Console.WriteLine("Change detected at: {0}", path);
            FileSystemEvent evt = Change;

            if (evt != null)
            {
                evt(path);
            }
        }
Exemplo n.º 12
0
        private static FileSystemEvent CreateFileSystemEvent(LogRecord record, string[] strings)
        {
            var fileSystemEvent = new FileSystemEvent()
            {
                Filename  = PathConverter.ReplaceDevicePath(strings[0]),
                ProcessId = record.Data.ProcessId,
                Type      = record.Data.EventType
            };

            return(fileSystemEvent);
        }
Exemplo n.º 13
0
        void OnFSEventFileCurrentDir(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            if (this.callbackCount == 0 &&
                fileSystemEvent.EventType == FSEventType.Change &&
                !string.IsNullOrEmpty(fileSystemEvent.FileName))
            {
                this.callbackCount++;
            }

            this.loop.CreateTimer()
            .Start(this.OnTimerClose, 250, 0);
        }
Exemplo n.º 14
0
        private void FireChangedEvent(FileSystemObserverKey key)
        {
            FileSystemEvent evt = ChangedEvent;

            if (evt != null)
            {
                // make sure the path still exist before throwing an event
                if (PathExists(key.FullPath) && CheckIfWeWantToFireThisEvent(key.FullPath))
                {
                    // okay you can fire the Changed event now
                    evt(key.FullPath);
                }
            }
        }
Exemplo n.º 15
0
 private void HandleFileEvent(FileSystemEvent fileEvent)
 {
     if (fileEvent.Type == EventType.Close)
     {
         FlushPostponedEvents(fileEvent);
     }
     else if (CanBePostponed(fileEvent) && AggregateEvents)
     {
         PostponeEventDelivery(fileEvent);
     }
     else if (!EventShouldBeIgnored(fileEvent))
     {
         DeliverEvent(fileEvent, AggregateEvents);
     }
 }
Exemplo n.º 16
0
        void OnFSEventDirMultipleFile(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            this.callbackCount++;

            if (this.fileCreated + this.fileRemoved == FileEventCount)
            {
                // Once we've processed all create events, delete all files
                this.timer.Start(this.OnTimerDeleteFile, 1, 0);
            }
            else if (this.callbackCount == 2 * FileEventCount)
            {
                // Once we've processed all create and delete events, stop watching
                this.timer.CloseHandle(this.OnClose);
                fsEvent.CloseHandle(this.OnClose);
            }
        }
        public void Work(FileSystemEvent e)
        {
            _inner.Work(e);
            if (e.EventArgs.FullPath.Contains(".svn"))
            {
                return;
            }

            _logger.DebugFormat("Work completed for {0}.", e.EventArgs.Name);

            if (_nextTaskSource != null)
            {
                _nextTaskSource.SetResult(e);
                _nextTaskSource = null;
            }
        }
Exemplo n.º 18
0
        private void FireDeletedEvent(FileSystemObserverKey key)
        {
            FileSystemEvent evt = DeletedEvent;

            if (evt != null)
            {
                // if the Path still exist on the fileSystem then it wasn't deleted
                // this can happen during the saving file process.
                // Don't thrown this event unless the path doesn't exist
                if (!PathExists(key.FullPath) && CheckIfWeWantToFireThisEvent(key.FullPath))
                {
                    // remove the path from existing paths
                    _existingPaths.Remove(key.FullPath);

                    // okay you can fire the Deleted event now
                    evt(key.FullPath);
                }
            }
        }
Exemplo n.º 19
0
        private void FireCreatedEvent(FileSystemObserverKey key)
        {
            FileSystemEvent evt = CreatedEvent;

            if (evt != null)
            {
                // check if the path still exist before firing this created event. this should filter out some temp files
                if (PathExists(key.FullPath) && CheckIfWeWantToFireThisEvent(key.FullPath))
                {
                    // check if path already exist. Can't create a path that already exist.
                    if (!_existingPaths.Contains(key.FullPath))
                    {
                        // need to add this to the existing paths list
                        _existingPaths.Add(key.FullPath);

                        // okay you can fire the Created event now
                        evt(key.FullPath);
                    }
                }
            }
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            EventLooper looper = new EventLooper(null);

            FileSystemEvent fsEvent = new FileSystemEvent(
                null,
                looper,
                null
                );

            fsEvent.Start(
                @"F:\",
                FileSystemEventFlags.WatchEntry,
                (name, eventType) =>
            {
                Console.WriteLine(name);
                Console.WriteLine(eventType);
            }
                );
            looper.Run();
        }
Exemplo n.º 21
0
        private void DeliverEvent(FileSystemEvent fileEvent, bool postponeDelivery)
        {
            switch (fileEvent.Type)
            {
            case EventType.Change:
                OnChange?.Invoke(fileEvent.Filename, fileEvent.ProcessId);
                break;

            case EventType.Create:
                OnCreate?.Invoke(fileEvent.Filename, fileEvent.ProcessId);
                break;

            case EventType.Delete:
                OnDelete?.Invoke(fileEvent.Filename, fileEvent.ProcessId);
                break;

            case EventType.Move:
                OnRenameOrMove?.Invoke(fileEvent.Filename, ((RenameOrMoveEvent)fileEvent).OldFilename, fileEvent.ProcessId);
                break;

            default:
                break;
            }
        }
 void HandleFileSystemDeleted(FileSystemEvent fileEvent)
 {
     RemoveHash(fileEvent.Path);
 }
Exemplo n.º 23
0
 void HandleFileSystemDeleted(FileSystemEvent fileEvent)
 {
     RemoveHash(fileEvent.Path);
 }
Exemplo n.º 24
0
 void OnFSEvent(FSEvent fsEvent, FileSystemEvent fileSystemEvent) => this.callbackCount++;
Exemplo n.º 25
0
 private bool CanBePostponed(FileSystemEvent fileEvent)
 {
     return(fileEvent.Type == EventType.Change || fileEvent.Type == EventType.Create);
 }
Exemplo n.º 26
0
 void HandleFileSystemChangedAndCreated(FileSystemEvent fileEvent)
 {
     HandleHash(fileEvent.Path, GenerateHashForFile(fileEvent.Path));
 }
Exemplo n.º 27
0
 public void Add(FileSystemEvent e) => _eventQueue.Enqueue(e);
Exemplo n.º 28
0
        void FireEvent(string path)
        {
            FileSystemEvent evt = Change;

            evt(path);
        }
 void HandleFileSystemChangedAndCreated(FileSystemEvent fileEvent)
 {
     HandleHash(fileEvent.Path, GenerateHashForFile(fileEvent.Path));
 }