public RunVM() { Activator = new ViewModelActivator(); Protocol = new RootProtocol(); AutoScale = new ScopeCommand <string>(this, Protocol.AutoScale); Clear = new ScopeCommand <string>(this, Protocol.Clear); Run = new ScopeCommand <string>(this, Protocol.Run); Stop = new ScopeCommand <string>(this, Protocol.Stop); SingleTrigger = new ScopeCommand <string>(this, Protocol.Single); ForceTrigger = new ScopeCommand <string>(this, Protocol.Force); Status = new ScopeCommand <string>(this, Protocol.Status, "AUTO"); AllScopeCommands = new List <IScopeCommand> { AutoScale, Clear, Run, Stop, SingleTrigger, ForceTrigger, }; this.WhenActivated(disposables => { this.HandleActivation(); Disposable .Create(() => this.HandleDeactivation()) .DisposeWith(disposables); var statusTimer = Observable.Interval(TimeSpan.FromMilliseconds(1000)) .ToSignal() .ObserveOn(RxApp.MainThreadScheduler) .InvokeCommand(Status.GetCommand); }); }
private IConsensusProtocol?EnsureProtocol(IProtocolIdentifier id) { ValidateId(id); if (_registry.TryGetValue(id, out var existingProtocol)) { return(existingProtocol); } Logger.LogTrace($"Creating protocol {id} on demand"); if (_terminated) { Logger.LogTrace($"Protocol {id} not created since broadcaster is terminated"); return(null); } switch (id) { case BinaryBroadcastId bbId: var bb = new BinaryBroadcast(bbId, _validators, this); RegisterProtocols(new[] { bb }); return(bb); case CoinId coinId: var coin = new CommonCoin( coinId, _validators, _wallet.GetThresholdSignatureKeyForBlock((ulong)_era - 1) ?? throw new InvalidOperationException($"No TS keys present for era {_era}"), this ); RegisterProtocols(new[] { coin }); return(coin); case ReliableBroadcastId rbcId: var rbc = new ReliableBroadcast(rbcId, _validators, this); RegisterProtocols(new[] { rbc }); return(rbc); case BinaryAgreementId baId: var ba = new BinaryAgreement(baId, _validators, this); RegisterProtocols(new[] { ba }); return(ba); case CommonSubsetId acsId: var acs = new CommonSubset(acsId, _validators, this); RegisterProtocols(new[] { acs }); return(acs); case HoneyBadgerId hbId: var hb = new HoneyBadger( hbId, _validators, _wallet.GetTpkePrivateKeyForBlock((ulong)_era - 1) ?? throw new InvalidOperationException($"No TPKE keys present for era {_era}"), this ); RegisterProtocols(new[] { hb }); return(hb); case RootProtocolId rootId: var root = new RootProtocol(rootId, _validators, _wallet.EcdsaKeyPair.PrivateKey, this, _validatorAttendanceRepository, StakingContract.CycleDuration, HardforkHeights.IsHardfork_9Active((ulong)_era)); RegisterProtocols(new[] { root }); return(root); default: throw new Exception($"Unknown protocol type {id}"); } }