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)); } }
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(); }); }
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(); }); }
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); } } } }
/// <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); }
/// <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; }
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(); } }
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); }
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); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); _closeViewToken = this.Services().MessengerHub.Subscribe <CloseViewsToRoot>(m => Finish()); }
public void Dispose() { _subToConfig?.Dispose(); _subToConfig = null; Clear(); }
public TokenContainer(TinyMessageSubscriptionToken token, Type messageType) { Token = token; MessageType = messageType; }
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)); }
public MouseDragListener(ITinyMessengerHub messengerHub) { this.messengerHub = messengerHub; updateSubscriptionToken = messengerHub.Subscribe <UpdateMessage>(m => Poll()); }
public NamedPipeServer(ILogger logger, ITinyMessengerHub hub) : base(logger, hub, NamedPipes.ServerPipe) { _subToStart = hub.Subscribe <OnStartupMessage>(_ => StartServer()); _subToStop = hub.Subscribe <OnStopMessage>(_ => StopServer()); }
public void Unsubscribe(ref TinyMessageSubscriptionToken token) { Messages.Instance.Unsubscribe(token); messageTokens.Remove(token); token = null; }
/// <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); }
public ServiceChecker(ITinyMessengerHub hub) { _hub = hub; _subToOpen = _hub.Subscribe <FormOpenedMessage>(StartChecker); _subToClose = _hub.Subscribe <FormClosingMessage>(StopChecker); }
public void Dispose() { _subToSend?.Dispose(); _subToSend = null; }
public void Ctor_NullHub_ThrowsArgumentNullException() { var messenger = UtilityMethods.GetMessenger(); var token = new TinyMessageSubscriptionToken(null, typeof(ITinyMessage)); }
void OnEnable() { resetToken = MessageHub.Subscribe <ResetMessage>(OnResetRequested); }
public void Ctor_ValidHubAndMessageType_DoesNotThrow() { var messenger = UtilityMethods.GetMessenger(); var token = new TinyMessageSubscriptionToken(messenger, typeof(TestMessage)); }
protected override void OnEnter() { subscriptionToken = MessengerHub.Subscribe <MouseDownMessage>(OnMouseDown); }
public void Unsubscribe <TMessage>(TinyMessageSubscriptionToken token) where TMessage : class, ITinyMessage { hub.Unsubscribe <TMessage>(token); }
public SubscribingTimer(ITinyMessengerHub messengerHub) { this.messengerHub = messengerHub; pauseSubscriptionToken = messengerHub.Subscribe <SetPausedMessage>(OnGamePauseMessage); }
private void Start() { _subscription = EventBus.Subscribe <GameStateChanged>(OnGameStateChanged); SwitchToCamera(1); // switch to static camera }
public void Start() { updateSubscriptionToken?.Dispose(); updateSubscriptionToken = messengerHub.Subscribe <UpdateMessage>(OnUpdate); }
public static void Unsubscribe <TMessage>(TinyMessageSubscriptionToken token) where TMessage : HoloNetGlobalMessage { HoloNetAppModule.instance.messenger.Unsubscribe <TMessage>(token); }
public void Stop() { updateSubscriptionToken?.Dispose(); updateSubscriptionToken = null; }