public AccountPanelViewModel() { SetNewPassword = ReactiveCommand.CreateFromObservable( () => SetNewPasswordImpl(_newPassword), this.WhenAnyValue(vm => vm.User, vm => vm.NewPassword, (user, password) => user != null && password.HasValue())); SetNewSimplePassword = ReactiveCommand.CreateFromObservable(SetNewSimplePasswordImpl); SetNewComplexPassword = ReactiveCommand.CreateFromObservable(SetNewComplexPasswordImpl); ExpirePassword = ReactiveCommand.CreateFromObservable(() => Messages.Handle(new MessageInfo(MessageType.Question, "Are you sure you want to expire the password?", "Expire password?", "Yes", "No")) .Where(result => result == 0) .SelectMany(_ => _adFacade.ExpirePassword(User.Principal.SamAccountName))); UnlockAccount = ReactiveCommand.CreateFromObservable(() => _adFacade.UnlockUser(User.Principal.SamAccountName)); RunLockoutStatus = ReactiveCommand.Create(() => ExecutionService.RunFileFromCache("LockoutStatus", "LockoutStatus.exe", $"-u:{_adFacade.CurrentDomain}\\{User.Principal.SamAccountName}")); OpenPermittedWorkstations = ReactiveCommand.CreateFromObservable(() => _dialogRequests.Handle(new DialogInfo(new PermittedWorkstationsDialog(), _user.Principal.SamAccountName))); ToggleEnabled = ReactiveCommand.CreateFromObservable(() => _adFacade.SetEnabled(User.Principal.SamAccountName, !User.Principal.Enabled ?? true)); OpenSplunk = ReactiveCommand.Create(() => { Process.Start(string.Format(Locator.Current.GetService <SettingsFacade>().SplunkUrl, _adFacade.CurrentDomainShortName, User.Principal.SamAccountName)); }); this.WhenActivated(disposables => { SetNewPassword .ObserveOnDispatcher() .Do(_ => NewPassword = "") .SelectMany(newPass => _messages.Handle(new MessageInfo(MessageType.Success, $"New password is: {newPass}", "Password set"))) .Subscribe() .DisposeWith(disposables); SetNewSimplePassword .ObserveOnDispatcher() .SelectMany(newPass => _messages.Handle(MessageInfo.PasswordSetMessageInfo(newPass))) .Subscribe() .DisposeWith(disposables); SetNewComplexPassword .ObserveOnDispatcher() .SelectMany(newPass => _messages.Handle(MessageInfo.PasswordSetMessageInfo(newPass))) .Subscribe() .DisposeWith(disposables); ExpirePassword .SelectMany(_ => _messages.Handle(new MessageInfo(MessageType.Success, "User must change password at next login", "Password expired"))) .Subscribe() .DisposeWith(disposables); UnlockAccount .SelectMany(_ => { MessageBus.Current.SendMessage(_user.CN, ApplicationActionRequest.Refresh); return(_messages.Handle(new MessageInfo(MessageType.Success, "Account unlocked"))); }) .Subscribe() .DisposeWith(disposables); ToggleEnabled .Subscribe(_ => MessageBus.Current.SendMessage(_user.CN, ApplicationActionRequest.Refresh)) .DisposeWith(disposables); Observable.Merge( SetNewPassword.ThrownExceptions, SetNewSimplePassword.ThrownExceptions, SetNewComplexPassword.ThrownExceptions) .SelectMany(ex => _messages.Handle(MessageInfo.PasswordSetErrorMessageInfo(ex.Message))) .Subscribe() .DisposeWith(disposables); Observable.Merge <(string Title, string Message)>( ExpirePassword.ThrownExceptions.Select(ex => ("Could not expire password", ex.Message)), UnlockAccount.ThrownExceptions.Select(ex => ("Could not unlock acount", ex.Message)), RunLockoutStatus.ThrownExceptions.Select(ex => ("Could not open LockOutStatus", ex.Message)), OpenPermittedWorkstations.ThrownExceptions.Select(ex => ("Could not open Permitted Workstations", ex.Message)), ToggleEnabled.ThrownExceptions.Select(ex => ("Could not toggle enabled status", ex.Message))) .SelectMany(dialogContent => _messages.Handle(new MessageInfo(MessageType.Error, dialogContent.Message, dialogContent.Title))) .Subscribe() .DisposeWith(disposables); }); }