public DualBootViewModel(IDeploymentContext context, IContextDialog dialogService, IOperationContext operationContext) { this.context = context; var isChangingDualBoot = new Subject <bool>(); UpdateStatusWrapper = new CommandWrapper <Unit, DualBootStatus>(this, ReactiveCommand.CreateFromTask(GetStatus, isChangingDualBoot), dialogService, operationContext); UpdateStatusWrapper.Command.Subscribe(x => { IsCapable = x.CanDualBoot; IsEnabled = x.IsEnabled; IsUpdated = true; }); var canChangeDualBoot = UpdateStatusWrapper.Command.IsExecuting.Select(isExecuting => !isExecuting); EnableDualBootWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(EnableDualBoot, this.WhenAnyValue(x => x.IsCapable, x => x.IsEnabled, (isCapable, isEnabled) => isCapable && !isEnabled) .Merge(canChangeDualBoot)), dialogService, operationContext); EnableDualBootWrapper.Command.Subscribe(async _ => { await dialogService.ShowAlert(this, Resources.Done, Resources.DualBootEnabled); IsEnabled = !IsEnabled; }); DisableDualBootWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(DisableDualBoot, this.WhenAnyValue(x => x.IsCapable, x => x.IsEnabled, (isCapable, isEnabled) => isCapable && isEnabled) .Merge(canChangeDualBoot)), dialogService, operationContext); DisableDualBootWrapper.Command.Subscribe(async _ => { await dialogService.ShowAlert(this, Resources.Done, Resources.DualBootDisabled); IsEnabled = !IsEnabled; }); DisableDualBootWrapper.Command.IsExecuting.Select(x => !x).Subscribe(isChangingDualBoot); EnableDualBootWrapper.Command.IsExecuting.Select(x => !x).Subscribe(isChangingDualBoot); IsBusyObservable = Observable.Merge(DisableDualBootWrapper.Command.IsExecuting, EnableDualBootWrapper.Command.IsExecuting, UpdateStatusWrapper.Command.IsExecuting); }
public FolderNode(IContextDialog dialog) { OpenCommand = ReactiveCommand.Create(() => Process.Start(Path)); OpenCommand.ThrownExceptions.Subscribe(async ex => await dialog.ShowAlert(this, "Error", "Cannot open the script")); }