Example #1
0
        /// <summary>
        /// Toggle on and off subscription to
        /// automatic cloud updates.
        /// </summary>
        public static ExternalEvent ToggleSubscription(
            // EventHandler<IdlingEventArgs> handler
            IExternalEventHandler handler)
        {
            if (Subscribed)
            {
                Debug.Print("Unsubscribing...");
                //_uiapp.Idling -= _handler;
                //_handler = null;
                _event.Dispose();
                _event = null;

                _buttons[_subscribeButtonIndex].ItemText
                    = _subscribe;

                _timer.Stop();
                _timer.Report("Subscription timing");
                _timer = null;
                Debug.Print("Unsubscribed.");
            }
            else
            {
                Debug.Print("Subscribing...");
                //_uiapp.Idling += handler;
                //_handler = handler;
                _event = ExternalEvent.Create(handler);

                _buttons[_subscribeButtonIndex].ItemText
                    = _unsubscribe;

                _timer = new JtTimer("Subscription");
                Debug.Print("Subscribed.");
            }
            return(_event);
        }
        public static bool ToggleSubscription2(IExternalEventHandler handler)
        {
            if (Subscribed)
            {
                Util.Log("Unsubscribing...");

                _event.Dispose();
                _event = null;

                button1.ItemText = _subscribe;

                //_timer.Stop();
                //_timer.Report( "Subscription timing" );
                //_timer = null;

                Util.Log("Unsubscribed.");
            }
            else
            {
                Util.Log("Subscribing...");

                _event = ExternalEvent.Create(handler);

                button1.ItemText = _unsubscribe;

                //_timer = new JtTimer( "Subscription" );

                Util.Log("Subscribed.");
            }
            return(null != _event);
        }
 /// <summary>
 ///     Create a new <see cref="ExternalEvent" /> for an <see cref="IExternalEventHandler" /> instance
 /// </summary>
 /// <param name="handler">The <see cref="IExternalEventHandler" /> instance</param>
 /// <returns>The <see cref="ExternalEvent" /> created</returns>
 private static Task <ExternalEvent> CreateExternalEvent(IExternalEventHandler handler)
 {
     return(new TaskCompletionSource <ExternalEvent>().Await(Locker.LockAsync(), (unlockKey, tcs) =>
     {
         var creationTask = FutureExternalEventCreator.RunAsync <IExternalEventHandler, ExternalEvent>(handler);
         tcs.Await(creationTask, () => UnlockKeys.Enqueue(unlockKey));
     }).Task);
 }
 public FutureExternalEvent(IExternalEventHandler handler)
 {
     Handler = handler;
     ExternalEventTaskCreator = () => CreateExternalEvent(handler).ContinueWith(task =>
     {
         CreatedExternalEvent = task.Result;
         return(CreatedExternalEvent);
     });
 }
Example #5
0
 public ExternalEventPair(IExternalEventHandler handler, Func <Task <ExternalEvent> > futureCreator)
 {
     Handler       = handler;
     FutureTrigger = futureCreator().ContinueWith(task =>
     {
         Trigger = task.Result;
         return(Trigger);
     });
 }
Example #6
0
        /// <summary>
        /// Toggle on and off subscription to automatic 
        /// cloud updates. Return true when subscribed.
        /// </summary>
        public static bool ToggleSubscription2(
            IExternalEventHandler handler)
        {
            if ( Subscribed )
              {
            Util.Log( "Unsubscribing..." );

            _event.Dispose();
            _event = null;

            _buttons[_subscribeButtonIndex].ItemText
              = _subscribe;

            //_timer.Stop();
            //_timer.Report( "Subscription timing" );
            //_timer = null;

            Util.Log( "Unsubscribed." );
              }
              else
              {
            Util.Log( "Subscribing..." );

            _event = ExternalEvent.Create( handler );

            _buttons[_subscribeButtonIndex].ItemText
              = _unsubscribe;

            //_timer = new JtTimer( "Subscription" );

            Util.Log( "Subscribed." );
              }
              return null != _event;
        }
Example #7
0
 internal ExternalEventPair(ExternalEvent trigger, IExternalEventHandler handler)
 {
     EventTrigger = trigger;
     EventHandler = handler;
 }
Example #8
0
        /// <summary>
        /// Toggle on and off subscription to 
        /// automatic cloud updates.
        /// </summary>
        public static ExternalEvent ToggleSubscription(
            // EventHandler<IdlingEventArgs> handler
            IExternalEventHandler handler)
        {
            if( Subscribed )
              {
            Debug.Print( "Unsubscribing..." );
            //_uiapp.Idling -= _handler;
            //_handler = null;
            _event.Dispose();
            _event = null;

            _buttons[_subscribeButtonIndex].ItemText
              = _subscribe;

            _timer.Stop();
            _timer.Report( "Subscription timing" );
            _timer = null;
            Debug.Print( "Unsubscribed." );
              }
              else
              {
            Debug.Print( "Subscribing..." );
            //_uiapp.Idling += handler;
            //_handler = handler;
            _event = ExternalEvent.Create( handler );

            _buttons[_subscribeButtonIndex].ItemText
              = _unsubscribe;

            _timer = new JtTimer( "Subscription" );
            Debug.Print( "Subscribed." );
              }
              return _event;
        }
 private FutureExternalEvent(IExternalEventHandler handler, ExternalEvent externalEvent)
 {
     Handler = handler;
     CreatedExternalEvent     = externalEvent;
     ExternalEventTaskCreator = () => TaskUtils.FromResult(externalEvent);
 }
Example #10
0
 public ExternalEventPair(IExternalEventHandler handler, Func <ExternalEvent> creator)
 {
     Handler = handler;
     Trigger = creator();
 }
Example #11
0
 public ExternalEventPair(IExternalEventHandler handler) : this(handler, () => ExternalEvent.Create(handler))
 {
 }
Example #12
0
 /// <summary>
 ///     Create a new <see cref="ExternalEvent" /> for an <see cref="IExternalEventHandler" /> instance
 /// </summary>
 /// <param name="handler">The <see cref="IExternalEventHandler" /> instance</param>
 /// <returns>The <see cref="ExternalEvent" /> created</returns>
 private static Task <ExternalEvent> CreateExternalEvent(IExternalEventHandler handler)
 {
     return(ExternalEventCreator.RunAsync <Func <UIApplication, ExternalEvent>, ExternalEvent>(app => ExternalEvent.Create(handler)));
 }