Ejemplo n.º 1
0
        void InitializeFSEventStream()
        {
            if (eventStream != null)
            {
                eventStream.Events -= OnFSEventStreamEvents;
                eventStream.Dispose();
                eventStream = null;
            }

            if (Directory.Exists(currentWatchPath))
            {
                Console.WriteLine("Creating new FSEventStream: latency={0}, path={1}", eventLatency, currentWatchPath);

                eventStreamIsRunning = false;

                eventStream = new FSEventStream(new [] { currentWatchPath },
                                                eventLatency, FSEventStreamCreateFlags.FileEvents);
                eventStream.Events += OnFSEventStreamEvents;
                eventStream.ScheduleWithRunLoop(NSRunLoop.Current);

                EventStreamView.DataSource = eventsDataSource = new FSEventDataSource();

                ToggleFSEventStream();
            }
        }
Ejemplo n.º 2
0
 public MacFileSystemWatcher(string filePath)
 {
     System.Diagnostics.Debug.WriteLine("Creating MacFileSystemWatcher");
     _eventStream         = new FSEventStream(new[] { filePath }, TimeSpan.FromMilliseconds(500), FSEventStreamCreateFlags.FileEvents);
     _eventStream.Events += OnFSEventStreamEvents;
     _eventStream.ScheduleWithRunLoop(NSRunLoop.Current);
     _eventStream.Start();
 }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        public void Setup(string path, int detectionToAlertDelayMilliseconds)
        {
            _eventStream = new FSEventStream(new string[] { path },
                                             TimeSpan.FromMilliseconds(100),
                                             FSEventStreamCreateFlags.FileEvents);

            _eventStream.ScheduleWithRunLoop(Foundation.NSRunLoop.Current);

            DetectionToAlertDelayMilliseconds = detectionToAlertDelayMilliseconds;

            _eventStream.Events += eventStream_Events;
        }
Ejemplo n.º 5
0
        public void Setup(Repository repository, int detectionToAlertDelayMilliseconds)
        {
            _repository = repository;

            _eventStream = new FSEventStream(new string[] { _repository.Path },
                                             TimeSpan.FromMilliseconds(100),
                                             FSEventStreamCreateFlags.FileEvents);

            _eventStream.ScheduleWithRunLoop(Foundation.NSRunLoop.Main);

            DetectionToAlertDelayMilliseconds = detectionToAlertDelayMilliseconds;

            _eventStream.Events += eventStream_Events;
        }
Ejemplo n.º 6
0
		public FileSystemWatcher(string path, bool includeSubdirectories)
		{
			if (!includeSubdirectories) {
				Filter = (s) => {
					return System.IO.Path.GetDirectoryName(s) == path;
				};
			}
			fsEventStream = new FSEventStream(
				new string[] { path }, TimeSpan.FromSeconds(1),
				FSEventStreamCreateFlags.FileEvents | FSEventStreamCreateFlags.IgnoreSelf);
			fsEventStream.Events += handleEvents;
			fsEventStream.ScheduleWithRunLoop(NSRunLoop.Current);
			fsEventStream.Start();
		}
Ejemplo n.º 7
0
        void StartMonitoringExternalCssChanges()
        {
            if (fsEventStream != null)
            {
                return;
            }

            var monitorPaths = new [] { ClientApp.SharedInstance.WebServer.SourceBasePath.FullPath };

            Log.Info(TAG, $"Starting CSS monitor for paths: {string.Join (", ", monitorPaths)}");

            fsEventStream = new FSEventStream(
                monitorPaths,
                TimeSpan.FromSeconds(1),
                FSEventStreamCreateFlags.WatchRoot | FSEventStreamCreateFlags.FileEvents);
            fsEventStream.Events += HandleFSEventStreamEvents;
            fsEventStream.ScheduleWithRunLoop(NSRunLoop.Current);
            fsEventStream.Start();
        }
Ejemplo n.º 8
0
 public bool InitWatchFolder(string path)
 {
     try
     {
         this.path = path;
         TimeSpan eventLatency = TimeSpan.FromSeconds(1);
         //https://developer.apple.com/documentation/coreservices/file_system_events/1455376-fseventstreamcreateflags
         eventStream         = new FSEventStream(new[] { path }, eventLatency, FSEventStreamCreateFlags.FileEvents | FSEventStreamCreateFlags.NoDefer);
         eventStream.Events += OnAppDataChanged;
         eventStream.ScheduleWithRunLoop(NSRunLoop.Current);
         Start();
         return(true);
     }
     catch (Exception e)
     {
         this.path = null;
         return(false);
     }
 }
Ejemplo n.º 9
0
		public override bool ReadFromUrl (NSUrl url, string typeName, out NSError outError)
		{
			fsEvents = new FSEventStream (new [] { Path.GetDirectoryName (url.Path) },
				TimeSpan.FromSeconds (0), FSEventStreamCreateFlags.FileEvents);

			fsEvents.Events += (sender, e) => {
				foreach (var evnt in e.Events) {
					if (evnt.Path == url.Path && (evnt.Flags & FSEventStreamEventFlags.ItemModified) != 0) {
						ReloadDocument ();
						break;
					}
				}
			};

			fsEvents.ScheduleWithRunLoop (NSRunLoop.Current);
			fsEvents.Start ();

			documentUrl = url;
			outError = null;
			return true;
		}
Ejemplo n.º 10
0
        public override bool ReadFromUrl(NSUrl url, string typeName, out NSError outError)
        {
            fsEvents = new FSEventStream(new [] { Path.GetDirectoryName(url.Path) },
                                         TimeSpan.FromSeconds(0), FSEventStreamCreateFlags.FileEvents);

            fsEvents.Events += (sender, e) => {
                foreach (var evnt in e.Events)
                {
                    if (evnt.Path == url.Path && evnt.Flags.HasFlag(FSEventStreamEventFlags.ItemModified))
                    {
                        ReloadDocument();
                        break;
                    }
                }
            };

            fsEvents.ScheduleWithRunLoop(NSRunLoop.Main);
            fsEvents.Start();

            documentUrl = url;
            outError    = null;
            return(true);
        }
		void InitializeFSEventStream ()
		{
			if (eventStream != null) {
				eventStream.Events -= OnFSEventStreamEvents;
				eventStream.Dispose ();
				eventStream = null;
			}

			if (Directory.Exists (currentWatchPath)) {
				Console.WriteLine ("Creating new FSEventStream: latency={0}, path={1}", eventLatency, currentWatchPath);

				eventStreamIsRunning = false;

				eventStream = new FSEventStream (new [] { currentWatchPath },
					eventLatency, FSEventStreamCreateFlags.FileEvents);
				eventStream.Events += OnFSEventStreamEvents;
				eventStream.ScheduleWithRunLoop (NSRunLoop.Current);

				EventStreamView.DataSource = eventsDataSource = new FSEventDataSource ();

				ToggleFSEventStream ();
			}
		}