Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Sync.Strategy.MacWatcher"/> class.
        /// </summary>
        /// <param name="pathname">Path to be monitored.</param>
        /// <param name="queue">Queue to pass the new events to.</param>
        /// <param name="latency">Maximum latency for file system events.</param>
        public MacWatcher(string pathname, ISyncEventQueue queue, TimeSpan latency)
        {
            if (string.IsNullOrEmpty(pathname))
            {
                throw new ArgumentNullException("The given fs stream must not be null");
            }

            if (queue == null)
            {
                throw new ArgumentNullException("The given queue must not be null");
            }

            this.Queue         = queue;
            this.RunLoopThread = new Thread(() =>
            {
                this.RunLoop = NSRunLoop.Current;
                while (!this.StopRunLoop)
                {
                    this.RunLoop.RunUntil(NSDate.FromTimeIntervalSinceNow(1));
                    this.CleanLastRenameEvent();
                }
            });

            this.RunLoopThread.Start();
            while (RunLoop == null)
            {
                Thread.Sleep(10);
            }

            this.FsStream     = new FSEventStream(new [] { pathname }, latency, FSEventStreamCreateFlags.FileEvents);
            this.EnableEvents = false;
            this.FsStream.ScheduleWithRunLoop(this.RunLoop);
        }
        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();
            }
        }
Esempio n. 3
0
		public void Dispose()
		{
			if (fsEventStream != null) {
				fsEventStream.Dispose();
				fsEventStream = null;
			}
		}
Esempio n. 4
0
 public void CreateFSEventStream()
 {
     watchedFileChanged   = false;
     exludedFileChanged   = false;
     fsEventStreamStarted = false;
     fsEventStream        = new FSEventStream(st_dev, pathsToWatchRelativeToDevice, FSEvent.SinceNowId, TimeSpan.FromSeconds(1), FSEventStreamCreateFlags.WatchRoot | FSEventStreamCreateFlags.FileEvents | FSEventStreamCreateFlags.NoDefer);
     Assert.IsNotNull(fsEventStream, "Null");
 }
Esempio n. 5
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();
 }
Esempio n. 6
0
        void StopMonitoringExternalCssChanges()
        {
            if (fsEventStream != null)
            {
                Log.Info(TAG, "Stopping CSS monitor");

                fsEventStream.Stop();
                fsEventStream.Dispose();
                fsEventStream = null;
            }
        }
Esempio n. 7
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;
        }
Esempio n. 8
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;
        }
Esempio n. 9
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();
		}
Esempio n. 10
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();
        }
Esempio n. 11
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);
     }
 }
Esempio n. 12
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;
		}
Esempio n. 13
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 ();
			}
		}
Esempio n. 15
0
 public void Create()
 {
     using var eventStream = new FSEventStream(new [] { Path.Combine(Environment.GetEnvironmentVariable("HOME"), "Desktop") }, TimeSpan.FromSeconds(5), FSEventStreamCreateFlags.FileEvents);
 }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Sync.Strategy.MacWatcher"/> class.
        /// </summary>
        /// <param name="pathname">Path to be monitored.</param>
        /// <param name="queue">Queue to pass the new events to.</param>
        /// <param name="latency">Maximum latency for file system events.</param>
        public MacWatcher(string pathname, ISyncEventQueue queue, TimeSpan latency) {
            if (string.IsNullOrEmpty(pathname)) {
                throw new ArgumentNullException("pathname", "The given fs stream must not be null");
            }

            if (queue == null) {
                throw new ArgumentNullException("queue", "The given queue must not be null");
            }

            this.Queue = queue;
            this.RunLoopThread = new Thread(() => {
                this.RunLoop = NSRunLoop.Current;
                while (!this.StopRunLoop) {
                    this.RunLoop.RunUntil(NSDate.FromTimeIntervalSinceNow(1));
                    this.CleanLastRenameEvent();
                }
            });

            this.RunLoopThread.Start();
            while (RunLoop == null) {
                Thread.Sleep(10);
            }

            this.FsStream = new FSEventStream(new [] { pathname }, latency, FSEventStreamCreateFlags.FileEvents);
            this.EnableEvents = false;
            this.FsStream.ScheduleWithRunLoop(this.RunLoop);
        }