コード例 #1
0
ファイル: TinyMessenger.cs プロジェクト: Stjerneklar/2DGame
            private void RemoveSubscriptionInternal <TMessage>(TinyMessageSubscriptionToken subscriptionToken)
                where TMessage : class, ITinyMessage
            {
                if (subscriptionToken == null)
                {
                    throw new ArgumentNullException("subscriptionToken");
                }

                lock (_SubscriptionsPadlock)
                {
                    var currentlySubscribed = (from sub in _Subscriptions
                                               where object.ReferenceEquals(sub.Subscription.SubscriptionToken, subscriptionToken)
                                               select sub).ToList();

                    currentlySubscribed.ForEach(sub => _Subscriptions.Remove(sub));
                }
            }
コード例 #2
0
        public PartyModePanel(PartyModeViewModel viewModel, ITinyMessengerHub hub)
        {
            InitializeComponent();
            _viewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel));
            _hub       = hub ?? throw new ArgumentNullException(nameof(hub));
            clientListGrid.DataSource = new BindingList <RemoteClient>(_viewModel.KnownClients);
            var logData = new BindingList <ExecutionLog>(_viewModel.GetLogs());

            logGrid.DataSource = logData;
            activeCheckbox.SetChecked(_viewModel.IsActive);
            _eventSubscription = _hub.Subscribe <ActionLoggedEvent>(msg =>
            {
                logData.Add(msg.Log);
                logGrid.FirstDisplayedScrollingRowIndex = logGrid.RowCount - 1;
                logGrid.Refresh();
            });
        }
コード例 #3
0
        public BacklightControls(ILogger logger, ITinyMessengerHub hub)
        {
            _logger = logger;
            _hub    = hub;

            // React to config changes.
            _subToConfig = _hub.Subscribe <OnConfigLoadedMessage>(message =>
            {
                var data = message.Data;
                Clear();
                Initialize(data.KeyboardCorePath);

                _currentLevel = CheckBacklightStatus();
                if (!_currentLevel.HasValue ||
                    (_currentLevel.Value != LightLevel.Off && _currentLevel.Value != data.LightLevel))
                {
                    // backlight preference has changed, let's set it to the new value.
                    ActivateBacklight(data.LightLevel);
                }

                // React to direct request to change backlight.
                _subToActivate   = _hub.Subscribe <ActivateBacklightRequestMessage>(_ => ActivateBacklight(data.LightLevel));
                _subToDeactivate = _hub.Subscribe <DeactivateBacklightRequestMessage>(_ => ActivateBacklight(LightLevel.Off));
                _subToRequest    = _hub.Subscribe <GetBacklightStateRequestMessage>(_ => SendBacklightState(CheckBacklightStatus()));
                // Save backlight state on stop.
                _subToStop = _hub.Subscribe <OnStopMessage>(_ =>
                {
                    data.SavedState = CheckBacklightStatus() ?? LightLevel.Off;

                    _hub.Publish(new ConfigSaveRequestMessage(this, data));
                });
                // Restore backlight state on start.
                _subToStart = _hub.Subscribe <OnStartupMessage>(_ =>
                {
                    if (data.SaveBacklightState)
                    {
                        ActivateBacklight(data.SavedState);
                    }
                });

                StartChecker();
            });
        }
コード例 #4
0
    private void RemoveSubscriptionInternal <TMessage>(TinyMessageSubscriptionToken subscriptionToken)
        where TMessage : class, ITinyMessage
    {
        if (subscriptionToken == null)
        {
            throw new ArgumentNullException("subscriptionToken");
        }

        lock (_SubscriptionsPadlock)
        {
            for (int i = _Subscriptions.Count - 1; i >= 0; i--)
            {
                if (object.ReferenceEquals(_Subscriptions[i].Subscription.SubscriptionToken, subscriptionToken))
                {
                    _Subscriptions.RemoveAt(i);
                }
            }
        }
    }
コード例 #5
0
ファイル: TinyMessenger.cs プロジェクト: Stjerneklar/2DGame
                /// <summary>
                /// Initializes a new instance of the WeakTinyMessageSubscription class.
                /// </summary>
                /// <param name="destination">Destination object</param>
                /// <param name="deliveryAction">Delivery action</param>
                /// <param name="messageFilter">Filter function</param>
                public WeakTinyMessageSubscription(TinyMessageSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter)
                {
                    if (subscriptionToken == null)
                    {
                        throw new ArgumentNullException("subscriptionToken");
                    }

                    if (deliveryAction == null)
                    {
                        throw new ArgumentNullException("deliveryAction");
                    }

                    if (messageFilter == null)
                    {
                        throw new ArgumentNullException("messageFilter");
                    }

                    _SubscriptionToken = subscriptionToken;
                    _DeliveryAction    = new WeakReference(deliveryAction);
                    _MessageFilter     = new WeakReference(messageFilter);
                }
コード例 #6
0
ファイル: TinyMessenger.cs プロジェクト: Stjerneklar/2DGame
                /// <summary>
                /// Initializes a new instance of the TinyMessageSubscription class.
                /// </summary>
                /// <param name="destination">Destination object</param>
                /// <param name="deliveryAction">Delivery action</param>
                /// <param name="messageFilter">Filter function</param>
                public StrongTinyMessageSubscription(TinyMessageSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter)
                {
                    if (subscriptionToken == null)
                    {
                        throw new ArgumentNullException("subscriptionToken");
                    }

                    if (deliveryAction == null)
                    {
                        throw new ArgumentNullException("deliveryAction");
                    }

                    if (messageFilter == null)
                    {
                        throw new ArgumentNullException("messageFilter");
                    }

                    _SubscriptionToken = subscriptionToken;
                    _DeliveryAction    = deliveryAction;
                    _MessageFilter     = messageFilter;
                }
コード例 #7
0
        public override void OnViewLoaded()
        {
            base.OnViewLoaded();
            _orderNotified = new List <Guid>();

            _serialDisposable.Disposable = ObserveTimerForRefresh()
                                           .Where(_ => _orderToCreate == null || !_orderToCreate.IsPendingCreation)
                                           .SelectMany(_ => GetActiveOrderStatus())
                                           .CatchAndLogError(null)
                                           .Where(orderStatusDetail => orderStatusDetail != null)
                                           .ObserveOn(SynchronizationContext.Current)
                                           .Where(_ => _refreshGate)
                                           .Subscribe(orderStatusDetails =>
            {
                try
                {
                    _refreshGate = false;
                    RefreshOrderStatus(orderStatusDetails);
                }
                catch (Exception ex)
                {
                    Logger.LogErrorWithCaller(ex);
                }
                finally
                {
                    _refreshGate = true;
                }
            });

            _token = this.Services().MessengerHub.Subscribe <OrderDeleted>(orderId =>
            {
                CancelOrder.ExecuteIfPossible(orderId.Content);
            });

            if (_orderToCreate != null)
            {
                CreateOrder(_orderToCreate.PassengerName).FireAndForget();
            }
        }
コード例 #8
0
        public void ShowDialog <T>(string title, IEnumerable <T> items, Func <T, string> displayNameSelector, Action <T> onResult)
        {
            var messenger = TinyIoCContainer.Current.Resolve <ITinyMessengerHub>();
            var list      = items.ToArray();

            if (displayNameSelector == null)
            {
                displayNameSelector = x => x.ToString();
            }
            if (onResult == null)
            {
                onResult = result => { };
            }

            var displayList = list.Select(displayNameSelector).ToArray();

            var ownerId = Guid.NewGuid().ToString();
            var i       = new Intent(Context.Activity, typeof(SelectItemDialogActivity));

            i.AddFlags(ActivityFlags.NewTask | ActivityFlags.ReorderToFront);
            i.PutExtra("Title", title);
            i.PutExtra("Items", displayList);
            i.PutExtra("OwnerId", ownerId);
            TinyMessageSubscriptionToken token = null;

            token = messenger.Subscribe <SubNavigationResultMessage <int> >(msg =>
            {
                messenger.Unsubscribe <ActivityCompleted>(token);
                if (token != null)
                {
                    token.Dispose();
                }
                onResult(list[msg.Result]);
            },
                                                                            msg => msg.MessageId == ownerId);
            Context.Activity.StartActivity(i);
        }
コード例 #9
0
ファイル: TinyMessenger.cs プロジェクト: Stjerneklar/2DGame
            private TinyMessageSubscriptionToken AddSubscriptionInternal <TMessage>(Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter, bool strongReference, ITinyMessageProxy proxy)
                where TMessage : class, ITinyMessage
            {
                if (deliveryAction == null)
                {
                    throw new ArgumentNullException("deliveryAction");
                }

                if (messageFilter == null)
                {
                    throw new ArgumentNullException("messageFilter");
                }

                if (proxy == null)
                {
                    throw new ArgumentNullException("proxy");
                }

                lock (_SubscriptionsPadlock)
                {
                    var subscriptionToken = new TinyMessageSubscriptionToken(this, typeof(TMessage));

                    ITinyMessageSubscription subscription;
                    if (strongReference)
                    {
                        subscription = new StrongTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                    }
                    else
                    {
                        subscription = new WeakTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                    }

                    _Subscriptions.Add(new SubscriptionItem(proxy, subscription));

                    return(subscriptionToken);
                }
            }
コード例 #10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            _closeViewToken = this.Services().MessengerHub.Subscribe <CloseViewsToRoot>(m => Finish());
        }
コード例 #11
0
 public void Dispose()
 {
     _subToConfig?.Dispose();
     _subToConfig = null;
     Clear();
 }
コード例 #12
0
 public TokenContainer(TinyMessageSubscriptionToken token, Type messageType)
 {
     Token       = token;
     MessageType = messageType;
 }
コード例 #13
0
ファイル: DraggingState.cs プロジェクト: AlexMeuer/Rubik
 protected override void OnEnter()
 {
     dragProgressSubscriptionToken = MessengerHub.Subscribe <DragProgressMessage>(OnDragProgress);
     dragEndSubscriptionToken      = MessengerHub.Subscribe <DragEndMessage>(OnDragEnd);
 }
        public void Ctor_InvalidMessageType_ThrowsArgumentOutOfRangeException()
        {
            var messenger = UtilityMethods.GetMessenger();

            var token = new TinyMessageSubscriptionToken(messenger, typeof(object));
        }
コード例 #15
0
 public MouseDragListener(ITinyMessengerHub messengerHub)
 {
     this.messengerHub       = messengerHub;
     updateSubscriptionToken = messengerHub.Subscribe <UpdateMessage>(m => Poll());
 }
コード例 #16
0
 public NamedPipeServer(ILogger logger, ITinyMessengerHub hub) : base(logger, hub, NamedPipes.ServerPipe)
 {
     _subToStart = hub.Subscribe <OnStartupMessage>(_ => StartServer());
     _subToStop  = hub.Subscribe <OnStopMessage>(_ => StopServer());
 }
コード例 #17
0
 public void Unsubscribe(ref TinyMessageSubscriptionToken token)
 {
     Messages.Instance.Unsubscribe(token);
     messageTokens.Remove(token);
     token = null;
 }
コード例 #18
0
ファイル: TinyMessenger.cs プロジェクト: Stjerneklar/2DGame
 /// <summary>
 /// Unsubscribe from a particular message type.
 ///
 /// Does not throw an exception if the subscription is not found.
 /// </summary>
 /// <param name="subscriptionToken">Subscription token received from Subscribe</param>
 public void Unsubscribe(TinyMessageSubscriptionToken subscriptionToken)
 {
     RemoveSubscriptionInternal <ITinyMessage>(subscriptionToken);
 }
コード例 #19
0
 public ServiceChecker(ITinyMessengerHub hub)
 {
     _hub        = hub;
     _subToOpen  = _hub.Subscribe <FormOpenedMessage>(StartChecker);
     _subToClose = _hub.Subscribe <FormClosingMessage>(StopChecker);
 }
コード例 #20
0
ファイル: NamedPipeClient.cs プロジェクト: jmg999/LBCService
 public void Dispose()
 {
     _subToSend?.Dispose();
     _subToSend = null;
 }
        public void Ctor_NullHub_ThrowsArgumentNullException()
        {
            var messenger = UtilityMethods.GetMessenger();

            var token = new TinyMessageSubscriptionToken(null, typeof(ITinyMessage));
        }
コード例 #22
0
 void OnEnable()
 {
     resetToken = MessageHub.Subscribe <ResetMessage>(OnResetRequested);
 }
        public void Ctor_ValidHubAndMessageType_DoesNotThrow()
        {
            var messenger = UtilityMethods.GetMessenger();

            var token = new TinyMessageSubscriptionToken(messenger, typeof(TestMessage));
        }
コード例 #24
0
 protected override void OnEnter()
 {
     subscriptionToken = MessengerHub.Subscribe <MouseDownMessage>(OnMouseDown);
 }
コード例 #25
0
 public void Unsubscribe <TMessage>(TinyMessageSubscriptionToken token)
     where TMessage : class, ITinyMessage
 {
     hub.Unsubscribe <TMessage>(token);
 }
コード例 #26
0
 public SubscribingTimer(ITinyMessengerHub messengerHub)
 {
     this.messengerHub      = messengerHub;
     pauseSubscriptionToken = messengerHub.Subscribe <SetPausedMessage>(OnGamePauseMessage);
 }
コード例 #27
0
 private void Start()
 {
     _subscription = EventBus.Subscribe <GameStateChanged>(OnGameStateChanged);
     SwitchToCamera(1); // switch to static camera
 }
コード例 #28
0
 public void Start()
 {
     updateSubscriptionToken?.Dispose();
     updateSubscriptionToken = messengerHub.Subscribe <UpdateMessage>(OnUpdate);
 }
コード例 #29
0
ファイル: HoloNet.cs プロジェクト: nolikenet/holonet
 public static void Unsubscribe <TMessage>(TinyMessageSubscriptionToken token)
     where TMessage : HoloNetGlobalMessage
 {
     HoloNetAppModule.instance.messenger.Unsubscribe <TMessage>(token);
 }
コード例 #30
0
 public void Stop()
 {
     updateSubscriptionToken?.Dispose();
     updateSubscriptionToken = null;
 }