Beispiel #1
0
        void StartWriteMonitor()
        {
            NSUrl fileURL = TestFileUrl;

            var stream         = File.Create(fileURL.Path);
            int fileDescriptor = GetFileDescriptor(stream);

            dispatchSource = new DispatchSource.WriteMonitor(fileDescriptor, DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Write monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                string message = string.Format("Write monitor: {0} was opened in write mode", fileURL.LastPathComponent.ToString());
                PrintResult(textView, message);
                dispatchSource.Cancel();
                stream.Close();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Write monitor cancelled");
            });

            dispatchSource.Resume();
        }
Beispiel #2
0
        void StartVnodeMonitor()
        {
            NSUrl fileURL = TestFileUrl;

            var stream         = File.Create(fileURL.Path);
            int fileDescriptor = GetFileDescriptor(stream);

            dispatchSource = new DispatchSource.VnodeMonitor(fileDescriptor,
                                                             VnodeMonitorKind.Delete | VnodeMonitorKind.Extend | VnodeMonitorKind.Write,
                                                             DispatchQueue.MainQueue
                                                             );

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Vnode monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                var observedEvents = ((DispatchSource.VnodeMonitor)dispatchSource).ObservedEvents;
                string message     = string.Format("Vnode monitor event for {0}: {1}", fileURL.LastPathComponent, observedEvents.ToString());
                PrintResult(textView, message);
                dispatchSource.Cancel();
                stream.Close();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Vnode monitor cancelled");
            });

            dispatchSource.Resume();
        }
        void TestReadMonitor()
        {
            NSUrl fileURL        = TestFileUrl;
            int   fileDescriptor = 0;

            using (var stream = new FileStream(fileURL.Path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)) {
                fileDescriptor = GetFileDescriptor(stream);
            }

            dispatchSource = new DispatchSource.ReadMonitor(fileDescriptor, DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Read monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                PrintResult(textView, string.Format("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
                dispatchSource.Cancel();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Read monitor cancelled");
            });

            dispatchSource.Resume();
        }
Beispiel #4
0
        void TestReadMonitor()
        {
            NSUrl fileURL = TestFileUrl;

            var stream         = File.OpenRead(fileURL.Path);
            int fileDescriptor = GetFileDescriptor(stream);

            dispatchSource = new DispatchSource.ReadMonitor(fileDescriptor, DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Read monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                PrintResult(textView, string.Format("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
                dispatchSource.Cancel();
                stream.Close();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Read monitor cancelled");
            });

            dispatchSource.Resume();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            dispatchSource = new DispatchSource.VnodeMonitor(documentsPath, VnodeMonitorKind.Delete | VnodeMonitorKind.Extend | VnodeMonitorKind.Write, DispatchQueue.MainQueue);
            dispatchSource.SetRegistrationHandler(() => {
                Console.WriteLine("Vnode monitor registered");
            });
            dispatchSource.SetEventHandler(() => {
                UpdateFilesList();
            });

            dispatchSource.Resume();
        }
        private void StartWriteMonitor()
        {
            var fileUrl        = TestFileUrl;
            var stream         = new FileStream(fileUrl.Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
            int fileDescriptor = GetFileDescriptor(stream);

            dispatchSource = new DispatchSource.WriteMonitor(fileDescriptor, DispatchQueue.MainQueue);
            dispatchSource.SetRegistrationHandler(() => PrintResult("Write monitor registered"));
            dispatchSource.SetEventHandler(() =>
            {
                PrintResult($"Write monitor: {fileUrl.LastPathComponent} was opened in write mode");
                CancelDispatchSource();

                stream.Dispose();
                stream = null;
            });

            dispatchSource.SetCancelHandler(() => PrintResult("Write monitor cancelled"));
            dispatchSource.Resume();
        }
        private void TestReadMonitor()
        {
            var fileUrl        = TestFileUrl;
            int fileDescriptor = 0;

            using (var stream = new FileStream(fileUrl.Path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
            {
                fileDescriptor = GetFileDescriptor(stream);
            }

            dispatchSource = new DispatchSource.ReadMonitor(fileDescriptor, DispatchQueue.MainQueue);
            dispatchSource.SetRegistrationHandler(() => PrintResult("Read monitor registered"));
            dispatchSource.SetEventHandler(() =>
            {
                PrintResult($"Read monitor: {fileUrl.LastPathComponent} was opened in read mode");
                CancelDispatchSource();
            });

            dispatchSource.SetCancelHandler(() => PrintResult("Read monitor cancelled"));
            dispatchSource.Resume();
        }
Beispiel #8
0
        void StartMemoryMonitor()
        {
            dispatchSource = new DispatchSource.MemoryPressure(
                MemoryPressureFlags.Critical | MemoryPressureFlags.Warn | MemoryPressureFlags.Normal,
                DispatchQueue.MainQueue);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Memory monitor registered");
            });

            dispatchSource.SetEventHandler(() => {
                var pressureLevel = ((DispatchSource.MemoryPressure)dispatchSource).PressureFlags;
                PrintResult(textView, string.Format("Memory worning of level: {0}", pressureLevel));
                tableView.UserInteractionEnabled = true;
                dispatchSource.Cancel();
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Memory monitor cancelled");
            });

            dispatchSource.Resume();
        }
Beispiel #9
0
        void StartTimer()
        {
            dispatchSource = new DispatchSource.Timer(DispatchQueue.MainQueue);

            long delay  = 2 * NanosecondsInSecond;
            long leeway = 5 * NanosecondsInSecond;

            ((DispatchSource.Timer)dispatchSource).SetTimer(DispatchTime.Now, delay, leeway);

            dispatchSource.SetRegistrationHandler(() => {
                PrintResult(textView, "Timer registered");
            });

            dispatchSource.SetEventHandler(() => {
                PrintResult(textView, "Timer tick");
            });

            dispatchSource.SetCancelHandler(() => {
                PrintResult(textView, "Timer stopped");
            });

            dispatchSource.Resume();
        }
		void TestReadMonitor ()
		{
			NSUrl fileURL = TestFileUrl;
			int fileDescriptor = 0;

			using (var stream = new FileStream (fileURL.Path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)) {
				fileDescriptor = GetFileDescriptor (stream);
			}

			dispatchSource = new DispatchSource.ReadMonitor (fileDescriptor, DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Read monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				PrintResult (textView, string.Format ("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
				dispatchSource.Cancel ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Read monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void StartWriteMonitor ()
		{
			NSUrl fileURL = TestFileUrl;
			var stream = new FileStream (fileURL.Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
			int fileDescriptor = GetFileDescriptor (stream);

			dispatchSource = new DispatchSource.WriteMonitor (fileDescriptor, DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Write monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				string message = string.Format ("Write monitor: {0} was opened in write mode", fileURL.LastPathComponent);
				PrintResult (textView, message);
				dispatchSource.Cancel ();
				stream.Close ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Write monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void StartMemoryMonitor ()
		{
			dispatchSource = new DispatchSource.MemoryPressure (
				MemoryPressureFlags.Critical | MemoryPressureFlags.Warn | MemoryPressureFlags.Normal, 
				DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Memory monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				var pressureLevel = ((DispatchSource.MemoryPressure)dispatchSource).PressureFlags;
				PrintResult (textView, string.Format ("Memory worning of level: {0}", pressureLevel));
				tableView.UserInteractionEnabled = true;
				dispatchSource.Cancel ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Memory monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void StartVnodeMonitor ()
		{
			NSUrl fileURL = TestFileUrl;

			testFileStream = File.Create (fileURL.Path);
			int fileDescriptor = GetFileDescriptor (testFileStream);

			dispatchSource = new DispatchSource.VnodeMonitor (fileDescriptor,
				VnodeMonitorKind.Delete | VnodeMonitorKind.Extend | VnodeMonitorKind.Write,
				DispatchQueue.MainQueue
			);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Vnode monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				var observedEvents = ((DispatchSource.VnodeMonitor)dispatchSource).ObservedEvents;
				string message = string.Format ("Vnode monitor event for {0}: {1}", fileURL.LastPathComponent, observedEvents);
				PrintResult (textView, message);
				dispatchSource.Cancel ();
				testFileStream.Close ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Vnode monitor cancelled");
			});

			dispatchSource.Resume ();
		}
		void StartTimer ()
		{
			dispatchSource = new DispatchSource.Timer (DispatchQueue.MainQueue);

			long delay = 2 * NanosecondsInSecond;
			long leeway = 5 * NanosecondsInSecond;

			((DispatchSource.Timer)dispatchSource).SetTimer (DispatchTime.Now, delay, leeway);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Timer registered");
			});

			dispatchSource.SetEventHandler (() => {
				PrintResult (textView, "Timer tick");
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Timer stopped");
			});

			dispatchSource.Resume ();
		}
		void TestReadMonitor ()
		{
			NSUrl fileURL = TestFileUrl;

			File.WriteAllText (fileURL.Path, "Roses are red");
			var stream = File.OpenRead (fileURL.Path);
			int fileDescriptor = GetFileDescriptor (stream);

			dispatchSource = new CoreFoundation.DispatchSource.ReadMonitor (fileDescriptor, DispatchQueue.MainQueue);

			dispatchSource.SetRegistrationHandler (() => {
				PrintResult (textView, "Read monitor registered");
			});

			dispatchSource.SetEventHandler (() => {
				PrintResult (textView, string.Format ("Read monitor: {0} was opened in read mode", fileURL.LastPathComponent));
				dispatchSource.Cancel ();
				stream.Close ();
			});

			dispatchSource.SetCancelHandler (() => {
				PrintResult (textView, "Read monitor cancelled");
			});

			dispatchSource.Resume ();
		}