public NotificationWithActivityViewModel(NotificationInfoWithActivity model, Activity activityModel, DateTime insertTime)
     : base(insertTime)
 {
     _target = new ActivityViewModel(activityModel);
     _targetModel = activityModel;
     _notificationModel = model;
     _notificationModel_Updated(null, null);
     _notificationModel.Updated += _notificationModel_Updated;
 }
Exemplo n.º 2
0
        public ActivityViewModel(Activity activity)
        {
            _model = activity;
            _comments = new ObservableCollection<CommentViewModel>();
            SendCommentCommand = new RelayCommand(SendCommentCommand_Executed);
            CancelCommentCommand = new RelayCommand(CancelCommentCommand_Executed);

            var tsk = Refresh();
            PropertyChanged += ActivityViewModel_PropertyChanged;
        }
Exemplo n.º 3
0
        public async Task<bool> Connect()
        {
            try
            {
                await _syncer.WaitAsync();
                //処理の最初に置くことでConnect()後はストリームの休止状態が終了している事を保証させる
                _isPause = false;

                //接続処理
                switch (Status)
                {
                    case StreamStateType.UnLoaded:
                        //読み込み
                        Status = StreamStateType.Loading;
                        var activities = await _activityGetter.TakeAsync(20);

                        //更新
                        Status = StreamStateType.Initing;
                        var outerActiveActivities = _isPause ? _hiddenActivities : _activities;
                        outerActiveActivities.Clear();
                        foreach (var item in activities)
                            outerActiveActivities.Add(new Activity(item));

                        //受信開始
                        Status = StreamStateType.Connected;
                        _streamObj = Circle.GetStream().Subscribe(async newInfo =>
                            {
                                try
                                {
                                    await _syncer.WaitAsync().ConfigureAwait(false);
                                    //一時停止している場合は外から見えない領域でストリームを更新
                                    //するために_activitiesではなく_tmpActivitiesが更新される
                                    var innerActiveActivities = _isPause ? _hiddenActivities : _activities;
                                    var item = innerActiveActivities.FirstOrDefault(activity => activity.CoreInfo.Id == newInfo.Id);
                                    var existUpdate = false;
                                    switch (newInfo.PostStatus)
                                    {
                                        case PostStatusType.First:
                                        case PostStatusType.Edited:
                                            //itemがnullの場合は更新する。nullでない場合はすでにある値を更新する。
                                            //しかし更新はActivityオブジェクト自体が行うため、Streamでは行わない
                                            if (item == null)
                                            {
                                                existUpdate = true;
                                                item = new Activity(newInfo);
                                                innerActiveActivities.Insert(0, item);
                                                if (innerActiveActivities.Count > MAX_ACTIVITIES_COUNT)
                                                {
                                                    innerActiveActivities[MAX_ACTIVITIES_COUNT].Dispose();
                                                    innerActiveActivities.RemoveAt(MAX_ACTIVITIES_COUNT);
                                                }
                                            }
                                            break;
                                        case PostStatusType.Removed:
                                            innerActiveActivities.Remove(item);
                                            existUpdate = true;
                                            break;
                                    }
                                    if (_isPause && existUpdate)
                                    {
                                        Status = StreamStateType.Paused;
                                        ChangedActivityCount++;
                                    }
                                }
                                finally
                                { _syncer.Release(); }
                            },
                            async ex =>
                            {
                                try
                                {
                                    await _syncer.WaitAsync().ConfigureAwait(false);
                                    _streamObj.Dispose();
                                    _streamObj = null;
                                    Status = StreamStateType.UnLoaded;
                                }
                                finally { _syncer.Release(); }
                            },
                            async () =>
                            {
                                try
                                {
                                    await _syncer.WaitAsync().ConfigureAwait(false);
                                    _streamObj.Dispose();
                                    _streamObj = null;
                                    Status = StreamStateType.UnLoaded;
                                }
                                finally { _syncer.Release(); }
                            });
                        break;
                    case StreamStateType.Paused:
                        Status = StreamStateType.Connected;
                        if (ChangedActivityCount > 0)
                        {
                            int hIdx, aIdx;
                            for (hIdx = 0; hIdx < _hiddenActivities.Count; hIdx++)
                                if ((aIdx = _activities.IndexOf(_hiddenActivities[hIdx])) < 0)
                                    _activities.Insert(hIdx, _hiddenActivities[hIdx]);
                                else if (aIdx != hIdx)
                                    _activities.Move(aIdx, hIdx);
                            for (aIdx = _activities.Count - 1; aIdx >= hIdx; aIdx--)
                                _activities.RemoveAt(aIdx);
                        }
                        //一時停止が終わったらActivityのGC解放のためにも消す
                        _hiddenActivities = null;
                        break;
                }
                return true;
            }
            catch (FailToOperationException)
            {
                Status = StreamStateType.UnLoaded;
                return false;
            }
            finally { _syncer.Release(); }
        }