public UserLockoutInfoViewModel()
        {
            SetUser = ReactiveCommand.CreateFromObservable <string, UserObject>(username => _adFacade.GetUser(username, TaskPoolScheduler.Default));

            GetLockoutInfo = ReactiveCommand.Create <Unit, IObservable <LockoutInfo> >(_ => _adFacade.GetLockoutInfo(_user.Value.CN, TaskPoolScheduler.Default));

            Close = ReactiveCommand.Create(_closeAction);

            _user = SetUser
                    .ToProperty(this, vm => vm.User);

            this.WhenActivated(disposables =>
            {
                GetLockoutInfo
                .Do(_ => _lockoutInfos.Clear())
                .Switch()
                .ObserveOnDispatcher()
                .Subscribe(lockoutInfo => _lockoutInfos.Add(lockoutInfo))
                .DisposeWith(disposables);

                Observable.Merge <(string Title, string Message)>(
                    SetUser.ThrownExceptions.Select(ex => ("Could not load user", ex.Message)),
                    GetLockoutInfo.ThrownExceptions.Select(ex => ("Could not get lockout info", ex.Message)),
                    Close.ThrownExceptions.Select(ex => ("Could not close dialog", ex.Message)))
                .SelectMany(dialogContent => _messages.Handle(new MessageInfo(MessageType.Error, dialogContent.Message, dialogContent.Title)))
                .Subscribe()
                .DisposeWith(disposables);
            });
        }
Ejemplo n.º 2
0
        public UserWindowViewModel()
        {
            SetUser = ReactiveCommand.CreateFromObservable <string, UserObject>(identity => Locator.Current.GetService <ADFacade>().GetUser(identity));

            _user = SetUser
                    .ToProperty(this, vm => vm.User);

            this.WhenActivated(disposables =>
            {
                SetUser
                .ThrownExceptions
                .SelectMany(ex => _messages.Handle(new MessageInfo(MessageType.Error, ex.Message, "Could not load user")))
                .Subscribe()
                .DisposeWith(disposables);
            });
        }