コード例 #1
0
        internal void NotifyCommitComplete(AsyncCommitInfo asyncCommitInfo)
        {
            if (asyncCommitInfo.VirtualizedItemInfos.Length < 1)
            {
                throw new DataGridInternalException();
            }

            int indexForItemInPage = asyncCommitInfo.VirtualizedItemInfos[0].Index;

            // We do not want to move the page we are about flag has committed to the front since it does not count as a legitimate user-access.
            // It will get moved to the front when one of its items is accessed.
            VirtualPage page = null;

            page = this.GetPageOrDefaultForItemIndex(indexForItemInPage, true);

            if (page == null)
            {
                throw new InvalidOperationException("An attempt was made to retrieve a page does not exist.");
            }

            if ((!this.HasPagePendingCommit) || (!page.IsCommitPending))
            {
                throw new InvalidOperationException("An attempt was made to commit a page that does not have a pending commit operation.");
            }

            Debug.Assert(page.IsDirty);

            page.EndCommitItems(asyncCommitInfo);

            // If we no longer have any pages pending commit.
            if (!this.HasPagePendingCommit)
            {
                // CleanUp and queue a request to fill empty pages from the start of the queue.
                m_pagingManager.CleanUpAndDisposeUnused();

                // This is a failsafe, to make sure that during the clean-up other commit were not queued.
                if (!this.HasPagePendingCommit)
                {
                    if (!this.IsRestarting)
                    {
                        // After the call to cleanup, there should only be LOCKED pending fill pages remaining.  Those are the one to refetch.
                        List <VirtualPage> lockedPages = this.GetLockedPages();
                        int lockedPageCount            = lockedPages.Count;

                        for (int i = 0; i < lockedPageCount; i++)
                        {
                            VirtualPage lockedPage = lockedPages[i];

                            if (lockedPage.IsFilled)
                            {
                                continue;
                            }

                            // The locked page has been created while commit was pending.  Let's queue its query data operation.
                            m_pagingManager.QueueQueryData(lockedPage);
                        }
                    }
                    else
                    {
                        // We just completed the last commit operation for a Restart request.
                        // Send another reset action which will in turn call another restart request.
                        // This time, no pages should have to be committed and the restart will end correctly, synchronously with the reset.

                        //this.OnCollectionChanged( new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Reset ) );
                        this.Restart();
                    }
                }
            }
        }