Example #1
0
        public UserInfoViewModel(SearchFlipViewModel parent, string screenName)
        {
            this._parent = parent;
            this._screenName = screenName;
            this.CompositeDisposable.Add(
                parent.ListenPropertyChanged(() => parent.DisplaySlimView)
                      .Subscribe(_ => RaisePropertyChanged(() => DisplaySlimView)));
            this.CompositeDisposable.Add(
                StoreHelper.GetUser(screenName)
                           .Finally(() => Communicating = false)
                           .ObserveOnDispatcher()
                           .Subscribe(
                               user =>
                               {
                                   User = new UserViewModel(user);
                                   this.CompositeDisposable.Add(User);

                                   this.CompositeDisposable.Add(this._statuses = new UserTimelineViewModel(this,
                                       new UserTimelineModel(user.Id, TimelineType.User)));
                                   this.RaisePropertyChanged(() => Statuses);

                                   this.CompositeDisposable.Add(this._favorites = new UserTimelineViewModel(this,
                                       new UserTimelineModel(user.Id, TimelineType.Favorites)));
                                   this.RaisePropertyChanged(() => Favorites);

                                   this.CompositeDisposable.Add(this._following = new UserFollowingViewModel(this));
                                   this.RaisePropertyChanged(() => Following);

                                   this.CompositeDisposable.Add(this._followers = new UserFollowersViewModel(this));
                                   this.RaisePropertyChanged(() => Followers);

                                   Setting.Accounts.Collection
                                          .Where(a => a.Id != user.Id)
                                          .Select(a => new RelationControlViewModel(this, a, user))
                                          .ForEach(RelationControls.Add);
                               },
                               ex =>
                               {
                                   parent.Messenger.RaiseSafe(() => new TaskDialogMessage(new TaskDialogOptions
                                   {
                                       Title = SearchFlipResources.MsgUserInfoLoadErrorTitle,
                                       MainIcon = VistaTaskDialogIcon.Error,
                                       MainInstruction = SearchFlipResources.MsgUserInfoLoadErrorInst,
                                       Content = ex.Message,
                                       CommonButtons = TaskDialogCommonButtons.Close
                                   }));
                                   User = null;
                                   parent.CloseResults();
                               }));
        }
Example #2
0
 public UserInfoViewModel(SearchFlipViewModel parent, string screenName)
 {
     this._parent = parent;
     this._screenName = screenName;
     var cd = new CompositeDisposable();
     this.CompositeDisposable.Add(cd);
     cd.Add(
         StoreHelper.GetUser(screenName)
                    .Finally(() => Communicating = false)
                    .ObserveOnDispatcher()
                    .Subscribe(
                        user =>
                        {
                            User = new UserViewModel(user);
                            var ps = this._statuses;
                            var usm = new UserTimelineModel(user.Id, TimelineType.User);
                            this._statuses = new UserTimelineViewModel(this, usm);
                            this.RaisePropertyChanged(() => Statuses);
                            cd.Add(_statuses);
                            if (ps != null)
                            {
                                ps.Dispose();
                            }
                            var pf = this._favorites;
                            var ufm = new UserTimelineModel(user.Id, TimelineType.Favorites);
                            this._favorites = new UserTimelineViewModel(this, ufm);
                            this.RaisePropertyChanged(() => Favorites);
                            cd.Add(_favorites);
                            if (pf != null)
                            {
                                pf.Dispose();
                            }
                            var pfw = this._following;
                            this._following = new UserFollowingViewModel(this);
                            this.RaisePropertyChanged(() => Following);
                            cd.Add(_following);
                            if (pfw != null)
                            {
                                pfw.Dispose();
                            }
                            var pfr = this._followers;
                            this._followers = new UserFollowersViewModel(this);
                            this.RaisePropertyChanged(() => Followers);
                            cd.Add(_followers);
                            if (pfr != null)
                            {
                                pfr.Dispose();
                            }
                            Setting.Accounts.Collection
                                   .Where(a => a.Id != user.Id)
                                   .Select(a => new RelationControlViewModel(this, a, user))
                                   .ForEach(RelationControls.Add);
                        },
                        ex =>
                        {
                            parent.Messenger.Raise(new TaskDialogMessage(new TaskDialogOptions
                            {
                                Title = "ユーザー表示エラー",
                                MainIcon = VistaTaskDialogIcon.Error,
                                MainInstruction = "ユーザーを表示できません。",
                                Content = ex.Message,
                                CommonButtons = TaskDialogCommonButtons.Close
                            }));
                            User = null;
                            parent.CloseResults();
                        }));
 }
        private async void LoadUser(string screenName)
        {
            try
            {
                var user = await StoreHelper.GetUserAsync(screenName);
                // overwrite by oficially-provided screen name
                this._screenName = user.ScreenName;
                RaisePropertyChanged(() => ScreenName);

                User = new UserViewModel(user);
                this.CompositeDisposable.Add(User);

                Setting.Accounts.Collection
                       .Where(a => a.Id != user.Id)
                       .Select(a => new RelationControlViewModel(this, a, user))
                       .ForEach(RelationControls.Add);

                this.CompositeDisposable.Add(this._statuses = new UserTimelineViewModel(this,
                    new UserTimelineModel(user.Id, TimelineType.User)));
                this.RaisePropertyChanged(() => Statuses);

                this.CompositeDisposable.Add(this._favorites = new UserTimelineViewModel(this,
                    new UserTimelineModel(user.Id, TimelineType.Favorites)));
                this.RaisePropertyChanged(() => Favorites);

                this.CompositeDisposable.Add(this._following = new UserFollowingViewModel(this));
                this.RaisePropertyChanged(() => Following);

                this.CompositeDisposable.Add(this._followers = new UserFollowersViewModel(this));
                this.RaisePropertyChanged(() => Followers);
            }
            catch (Exception ex)
            {
                _parent.Messenger.RaiseSafe(() => new TaskDialogMessage(new TaskDialogOptions
                {
                    Title = SearchFlipResources.MsgUserInfoLoadErrorTitle,
                    MainIcon = VistaTaskDialogIcon.Error,
                    MainInstruction =
                        SearchFlipResources.MsgUserInfoLoadErrorInstFormat.SafeFormat(
                            SearchFlipResources.MsgUserProfile),
                    Content = ex.Message,
                    CommonButtons = TaskDialogCommonButtons.Close
                }));
                User = null;
                _parent.CloseResults();
            }
            finally
            {
                Communicating = false;
            }
        }