public TestControlsViewModel( INyxBorg borg, IConfigManager config ) { PingCommand = ReactiveCommand.Create <object, Unit>(_ => { for (int i = 0; i < PingCount; i++) { borg.SendMessage(NyxMessage.Create("nyx", BasicHubAction.Ping, borg.NodeId)); } return(Unit.Default); }); SendActionCommand = ReactiveCommand.Create <object, Unit>(_ => { borg.SendMessage(NyxMessage.Create(ActionTarget, ActionText, string.IsNullOrWhiteSpace(ActionSource) ? borg.NodeId : ActionSource)); return(Unit.Default); }); ConnectCommand = ReactiveCommand.Create <object, Unit>(_ => { borg.Connect(ConnectionIp); return(Unit.Default); }); _connectionIp = config.Get("borg_hubIp", "127.0.0.1"); config.WhenConfigChanges .Throttle(TimeSpan.FromMilliseconds(200), ThreadPoolScheduler.Instance) .Where(k => k.Keys.Contains("borg_hubIp")) .Select(k => k.Sender.Get("borg_hubIp", "127.0.0.1")) .DistinctUntilChanged() .ObserveOnDispatcher() .Subscribe(s => ConnectionIp = s); borg.ConnectionStatusStream .ObserveOnDispatcher() .Subscribe(c => { IsConnected = c.HasFlag(ConnectionStatus.Connected); }); ValidActions = PluginManager.Instance .GetExtensions() .OfType <INyxMessageActions>() .SelectMany(_ => _.SupportedActions).ToList(); }
public void SubscribeUpdates() { if (_borg == null) { throw new NullReferenceException("This must run on a borg."); } NyxMessage.Create("nyx", NodesUpdateSubscribe, _borg.NodeId).SendMessage(_borg); _subscriptionDisposable.Disposable = _internalHubWatch .Where(o => o) .Throttle(TimeSpan.FromSeconds(10)) .ObserveOnPool() .Subscribe(o => { _logger.Debug("Subscribe update from hub after lost connection."); NyxMessage.Create("nyx", NodesUpdateSubscribe, _borg.NodeId).SendMessage(_borg); }); }