// 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); }
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); }
// Token: 0x060076FB RID: 30459 RVA: 0x0021FF70 File Offset: 0x0021E170 internal SynchronizationInfo GetSynchronizationInfo(IEnumerable collection) { CollectionRecord collectionRecord = this[collection]; if (collectionRecord == null) { return(SynchronizationInfo.None); } return(collectionRecord.SynchronizationInfo); }
//------------------------------------------------------ // // Public Properties // //------------------------------------------------------ public new CollectionRecord this[object o] { get { // look up the entry for o WeakRefKey key = new WeakRefKey(o); CollectionRecord cr = (CollectionRecord) base[key]; return(cr); } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ internal void Add(object collection, CollectionRecord cr) { base.Add(new WeakRefKey(collection), cr); // a new collection has been put into play - schedule a cleanup. // This heuristic is similar to DataBindEngine.GetViewRecord - a // new collection suggests that old collections may no longer be // alive - but also handles the case where collections are put // into play but not any views. This can arise in collection // synchronization (DDVSO 153188). DataBindEngine.CurrentDataBindEngine.ScheduleCleanup(); }
// Token: 0x060076F9 RID: 30457 RVA: 0x0021FE80 File Offset: 0x0021E080 private CollectionRecord EnsureCollectionRecord(object collection, Func <object, object> GetSourceItem = null) { CollectionRecord collectionRecord = this[collection]; if (collectionRecord == null) { collectionRecord = new CollectionRecord(); this.Add(collection, collectionRecord); object parent = (GetSourceItem != null) ? GetSourceItem(collection) : null; IEnumerable enumerable = collection as IEnumerable; if (enumerable != null) { BindingOperations.OnCollectionRegistering(enumerable, parent); } } return(collectionRecord); }
// return the CollectionRecord for the given collection. If one doesn't // exist yet, create it and raise the CollectionRegistering event CollectionRecord EnsureCollectionRecord(object collection, Func <object, object> GetSourceItem = null) { CollectionRecord cr = this[collection]; if (cr == null) { cr = new CollectionRecord(); Add(collection, cr); object parent = (GetSourceItem != null) ? GetSourceItem(collection) : null; IEnumerable ie = collection as IEnumerable; if (ie != null) { BindingOperations.OnCollectionRegistering(ie, parent); } } return(cr); }
// 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); } } } }
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); }
internal SynchronizationInfo GetSynchronizationInfo(IEnumerable collection) { CollectionRecord cr = this[collection]; return((cr != null)? cr.SynchronizationInfo : SynchronizationInfo.None); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ internal void Add(object collection, CollectionRecord cr) { base.Add(new WeakRefKey(collection), cr); }
// return the CollectionRecord for the given collection. If one doesn't // exist yet, create it and raise the CollectionRegistering event CollectionRecord EnsureCollectionRecord(object collection, Func<object, object> GetSourceItem=null) { CollectionRecord cr = this[collection]; if (cr == null) { cr = new CollectionRecord(); Add(collection, cr); object parent = (GetSourceItem != null) ? GetSourceItem(collection) : null; IEnumerable ie = collection as IEnumerable; if (ie != null) { BindingOperations.OnCollectionRegistering(ie, parent); } } return cr; }
// Token: 0x060076F7 RID: 30455 RVA: 0x0021FCA8 File Offset: 0x0021DEA8 internal void Add(object collection, CollectionRecord cr) { base.Add(new WeakRefKey(collection), cr); DataBindEngine.CurrentDataBindEngine.ScheduleCleanup(); }
// 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); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ internal void Add(object collection, CollectionRecord cr) { base.Add(new WeakRefKey(collection), cr); }