public ScopeCommand(IProtocolVM viewModel, IProtocolCommand protocolCommand, string defaultResponse) { //ViewModel = viewModel; ProtocolCommand = protocolCommand; if (protocolCommand.IsSettable) { var canSet = this.WhenValueChanged(x => x.IsEnabled) .Where(x => x == true); SetCommand = ReactiveCommand.CreateFromTask(SendCommandAsync, canSet); SetCommand.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't set")); Increment = ReactiveCommand.Create(IncrementValue); Increment.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't increment")); Decrement = ReactiveCommand.Create(DecrementValue); Decrement.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't decrement")); } else { // set command is used to send the command without a value or response SetCommand = ReactiveCommand.CreateFromTask(SendCommandAsync); } if (protocolCommand.IsQueryable) { if (App.Mock) { DefaultResponse = defaultResponse; } GetCommand = ReactiveCommand.CreateFromTask(SendQueryAsync); GetCommand.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't query")); } else { if (App.Mock) { DefaultResponse = null; } IsEnabled = true; } }
public ScopeCommand(IProtocolVM viewModel, IProtocolCommand protocolCommand) : this(viewModel, protocolCommand, "") { }