void OnAppDataChanged(object sender, FSEventStreamEventsArgs e)
 {
     foreach (var evnt in e.Events)
     {
         numDataChanged++;
         String message = numDataChanged + " " + evnt;
         System.Diagnostics.Debug.WriteLine(evnt);
         FileSystemWatcherObject o = new FileSystemWatcherObject(evnt.Path.Replace(path + "/", ""), evnt.Path, (evnt.Flags.HasFlag(FSEventStreamEventFlags.ItemIsDir) ? TargetType.Folder : TargetType.File));
         if (evnt.Flags.HasFlag(FSEventStreamEventFlags.ItemRenamed))
         {
             Event?.Invoke(FileSystemWatcherEventArgs.CreateRenamedEvent(o));
         }
         else if (evnt.Flags.HasFlag(FSEventStreamEventFlags.ItemCreated))
         {
             Event?.Invoke(FileSystemWatcherEventArgs.CreateCreatedEvent(o));
         }
         else if (evnt.Flags.HasFlag(FSEventStreamEventFlags.ItemRemoved))
         {
             Event?.Invoke(FileSystemWatcherEventArgs.CreateDeletedEvent(o));
         }
         else if (evnt.Flags.HasFlag(FSEventStreamEventFlags.ItemModified))
         {
             Event?.Invoke(FileSystemWatcherEventArgs.CreateChangedEvent(o));
         }
     }
 }
Beispiel #2
0
        void eventStream_Events(object sender, FSEventStreamEventsArgs args)
        {
            var interestingFlags = new FSEventStreamEventFlags[]
            {
                FSEventStreamEventFlags.ItemCreated,
                FSEventStreamEventFlags.ItemModified,
                FSEventStreamEventFlags.ItemRemoved,
                FSEventStreamEventFlags.ItemRenamed
            };

            var interestingEvents = args.Events
                                    .Where(e => interestingFlags.Any(f => e.Flags.HasFlag(f)))
                                    .Where(e => IsHead(e.Path))
                                    .ToArray();

            foreach (var ev in interestingEvents)
            {
                if (ev.Flags.HasFlag(FSEventStreamEventFlags.ItemCreated))
                {
                    Task.Run(() => Task.Delay(DetectionToAlertDelayMilliseconds)).ContinueWith(t => EatRepo(ev.Path));
                }
                else if (ev.Flags.HasFlag(FSEventStreamEventFlags.ItemModified))
                {
                    EatRepo(ev.Path);
                }
                else if (ev.Flags.HasFlag(FSEventStreamEventFlags.ItemRemoved))
                {
                    NotifyHeadDeletion(ev.Path);
                }
                else if (ev.Flags.HasFlag(FSEventStreamEventFlags.ItemRenamed))
                {
                    NotifyHeadDeletion(ev.Path);
                }
            }
        }
Beispiel #3
0
 private void handleEvents(object sender, FSEventStreamEventsArgs args)
 {
     foreach (var e in args.Events)
     {
         if ((e.Flags & FSEventStreamEventFlags.ItemModified) != 0)
         {
             if (Filter?.Invoke(e.Path) ?? true)
             {
                 Changed?.Invoke(e.Path);
             }
         }
         if ((e.Flags & FSEventStreamEventFlags.ItemCreated) != 0)
         {
             if (Filter?.Invoke(e.Path) ?? true)
             {
                 Changed?.Invoke(e.Path);
             }
         }
         if ((e.Flags & FSEventStreamEventFlags.ItemRemoved) != 0)
         {
             if (Filter?.Invoke(e.Path) ?? true)
             {
                 Changed?.Invoke(e.Path);
             }
         }
         if ((e.Flags & FSEventStreamEventFlags.ItemRenamed) != 0)
         {
             if (Filter?.Invoke(e.Path) ?? true)
             {
                 Changed?.Invoke(e.Path);
             }
         }
     }
 }
Beispiel #4
0
        private void OnFSEventStreamEvents(object sender, FSEventStreamEventsArgs e)
        {
            foreach (MonoMac.CoreServices.FSEvent fsEvent in e.Events)
            {
                bool isFile = (fsEvent.Flags & FSEventStreamEventFlags.ItemIsFile) != 0;
                Console.WriteLine(fsEvent.Path + " " + (FileOrDirectoryExists(fsEvent.Path, isFile) ? "exists" : "") + " " + fsEvent.Flags.ToString());
                if ((fsEvent.Flags & FSEventStreamEventFlags.ItemRemoved) != 0 && !FileOrDirectoryExists(fsEvent.Path, isFile))
                {
                    this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Deleted, fsEvent.Path, !isFile));
                    continue;
                }

                if ((fsEvent.Flags & FSEventStreamEventFlags.ItemCreated) != 0 && FileOrDirectoryExists(fsEvent.Path, isFile))
                {
                    this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Created, fsEvent.Path, !isFile));
                }

                if (((fsEvent.Flags & FSEventStreamEventFlags.ItemModified) != 0 ||
                     (fsEvent.Flags & FSEventStreamEventFlags.ItemInodeMetaMod) != 0) &&
                    FileOrDirectoryExists(fsEvent.Path, isFile))
                {
                    this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Changed, fsEvent.Path, !isFile));
                }

                if ((fsEvent.Flags & FSEventStreamEventFlags.ItemRenamed) != 0)
                {
                    if (FileOrDirectoryExists(fsEvent.Path, isFile))
                    {
                        if (this.LastRenameEvent != null && this.LastRenameEvent.Value.Id == fsEvent.Id - 1)
                        {
                            this.Queue.AddEvent(new CmisSync.Lib.Events.FSMovedEvent(this.LastRenameEvent.Value.Path, fsEvent.Path, !isFile));
                            this.LastRenameEvent = null;
                        }
                        else
                        {
                            this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Created, fsEvent.Path, !isFile));
                        }
                    }
                    else
                    {
                        this.CleanLastRenameEvent();
                        this.LastRenameEvent = fsEvent;
                        continue;
                    }
                }

                this.CleanLastRenameEvent();
            }
        }
        private void OnFSEventStreamEvents(object sender, FSEventStreamEventsArgs e)
        {
            _eventStream.Stop();

            System.Diagnostics.Debug.WriteLine("Received an event");
            foreach (var ev in e.Events)
            {
                System.Diagnostics.Debug.WriteLine(ev.Flags);
                System.Diagnostics.Debug.WriteLine(ev.Path);
            }

            var t = new EventArgs();

            Events?.Invoke(this, t);

            _eventStream.Start();
        }
        public void SetExclusionPathsTest()
        {
            var watchDirPath   = Path.Combine(dirPath, "WatchDir");
            var watchDir       = Directory.CreateDirectory(watchDirPath);
            var unWatchDirPath = Path.Combine(dirPath, "UnwatchDir");
            var unWatchDir     = Directory.CreateDirectory(unWatchDirPath);

            // Passing empty array returns a false
            Assert.IsFalse(fsEventStream.SetExclusionPaths(new string [] { }), "SetExclusionPaths empty array failed");

            // Excluding the unWatchDirPath from the watcher so any event inside it doesn't get
            var exclusionPaths = new string [] { Path.Combine(fsEventStream.PathsBeingWatched [0], "UnwatchDir"), Path.Combine(fsEventStream.PathsBeingWatched [0], "UnwatchDir") };

            Assert.IsTrue(fsEventStream.SetExclusionPaths(exclusionPaths), "SetExclusionPaths failed");

            Assert.True(true);
            FileStream fileToWatch   = File.Create(Path.Combine(watchDirPath, "TempFileToWatch.txt"));
            FileStream fileToExclude = File.Create(Path.Combine(unWatchDirPath, "TempFileToExclude.txt"));

            fileToWatch.Close();
            fileToExclude.Close();

            var taskCompletionSource     = new TaskCompletionSource <FSEventStreamEventsArgs> ();
            FSEventStreamEventsArgs args = null;

            TestRuntime.RunAsync(TimeSpan.FromSeconds(30), async() => {
                fsEventStream.Events += (sender, eventArgs) => {
                    taskCompletionSource.SetResult(eventArgs);
                };

                fsEventStream.ScheduleWithRunLoop(CFRunLoop.Current);
                fsEventStreamStarted = fsEventStream.Start();
                File.AppendAllText(Path.Combine(unWatchDirPath, "TempFileToExclude.txt"), "Adding to excluded file!");
                File.AppendAllText(Path.Combine(watchDirPath, "TempFileToWatch.txt"), "Adding to included file!");

                args = await taskCompletionSource.Task.ConfigureAwait(false);
            }, () => watchedFileChanged);

            fsEventStream.Show();

            Assert.IsNotNull(args, "Null args");
            // Assert that only one event is triggered and that the path is that of the watched file
            Assert.AreEqual(args.Events.Length, 1, "More events triggered");
            Assert.AreEqual(Path.Combine(fsEventStream.PathsBeingWatched [0], "WatchDir", "TempFileToWatch.txt"), args.Events [0].Path, "Watched file not triggered");
        }
Beispiel #7
0
        void HandleFSEventStreamEvents(object sender, FSEventStreamEventsArgs args)
        {
            var xiexports  = WindowScriptObject?.ValueForKey(new NSString("xiexports")) as WebScriptObject;
            var cssMonitor = xiexports?.ValueForKey(new NSString("cssMonitor")) as WebScriptObject;

            if (cssMonitor == null)
            {
                return;
            }

            var basePath = ClientApp.SharedInstance.WebServer.SourceBasePath.FullPath;

            foreach (var fsEvent in args.Events)
            {
                cssMonitor.CallWebScriptMethod("notifyFileEvent", new NSObject [] {
                    new NSString(fsEvent.Path.Substring(basePath.Length))
                });
            }
        }
        void eventStream_Events(object sender, FSEventStreamEventsArgs args)
        {
            var interestingFlags = new FSEventStreamEventFlags[]
            {
                FSEventStreamEventFlags.ItemCreated,
                FSEventStreamEventFlags.ItemModified,
                FSEventStreamEventFlags.ItemRemoved,
                FSEventStreamEventFlags.ItemRenamed
            };

            var interestingEvents = args.Events
                                    .Where(e => interestingFlags.Any(f => e.Flags.HasFlag(f)))
                                    .ToArray();

            if (interestingEvents.Any())
            {
                PauseWatcherAndScheduleCallback();
            }
        }
        public void FSEventFileChangedTest()
        {
            string path = Path.Combine(dirPath, "TempFileToWatch.txt");
            var    taskCompletionSource  = new TaskCompletionSource <FSEventStreamEventsArgs> ();
            FSEventStreamEventsArgs args = null;

            TestRuntime.RunAsync(TimeSpan.FromSeconds(30), async() => {
                fsEventStream.Events += (sender, eventArgs) => {
                    taskCompletionSource.SetResult(eventArgs);
                    watchedFileChanged = true;
                };
                fsEventStream.ScheduleWithRunLoop(CFRunLoop.Current);
                fsEventStreamStarted = fsEventStream.Start();
                File.AppendAllText(path, "Hello World!");
                Assert.IsTrue(File.Exists(path));
                args = await taskCompletionSource.Task.ConfigureAwait(false);
            }, () => watchedFileChanged);

            Assert.IsNotNull(args, "Null args");
        }
Beispiel #10
0
		private void handleEvents(object sender, FSEventStreamEventsArgs args)
		{
			foreach (var e in args.Events) {
				if ((e.Flags & FSEventStreamEventFlags.ItemModified) != 0) {
					if (Filter?.Invoke(e.Path) ?? true) {
						Changed?.Invoke(e.Path);
					}
				}
				if ((e.Flags & FSEventStreamEventFlags.ItemCreated) != 0) {
					if (Filter?.Invoke(e.Path) ?? true) {
						Created?.Invoke(e.Path);
					}
				}
				if ((e.Flags & FSEventStreamEventFlags.ItemRemoved) != 0) {
					if (Filter?.Invoke(e.Path) ?? true) {
						Deleted?.Invoke(e.Path);
					}
				}
				if ((e.Flags & FSEventStreamEventFlags.ItemRenamed) != 0) {
					if (((e.Flags & FSEventStreamEventFlags.ItemIsFile) != 0 && System.IO.File.Exists(e.Path)) ||
					    ((e.Flags & FSEventStreamEventFlags.ItemIsDir) != 0 && System.IO.Directory.Exists(e.Path))) {
						if (lastRenameEvent != null && lastRenameEvent.Value.Id == e.Id - 1) {
							Renamed?.Invoke (lastRenameEvent.Value.Path, e.Path);
							lastRenameEvent = null;
						} else {
							Created?.Invoke(e.Path);
						}
					} else {
						CleanLastRenameEvent();
						lastRenameEvent = e;
						continue;
					}
				}
				CleanLastRenameEvent();
			}
		}
Beispiel #11
0
        private void OnFSEventStreamEvents(object sender, FSEventStreamEventsArgs e) {
            foreach (MonoMac.CoreServices.FSEvent fsEvent in e.Events) {
                bool isFile = (fsEvent.Flags & FSEventStreamEventFlags.ItemIsFile) != 0;
                if ((fsEvent.Flags & FSEventStreamEventFlags.ItemRemoved) != 0 && !FileOrDirectoryExists(fsEvent.Path, isFile)) {
                    this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Deleted, fsEvent.Path, !isFile));
                    continue;
                }

                if ((fsEvent.Flags & FSEventStreamEventFlags.ItemCreated) != 0 && FileOrDirectoryExists(fsEvent.Path, isFile)) {
                    this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Created, fsEvent.Path, !isFile));
                }

                if (((fsEvent.Flags & FSEventStreamEventFlags.ItemModified) != 0
                    || (fsEvent.Flags & FSEventStreamEventFlags.ItemInodeMetaMod) != 0)
                    && FileOrDirectoryExists(fsEvent.Path, isFile)) {
                    this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Changed, fsEvent.Path, !isFile));
                }

                if ((fsEvent.Flags & FSEventStreamEventFlags.ItemRenamed) != 0) {
                    if (FileOrDirectoryExists(fsEvent.Path, isFile)) {
                        if (this.LastRenameEvent != null && this.LastRenameEvent.Value.Id == fsEvent.Id - 1) {
                            this.Queue.AddEvent(new CmisSync.Lib.Events.FSMovedEvent(this.LastRenameEvent.Value.Path, fsEvent.Path, !isFile));
                            this.LastRenameEvent = null;
                        } else {
                            this.Queue.AddEvent(new CmisSync.Lib.Events.FSEvent(WatcherChangeTypes.Created, fsEvent.Path, !isFile));
                        }
                    } else {
                        this.CleanLastRenameEvent();
                        this.LastRenameEvent = fsEvent;
                        continue;
                    }
                }

                this.CleanLastRenameEvent();
            }
        }
		void OnFSEventStreamEvents (object sender, FSEventStreamEventsArgs e)
		{
			eventsDataSource.Add (e.Events);
			EventStreamView.ReloadData ();
			EventStreamView.ScrollRowToVisible (EventStreamView.RowCount - 1);
		}
 void OnFSEventStreamEvents(object sender, FSEventStreamEventsArgs e)
 {
     eventsDataSource.Add(e.Events);
     EventStreamView.ReloadData();
     EventStreamView.ScrollRowToVisible(EventStreamView.RowCount - 1);
 }