public override void Unschedule(NSRunLoop aRunLoop, string mode)
            {
                var cfRunLoop = aRunLoop.GetCFRunLoop();
                var nsMode    = new NSString(mode);

                cfRunLoop.RemoveSource(source, nsMode);
            }
Example #2
0
        public Task <IBitmap> Load(Stream sourceStream, float?desiredWidth, float?desiredHeight)
        {
            var data = NSData.FromStream(sourceStream);

            var tcs = new TaskCompletionSource <IBitmap>();

#if UIKIT
            NSRunLoop.InvokeInBackground(() =>
            {
                try
                {
                    var bitmap = UIImage.LoadFromData(data);
                    if (bitmap == null)
                    {
                        throw new Exception("Failed to load image");
                    }

                    tcs.TrySetResult(new CocoaBitmap(bitmap));
                }
                catch (Exception ex)
                {
                    LogHost.Default.Debug(ex, "Unable to parse the known colour name.");
                    tcs.TrySetException(ex);
                }
            });
#else
            tcs.TrySetResult(new CocoaBitmap(new UIImage(data)));
#endif
            return(tcs.Task);
        }
Example #3
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);
        }
Example #4
0
 public NSRunLoopScheduler(NSRunLoop runLoop)
 {
     if (runLoop == null)
     {
         throw new ArgumentNullException("runLoop");
     }
     _runLoop = runLoop;
 }
Example #5
0
 public NSRunLoopScheduler()
 {
     _runLoop = NSRunLoop.Current;
     if (_runLoop == null)
     {
         throw new InvalidOperationException("Cannot create scheduler on thread without an NSRunLoop");
     }
 }
Example #6
0
        public void Activate(NSNotification notification)
        {
            if (Display.DisplayLink != null)
            {
                NSRunLoop loop = NSRunLoop.Current;
                Display.DisplayLink.AddToRunLoop(loop, NSRunLoopMode.Default);
            }

            Display.OnActivated();
        }
Example #7
0
        public void Deactivate(NSNotification notification)
        {
            if (Display.DisplayLink != null)
            {
                NSRunLoop loop = NSRunLoop.Current;
                Display.DisplayLink.RemoveFromRunLoop(loop, NSRunLoopMode.Default);
            }

            Display.OnDeactivated();
        }
Example #8
0
        public CMTimebaseError AddTimer(NSTimer timer, NSRunLoop runloop)
        {
            if (timer == null)
            {
                throw new ArgumentNullException("timer");
            }
            if (runloop == null)
            {
                throw new ArgumentNullException("runloop");
            }

            // FIXME: Crashes inside CoreMedia
            return(CMTimebaseAddTimer(Handle, timer.Handle, runloop.Handle));
        }
Example #9
0
        public CMTimebaseError AddTimer(NSTimer timer, NSRunLoop runloop)
        {
            if (timer == null)
            {
                throw new ArgumentNullException("timer");
            }
            if (runloop == null)
            {
                throw new ArgumentNullException("runloop");
            }

            // NSRunloop and CFRunloop[Ref] are NOT toll free bridged types
            using (var cf = runloop.GetCFRunLoop())
                return(CMTimebaseAddTimer(Handle, timer.Handle, cf.Handle));
        }
Example #10
0
        public CMTimebaseError AddTimer(NSTimer timer, NSRunLoop runloop)
        {
            if (timer is null)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(timer));
            }
            if (runloop is null)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(runloop));
            }

            // NSRunloop and CFRunloop[Ref] are NOT toll free bridged types
            using (var cf = runloop.GetCFRunLoop())
                return(CMTimebaseAddTimer(Handle, timer.Handle, cf.Handle));
        }
            public override void Schedule(NSRunLoop aRunLoop, string mode)
            {
                var cfRunLoop = aRunLoop.GetCFRunLoop();
                var nsMode    = new NSString(mode);

                cfRunLoop.AddSource(source, nsMode);

                if (notifying)
                {
                    return;
                }

                notifying = true;
                Notify(CFStreamEventType.HasBytesAvailable);
                notifying = false;
            }
Example #12
0
        public Task <IBitmap> LoadFromResource(string source, float?desiredWidth, float?desiredHeight)
        {
            var tcs = new TaskCompletionSource <IBitmap>();

#if UIKIT
            NSRunLoop.InvokeInBackground(() =>
            {
                try
                {
                    var bitmap = UIImage.FromBundle(source);
                    if (bitmap == null)
                    {
                        throw new Exception("Failed to load image from resource: " + source);
                    }

                    tcs.TrySetResult(new CocoaBitmap(bitmap));
                }
                catch (Exception ex)
                {
                    LogHost.Default.Debug(ex, "Unable to parse the known colour name.");
                    tcs.TrySetException(ex);
                }
            });
#else
            NSRunLoop.Main.BeginInvokeOnMainThread(() =>
            {
                try
                {
                    var bitmap = UIImage.ImageNamed(source);
                    if (bitmap == null)
                    {
                        throw new Exception("Failed to load image from resource: " + source);
                    }

                    tcs.TrySetResult(new CocoaBitmap(bitmap));
                }
                catch (Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            });
#endif
            return(tcs.Task);
        }
Example #13
0
        private void ClientReceiverThreadProc()
        {
            _tokenSource = new CancellationTokenSource();
            var token = _tokenSource.Token;

            var receiverThread = new Thread(() =>
            {
                _logger.LogMessage("Socket", LogLevel.Verbose, "Starting receiver thread loop.");

                RunLoop = NSRunLoop.Current;

                do
                {
                    RunLoop.Run();

                    Thread.Sleep(MqttProtocolInformation.InternalSettings.SocketReceiverThreadLoopDelay);
                }while(!token.IsCancellationRequested);
            });

            receiverThread.Start();
        }
Example #14
0
 public void ScheduleWithRunLoop(NSRunLoop runLoop)
 {
     ScheduleWithRunLoop(runLoop.GetCFRunLoop(), CFRunLoop.ModeDefault);
 }
Example #15
0
 public void ScheduleWithRunLoop(NSRunLoop runLoop, NSString runLoopMode)
 {
     ScheduleWithRunLoop(runLoop.GetCFRunLoop(), runLoopMode);
 }
Example #16
0
 public void AddToRunLoop(NSRunLoop runloop, NSRunLoopMode mode)
 {
     AddToRunLoop(runloop, NSRunLoop.FromEnum(mode));
 }
Example #17
0
 public NSRunLoopScheduler (NSRunLoop runLoop)
 {
     if (runLoop == null)
         throw new ArgumentNullException ("runLoop");
     _runLoop = runLoop;
 }
Example #18
0
 public NSRunLoopScheduler ()
 {
     _runLoop = NSRunLoop.Current;
     if (_runLoop == null)
         throw new InvalidOperationException ("Cannot create scheduler on thread without an NSRunLoop");
 }