public void Test_SourceNcc_CollectionChanged_Remove()
        {
            // Create ref list with all test items:
            List <SampleClass> refList = new List <SampleClass>();

            for (int e = 0; e < 100; e++)
            {
                refList.Add(new SampleClass(e));
            }

            ObservableCollection <SampleClass> col = new ObservableCollection <SampleClass>();
            AdvancedCollectionView             acv = new AdvancedCollectionView(col, true);

            // Add all items to collection:
            foreach (var item in refList)
            {
                col.Add(item);
            }

            // Remove all items from collection while DeferRefresh() is active:
            using (acv.DeferRefresh())
            {
                while (col.Count > 0)
                {
                    col.RemoveAt(0);
                }
            }

            // Check if unsubscribed from all items:
            foreach (var item in refList)
            {
                Assert.IsTrue(item.GetPropertyChangedEventHandlerSubscriberLength() == 0);
            }
        }
예제 #2
0
        public VideoCommentSidePaneContentViewModel(
            VideoCommentPlayer commentPlayer,
            CommentFilteringFacade commentFiltering,
            Services.DialogService dialogService
            )
        {
            CommentPlayer    = commentPlayer;
            CommentFiltering = commentFiltering;
            _dialogService   = dialogService;
            Comments         = new AdvancedCollectionView(CommentPlayer.Comments, true);

            HandleCommentFilterConditionChanged();

            void HandleCommentFilterConditionChanged()
            {
#pragma warning disable IDISP004 // Don't ignore created IDisposable.
                new[]
                {
                    Observable.FromEventPattern <CommentFilteringFacade.CommentOwnerIdFilteredEventArgs>(
                        h => CommentFiltering.FilteringCommentOwnerIdAdded += h,
                        h => CommentFiltering.FilteringCommentOwnerIdAdded -= h
                        ).ToUnit(),
                    Observable.FromEventPattern <CommentFilteringFacade.CommentOwnerIdFilteredEventArgs>(
                        h => CommentFiltering.FilteringCommentOwnerIdRemoved += h,
                        h => CommentFiltering.FilteringCommentOwnerIdRemoved -= h
                        ).ToUnit(),

                    Observable.FromEventPattern <CommentFilteringFacade.FilteringCommentTextKeywordEventArgs>(
                        h => CommentFiltering.FilterKeywordAdded += h,
                        h => CommentFiltering.FilterKeywordAdded -= h
                        ).ToUnit(),
                    Observable.FromEventPattern <CommentFilteringFacade.FilteringCommentTextKeywordEventArgs>(
                        h => CommentFiltering.FilterKeywordUpdated += h,
                        h => CommentFiltering.FilterKeywordUpdated -= h
                        ).ToUnit(),
                    Observable.FromEventPattern <CommentFilteringFacade.FilteringCommentTextKeywordEventArgs>(
                        h => CommentFiltering.FilterKeywordRemoved += h,
                        h => CommentFiltering.FilterKeywordRemoved -= h
                        ).ToUnit(),
                }
                .Merge()
                .Subscribe(_ => Comments.RefreshFilter())
#pragma warning restore IDISP004 // Don't ignore created IDisposable.
                .AddTo(_disposables);

                using (Comments.DeferRefresh())
                {
                    Comments.SortDescriptions.Add(new SortDescription("VideoPosition", SortDirection.Ascending));
                    Comments.Filter = (c) => !isCommentFiltered(c as VideoComment);
                }
            }
        }
예제 #3
0
        private void LoadChats()
        {
            // Subscribe to chat and MUC info changed events:
            ChatDBManager.INSTANCE.ChatChanged   += INSTANCE_ChatChanged;
            MUCDBManager.INSTANCE.MUCInfoChanged += INSTANCE_MUCInfoChanged;

            ChatDataTemplate        selectedChat = null;
            List <ChatDataTemplate> chats        = LoadChatsFromDB();

            // Clear list:
            CHATS.Clear();

            // Add chats:
            using (CHATS_ACV.DeferRefresh())
            {
                CHATS.AddRange(chats, false);
            }
            if (SelectedItem is null && selectedChat != null)
            {
                SelectedItem = selectedChat;
            }
        }