Inheritance: Livet.NotificationObject
Example #1
0
        public async Task Activate()
        {
            try
            {
                await _syncer.WaitAsync();
                if (_notificationTrigger != null)
                    return;

                //通知の監視をする。
                //  Timerの5分おきの処理とGetStream()の通知更新シグナルの受信をMerge()したものを使う。
                //  GetStream()はDefer().Retry()で例外発生時に再接続させる。間にDelaySubscription()を
                //  挟んで再接続の間に1分間の間隔を開ける。初回接続も1分間遅延するが気にしない。
                _notificationTrigger = Observable.Merge(
                        Observable.Interval(TimeSpan.FromMinutes(5)).Select(num => Unit.Default),
                        Observable.Defer(() => _account.PlusClient.Activity.GetStream().OfType<NotificationSignal>().Select(sig => Unit.Default))
                            .DelaySubscription(TimeSpan.FromMinutes(1))
                            .Retry())
                    .Throttle(TimeSpan.FromMinutes(1))
                    .Subscribe(unit => UpdateUnreadItemCount());
                
                UnreadedStream = new NotificationStream(_account.PlusClient.Notification.GetNotifications(true), _account);
                ReadedStream = new NotificationStream(_account.PlusClient.Notification.GetNotifications(false), _account);
                UpdateUnreadItemCount();
            }
            finally { _syncer.Release(); }
        }
 public NotificationStreamViewModel(string name, NotificationStream model)
 {
     _streamModel = model;
     Name = name;
     CompositeDisposable.Add(_modelPropChangedEventListener = new PropertyChangedEventListener(model));
     CompositeDisposable.Add(_thisPropChangedEventListener = new PropertyChangedEventListener(this));
     CompositeDisposable.Add(Items = ViewModelHelper.CreateReadOnlyDispatcherCollection(
         _streamModel.Items, item => WrapViewModel(item, DateTime.UtcNow), App.Current.Dispatcher));
     _modelPropChangedEventListener.Add(() => model.Status, Status_ChangedProperty);
 }