Esempio n. 1
0
        void _OnRawCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                // If an item got added, was it something we care to see?
                Assert.AreEqual(1, e.NewItems.Count);
                var newPost = (ActivityPost)e.NewItems[0];
                if (_IsInteresting(newPost.Actor))
                {
                    _filteredCollection.Add(newPost);
                    _interestMap[newPost.Actor] = true;
                }
                break;

            case NotifyCollectionChangedAction.Move:
                _filteredCollection.RefreshSort();
                break;

            case NotifyCollectionChangedAction.Remove:
                // If an item got removed, was it one we were really showing?
                Assert.AreEqual(1, e.OldItems.Count);
                var oldPost = (ActivityPost)e.OldItems[0];
                if (_IsInteresting(oldPost.Actor))
                {
                    if (_filteredCollection.Remove(oldPost))
                    {
                        if (!_filteredCollection.Any(post => post.Actor.UserId == oldPost.Actor.UserId))
                        {
                            oldPost.Actor.PropertyChanged -= _OnContactPropertyChanged;
                            _interestMap.Remove(oldPost.Actor);
                        }
                    }
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                // Unsupported
                Assert.Fail();
                break;

            case NotifyCollectionChangedAction.Reset:
                foreach (var contact in _interestMap.Keys)
                {
                    contact.PropertyChanged -= _OnContactPropertyChanged;
                }

                _interestMap.Clear();
                _filteredCollection.Clear();

                break;
            }
        }
Esempio n. 2
0
        void IMergeable <FacebookObjectId, ActivityPost> .Merge(ActivityPost other)
        {
            Verify.IsNotNull(other, "other");
            Verify.AreEqual(PostId, other.PostId, "other", "Can't merge two ActivityPosts with different Ids.");

            if (object.ReferenceEquals(this, other))
            {
                return;
            }

            Assert.AreEqual(ActorUserId, other.ActorUserId);
            //ActorUserId = other.ActorUserId;
            Assert.AreEqual(TargetUserId, other.TargetUserId);
            //TargetUserId = other.TargetUserId;

            Attachment        = other.Attachment;
            CanComment        = other.CanComment;
            CanLike           = other.CanLike;
            CanRemoveComments = other.CanRemoveComments;
            CommentCount      = other.CommentCount;
            Created           = other.Created;
            HasLiked          = other.HasLiked;
            LikedCount        = other.LikedCount;
            LikeUri           = other.LikeUri;
            Message           = other.Message;
            RawComments.Merge(other.RawComments, false);
            if (_hasGottenMoreComments)
            {
                GetMoreComments();
            }
            else
            {
                _NotifyPropertyChanged("HasMoreComments");
            }

            if (other._mergeableLikers != null && other._mergeableLikers.Count != 0)
            {
                if (this._mergeableLikers == null)
                {
                    _mergeableLikers = new FBMergeableCollection <FacebookContact>(false);
                }
                _mergeableLikers.Merge(other._mergeableLikers, false);
            }
            else if (_mergeableLikers != null)
            {
                _mergeableLikers.Clear();
            }

            Updated = other.Updated;
        }