public PostLimitPredictionViewModel() { CompositeDisposable.Add( InputModel.AccountSelector.Accounts.ListenCollectionChanged( _ => RaisePropertyChanged(() => IsPostLimitPredictionEnabled))); CompositeDisposable.Add( Observable.Interval(TimeSpan.FromSeconds(5)) .Where(_ => IsPostLimitPredictionEnabled) .Subscribe(_ => { var account = InputModel.AccountSelector.Accounts.FirstOrDefault(); if (account == null) { return; } var count = PostLimitPredictionService.GetCurrentWindowCount(account.Id); MaxUpdate = Setting.PostLimitPerWindow.Value; RemainUpdate = MaxUpdate - count; RaisePropertyChanged(() => RemainUpdate); RaisePropertyChanged(() => MaxUpdate); RaisePropertyChanged(() => ControlWidth); RaisePropertyChanged(() => IsWarningPostLimit); })); }
public BackstageAccountViewModel(BackstageViewModel parent, BackstageAccountModel model) { _parent = parent; _model = model; this.CompositeDisposable.Add( Observable.FromEvent( h => _model.ConnectionStateChanged += h, h => _model.ConnectionStateChanged -= h) .Subscribe(_ => ConnectionStateChanged())); this.CompositeDisposable.Add( Observable.FromEvent( h => _model.TwitterUserChanged += h, h => _model.TwitterUserChanged -= h) .Subscribe(_ => UserChanged())); this.CompositeDisposable.Add( Observable.FromEvent( h => _model.FallbackStateUpdated += h, h => _model.FallbackStateUpdated -= h) .Subscribe(_ => this.FallbackStateUpdated())); this.CompositeDisposable.Add( Observable.Interval(TimeSpan.FromSeconds(5)) .Subscribe(_ => { var count = PostLimitPredictionService.GetCurrentWindowCount(model.Account.Id); MaxUpdate = Setting.PostLimitPerWindow.Value; RemainUpdate = MaxUpdate - count; this.RaisePropertyChanged(() => RemainUpdate); this.RaisePropertyChanged(() => MaxUpdate); this.RaisePropertyChanged(() => IsWarningPostLimit); })); }