private static ReactiveCommand FireCommands( ICommandPublisher bus, IEnumerable <Func <Command> > commands, IObservable <bool> canExecute = null, IScheduler scheduler = null, string userErrorMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { if (scheduler == null) { scheduler = RxApp.MainThreadScheduler; } Func <object, Task> task = async _ => await Task.Run(() => { foreach (var func in commands) { bus.Send(func(), userErrorMsg, responseTimeout, ackTimeout); } }); var cmd = ReactiveCommand.CreateFromTask(task, canExecute, scheduler); cmd.ThrownExceptions #pragma warning disable CS0618 // Type or member is obsolete .SelectMany(ex => UserError.Throw(userErrorMsg, ex)) #pragma warning restore CS0618 // Type or member is obsolete .ObserveOn(MainThreadScheduler).Subscribe(result => { //This will return the recovery option returned from the registered user error handler //right now this is a simple message box in the view code behind /* n.b. this forces evaluation/execution of the select many */ }); return(cmd); }
private static ReactiveCommand <Unit, Unit> SendCommands( ICommandPublisher bus, IEnumerable <Func <Command> > commands, IObservable <bool> canExecute = null, IScheduler scheduler = null, string userErrorMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { if (scheduler == null) { scheduler = RxApp.MainThreadScheduler; } Func <Unit, Task> task = async _ => await Task.Run(() => { foreach (var func in commands) { bus.Send(func(), userErrorMsg, responseTimeout, ackTimeout); } }); var cmd = canExecute == null? ReactiveCommand.CreateFromTask(task, outputScheduler : scheduler) : ReactiveCommand.CreateFromTask(task, canExecute, scheduler); cmd.ThrownExceptions .SelectMany(ex => Interactions.Errors.Handle(new UserError(userErrorMsg ?? ex.Message, ex))) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(result => { // This will return the recovery option returned from the registered user error handler, // e.g. a simple message box in the view code behind /* n.b. this forces evaluation/execution of the select many */ }); return(cmd); }