private void FindValidHub() { if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "Nyx Borg Hub Finder"; } _runningClient = true; _stop = false; Thread.Sleep(TimeSpan.FromSeconds(2)); Interlocked.MemoryBarrier(); // First try the last ip. if (_borg.IsStarted && !string.IsNullOrWhiteSpace(_hubLastIp)) { var s = _borg.ConnectionStatusStream.SkipWhile(c => c.HasFlag(ConnectionStatus.Connecting)).Latest().First(); if (s.HasFlag(ConnectionStatus.Online) && s.HasFlag(ConnectionStatus.Disconnected)) { _logger.Trace($"Trying hub ip {_hubLastIp} ..."); if (!_borg.Connect(_hubLastIp, _hubPort)) { _logger.Trace("Last hub ip failed..."); } } Thread.Sleep(TimeSpan.FromSeconds(5)); } while (!_stop) { try { BroadcastSearchPacker().Wait(_cancelationToken.Token); } catch (TaskCanceledException) { break; } catch (Exception ex) { _logger.Trace(ex.ToString()); Thread.Sleep(TimeSpan.FromSeconds(2)); } } _runningClient = false; }
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(); }