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); })); }
public void NotifyFallbackState(bool isFallbacked) { if (!isFallbacked && !this.IsFallbacked) { return; } Task.Run(() => { this.IsFallbacked = isFallbacked; if (isFallbacked) { // calc prediction var threshold = DateTime.Now - TimeSpan.FromSeconds(Setting.PostWindowTimeSec.Value); var oldest = PostLimitPredictionService.GetStatuses(Account.Id) .Where(t => t.CreatedAt > threshold) .OrderByDescending(t => t.CreatedAt) .Take(Setting.PostLimitPerWindow.Value) // limit count .LastOrDefault(); if (oldest == null) { IsFallbacked = false; FallbackPredictedReleaseTime = DateTime.Now; } else { FallbackPredictedReleaseTime = oldest.CreatedAt + TimeSpan.FromSeconds(Setting.PostWindowTimeSec.Value); // create timer if (_prevScheduled != null) { _prevScheduled.Dispose(); } _prevScheduled = Observable.Timer(FallbackPredictedReleaseTime) .Subscribe(_ => { IsFallbacked = false; this.RaiseFallbackStateUpdated(); }); } } else { FallbackPredictedReleaseTime = DateTime.Now; if (_prevScheduled != null) { _prevScheduled.Dispose(); _prevScheduled = null; } } if (IsFallbacked) { BackstageModel.RegisterEvent(new PostLimitedEvent(Account, FallbackPredictedReleaseTime)); } this.RaiseFallbackStateUpdated(); }); }
public static void PostInitialize() { // initialize subsystems StatisticsService.Initialize(); PostLimitPredictionService.Initialize(); MuteBlockManager.Initialize(); StatusBroadcaster.Initialize(); StatusInbox.Initialize(); AutoUpdateService.StartSchedule(); NotificationService.Initialize(); UINotificationProxy.Initialize(); // activate plugins PluginManager.LoadedPlugins.ForEach(p => p.Initialize()); // activate scripts ScriptingManagerImpl.Initialize(); // other core systems initialize ReceiveManager.Initialize(); TwitterConfigurationService.Initialize(); BackstageModel.Initialize(); }