// Token: 0x060076FF RID: 30463 RVA: 0x00220044 File Offset: 0x0021E244
        private ViewRecord CacheView(object collection, CollectionViewSource cvs, CollectionView cv, ViewRecord vr)
        {
            CollectionRecord collectionRecord = this[collection];
            ViewTable        viewTable        = collectionRecord.ViewTable;

            if (viewTable == null)
            {
                viewTable = new ViewTable();
                collectionRecord.ViewTable = viewTable;
                if (!(collection is INotifyCollectionChanged))
                {
                    this._inactiveViewTables.Add(viewTable, 2);
                }
            }
            if (vr == null)
            {
                vr = new ViewRecord(cv);
            }
            else if (cv == null)
            {
                cv = (CollectionView)vr.View;
            }
            cv.SetViewManagerData(viewTable);
            viewTable[cvs] = vr;
            return(vr);
        }
示例#2
0
        internal void RegisterCollectionSynchronizationCallback(
            IEnumerable collection,
            object context,
            CollectionSynchronizationCallback synchronizationCallback)
        {
            CollectionRecord cr = EnsureCollectionRecord(collection);

            cr.SynchronizationInfo = new SynchronizationInfo(context, synchronizationCallback);

            ViewTable vt = cr.ViewTable;

            if (vt != null)
            {
                bool isSynchronized = cr.SynchronizationInfo.IsSynchronized;
                foreach (DictionaryEntry de in vt)
                {
                    ViewRecord     vr = (ViewRecord)de.Value;
                    CollectionView cv = vr.View as CollectionView;
                    if (cv != null)
                    {
                        cv.SetAllowsCrossThreadChanges(isSynchronized);
                    }
                }
            }
        }
        // Token: 0x06007700 RID: 30464 RVA: 0x002200BC File Offset: 0x0021E2BC
        internal bool Purge()
        {
            int count = this._inactiveViewTables.Count;

            if (count > 0)
            {
                ViewTable[] array = new ViewTable[count];
                this._inactiveViewTables.Keys.CopyTo(array, 0);
                for (int i = 0; i < count; i++)
                {
                    ViewTable key = array[i];
                    int       num = (int)this._inactiveViewTables[key];
                    if (--num > 0)
                    {
                        this._inactiveViewTables[key] = num;
                    }
                    else
                    {
                        this._inactiveViewTables.Remove(key);
                    }
                }
            }
            ArrayList arrayList = new ArrayList();
            bool      flag      = false;

            foreach (object obj in this)
            {
                DictionaryEntry  dictionaryEntry  = (DictionaryEntry)obj;
                WeakRefKey       weakRefKey       = (WeakRefKey)dictionaryEntry.Key;
                CollectionRecord collectionRecord = (CollectionRecord)dictionaryEntry.Value;
                if (weakRefKey.Target == null || !collectionRecord.IsAlive)
                {
                    arrayList.Add(weakRefKey);
                }
                else
                {
                    ViewTable viewTable = collectionRecord.ViewTable;
                    if (viewTable != null && viewTable.Purge())
                    {
                        flag = true;
                        if (viewTable.Count == 0)
                        {
                            collectionRecord.ViewTable = null;
                            if (!collectionRecord.IsAlive)
                            {
                                arrayList.Add(weakRefKey);
                            }
                        }
                    }
                }
            }
            for (int j = 0; j < arrayList.Count; j++)
            {
                base.Remove(arrayList[j]);
            }
            return(arrayList.Count > 0 || flag);
        }
示例#4
0
        // return an existing view (or null if there isn't one) over the collection
        private ViewRecord GetExistingView(object collection, CollectionViewSource cvs, Type collectionViewType, Func <object, object> GetSourceItem)
        {
            ViewRecord     result;
            CollectionView cv = collection as CollectionView;

            if (cv == null)
            {
                // look up cached entry
                CollectionRecord cr = EnsureCollectionRecord(collection, GetSourceItem);
                ViewTable        vt = cr.ViewTable;
                if (vt != null)
                {
                    ViewRecord vr = vt[cvs];
                    if (vr != null)
                    {
                        cv = (CollectionView)vr.View;
                    }
                    result = vr;

                    // activity on the VT - reset its expiration date
                    if (_inactiveViewTables.Contains(vt))
                    {
                        _inactiveViewTables[vt] = InactivityThreshold;
                    }
                }
                else
                {
                    result = null;
                }
            }
            else
            {
                // the collection is already a view, just use it directly (no tables needed)
                result = new ViewRecord(cv);
            }

            if (cv != null)
            {
                ValidateViewType(cv, collectionViewType);
            }

            return(result);
        }
        // Token: 0x060076FA RID: 30458 RVA: 0x0021FEC8 File Offset: 0x0021E0C8
        internal void RegisterCollectionSynchronizationCallback(IEnumerable collection, object context, CollectionSynchronizationCallback synchronizationCallback)
        {
            CollectionRecord collectionRecord = this.EnsureCollectionRecord(collection, null);

            collectionRecord.SynchronizationInfo = new SynchronizationInfo(context, synchronizationCallback);
            ViewTable viewTable = collectionRecord.ViewTable;

            if (viewTable != null)
            {
                bool isSynchronized = collectionRecord.SynchronizationInfo.IsSynchronized;
                foreach (object obj in viewTable)
                {
                    ViewRecord     viewRecord     = (ViewRecord)((DictionaryEntry)obj).Value;
                    CollectionView collectionView = viewRecord.View as CollectionView;
                    if (collectionView != null)
                    {
                        collectionView.SetAllowsCrossThreadChanges(isSynchronized);
                    }
                }
            }
        }
示例#6
0
        private ViewRecord CacheView(object collection, CollectionViewSource cvs, CollectionView cv, ViewRecord vr)
        {
            // create the view table, if necessary
            CollectionRecord cr = this[collection];
            ViewTable        vt = cr.ViewTable;

            if (vt == null)
            {
                vt           = new ViewTable();
                cr.ViewTable = vt;

                // if the collection doesn't implement INCC, it won't hold a strong
                // reference to its views.  To mitigate CollecitonView sorting from being silently
                // discarded, keep a
                // strong reference to the ViewTable alive for at least a few
                // Purge cycles.  (See comment at the top of the file.)
                if (!(collection is INotifyCollectionChanged))
                {
                    _inactiveViewTables.Add(vt, InactivityThreshold);
                }
            }

            // keep the view and the view table alive as long as any view
            // (or the collection itself) is alive
            if (vr == null)
            {
                vr = new ViewRecord(cv);
            }
            else if (cv == null)
            {
                cv = (CollectionView)vr.View;
            }
            cv.SetViewManagerData(vt);

            // add the view to the table
            vt[cvs] = vr;
            return(vr);
        }
        // Token: 0x060076FE RID: 30462 RVA: 0x0021FFC0 File Offset: 0x0021E1C0
        private ViewRecord GetExistingView(object collection, CollectionViewSource cvs, Type collectionViewType, Func <object, object> GetSourceItem)
        {
            CollectionView collectionView = collection as CollectionView;
            ViewRecord     result;

            if (collectionView == null)
            {
                CollectionRecord collectionRecord = this.EnsureCollectionRecord(collection, GetSourceItem);
                ViewTable        viewTable        = collectionRecord.ViewTable;
                if (viewTable != null)
                {
                    ViewRecord viewRecord = viewTable[cvs];
                    if (viewRecord != null)
                    {
                        collectionView = (CollectionView)viewRecord.View;
                    }
                    result = viewRecord;
                    if (this._inactiveViewTables.Contains(viewTable))
                    {
                        this._inactiveViewTables[viewTable] = 2;
                    }
                }
                else
                {
                    result = null;
                }
            }
            else
            {
                result = new ViewRecord(collectionView);
            }
            if (collectionView != null)
            {
                this.ValidateViewType(collectionView, collectionViewType);
            }
            return(result);
        }
示例#8
0
        // purge the table of dead entries 
        internal bool Purge()
        {
            // decrease the expiration dates of ViewTables on the inactive
            // list, and remove the ones that have expired. 
            int n = _inactiveViewTables.Count;
            if (n > 0) 
            { 
                ViewTable[] keys = new ViewTable[n];
                _inactiveViewTables.Keys.CopyTo(keys, 0); 

                for (int i=0; i<n; ++i)
                {
                    ViewTable vt = keys[i]; 
                    int expirationDate = (int)_inactiveViewTables[vt];
                    if (--expirationDate > 0) 
                    { 
                        _inactiveViewTables[vt] = expirationDate;
                    } 
                    else
                    {
                        _inactiveViewTables.Remove(vt);
                    } 
                }
            } 
 
            // purge the table of entries whose collection has been GC'd.
            ArrayList al = new ArrayList(); 

            foreach (DictionaryEntry de in this)
            {
                WeakRefKey key = (WeakRefKey)de.Key; 
                WeakReference wr = (WeakReference)de.Value;
 
                if (key.Target == null || !wr.IsAlive) 
                    al.Add(key);
            } 

            for (int k=0; k<al.Count; ++k)
            {
                this.Remove(al[k]); 
            }
 
            return (al.Count > 0); 
        }
示例#9
0
        private ViewRecord CacheView(object collection, CollectionViewSource cvs, CollectionView cv, ViewRecord vr) 
        {
            // create the view table, if necessary 
            ViewTable vt = this[collection]; 
            if (vt == null)
            { 
                vt = new ViewTable();
                Add(collection, vt);

                // if the collection doesn't implement INCC, it won't hold a strong 
                // reference to its views.  To mitigate Dev10 bug 452676, keep a
                // strong reference to the ViewTable alive for at least a few 
                // Purge cycles.  (See comment at the top of the file.) 
                if (!(collection is INotifyCollectionChanged))
                { 
                    _inactiveViewTables.Add(vt, InactivityThreshold);
                }
            }
 
            // keep the view and the view table alive as long as any view
            // (or the collection itself) is alive 
            if (vr == null) 
                vr = new ViewRecord(cv);
            else if (cv == null) 
                cv = (CollectionView)vr.View;
            cv.SetViewManagerData(vt);

            // add the view to the table 
            vt[cvs] = vr;
            return vr; 
        } 
示例#10
0
        //------------------------------------------------------ 
        //
        //  Internal Methods 
        //
        //------------------------------------------------------

        internal void Add(object collection, ViewTable vt) 
        {
            base.Add(new WeakRefKey(collection), new WeakReference(vt)); 
        } 
示例#11
0
        // purge the table of dead entries
        internal bool Purge()
        {
            // decrease the expiration dates of ViewTables on the inactive
            // list, and remove the ones that have expired.
            int n = _inactiveViewTables.Count;

            if (n > 0)
            {
                ViewTable[] keys = new ViewTable[n];
                _inactiveViewTables.Keys.CopyTo(keys, 0);

                for (int i = 0; i < n; ++i)
                {
                    ViewTable vt             = keys[i];
                    int       expirationDate = (int)_inactiveViewTables[vt];
                    if (--expirationDate > 0)
                    {
                        _inactiveViewTables[vt] = expirationDate;
                    }
                    else
                    {
                        _inactiveViewTables.Remove(vt);
                    }
                }
            }

            // purge the table of entries whose collection has been GC'd.
            ArrayList al = new ArrayList();
            bool      foundViewTableDirt = false;

            foreach (DictionaryEntry de in this)
            {
                WeakRefKey       key = (WeakRefKey)de.Key;
                CollectionRecord cr  = (CollectionRecord)de.Value;

                if (key.Target == null || !cr.IsAlive)
                {
                    al.Add(key);
                }
                else
                {
                    // also purge ViewTable entries whose key (CVS) has been GC'd
                    ViewTable vt = cr.ViewTable;
                    if (vt != null && vt.Purge())
                    {
                        foundViewTableDirt = true;
                        if (vt.Count == 0)
                        {
                            // remove the ViewTable (it has no views remaining)
                            cr.ViewTable = null;

                            if (!cr.IsAlive)
                            {
                                al.Add(key);
                            }
                        }
                    }
                }
            }

            for (int k = 0; k < al.Count; ++k)
            {
                this.Remove(al[k]);
            }

            return(al.Count > 0 || foundViewTableDirt);
        }
示例#12
0
        // purge the table of dead entries
        internal bool Purge()
        {
            // decrease the expiration dates of ViewTables on the inactive
            // list, and remove the ones that have expired.
            int n = _inactiveViewTables.Count;
            if (n > 0)
            {
                ViewTable[] keys = new ViewTable[n];
                _inactiveViewTables.Keys.CopyTo(keys, 0);

                for (int i=0; i<n; ++i)
                {
                    ViewTable vt = keys[i];
                    int expirationDate = (int)_inactiveViewTables[vt];
                    if (--expirationDate > 0)
                    {
                        _inactiveViewTables[vt] = expirationDate;
                    }
                    else
                    {
                        _inactiveViewTables.Remove(vt);
                    }
                }
            }

            // purge the table of entries whose collection has been GC'd.
            ArrayList al = new ArrayList();
            bool foundViewTableDirt = false;

            foreach (DictionaryEntry de in this)
            {
                WeakRefKey key = (WeakRefKey)de.Key;
                CollectionRecord cr = (CollectionRecord)de.Value;

                if (key.Target == null || !cr.IsAlive)
                {
                    al.Add(key);
                }
                else
                {
                    // also purge ViewTable entries whose key (CVS) has been GC'd
                    ViewTable vt = cr.ViewTable;
                    if (vt != null && vt.Purge())
                    {
                        foundViewTableDirt = true;
                        if (vt.Count == 0)
                        {
                            // remove the ViewTable (it has no views remaining)
                            cr.ViewTable = null;

                            if (!cr.IsAlive)
                            {
                                al.Add(key);
                            }
                        }
                    }
                }
            }

            for (int k=0; k<al.Count; ++k)
            {
                this.Remove(al[k]);
            }

            return (al.Count > 0 || foundViewTableDirt);
        }