예제 #1
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);
                    }
                }
            }
        }
예제 #2
0
 internal void RegisterCollectionSynchronizationCallback(
     IEnumerable collection,
     object context,
     CollectionSynchronizationCallback synchronizationCallback)
 {
     _viewManager.RegisterCollectionSynchronizationCallback(collection, context, synchronizationCallback);
 }
예제 #3
0
        public SynchronizationInfo(object context, CollectionSynchronizationCallback callback)
        {
            if (callback == null)
            {
                // 80% case:  no callback - use the context as target of lock().
                // For this case, just store the context directly - we ask people
                // not to use a lock object that hold references.
                _context        = context;
                _callbackMethod = null;
                _callbackTarget = null;
            }
            else
            {
                // General case: invoke the callback to gain access.
                // In this case, both the context and the callback's target
                // belong to the app and should not be kept alive by WPF.
                _context        = new WeakReference(context);
                _callbackMethod = callback.Method;

                // distinguish static methods (target = null) from methods whose
                // target gets GC'd
                object target = callback.Target;
                _callbackTarget = (target != null)? new WeakReference(target) : ViewManager.StaticWeakRef;
            }
        }
예제 #4
0
		public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");
			if (callback == null)
				throw new ArgumentNullException("callback");

			SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback));
		}
예제 #5
0
        public void DisableCollectionSynchronization()
        {
            string[] stuff   = new[] { "foo", "bar" };
            object   context = new object();
            CollectionSynchronizationCallback callback = (collection, o, method, access) => { };

            BindingBase.EnableCollectionSynchronization(stuff, context, callback);

            BindingBase.DisableCollectionSynchronization(stuff);

            CollectionSynchronizationContext syncContext;

            Assert.IsFalse(BindingBase.TryGetSynchronizedCollection(stuff, out syncContext));
            Assert.IsNull(syncContext);
        }
        // Token: 0x060076F1 RID: 30449 RVA: 0x0021FAE4 File Offset: 0x0021DCE4
        public SynchronizationInfo(object context, CollectionSynchronizationCallback callback)
        {
            if (callback == null)
            {
                this._context        = context;
                this._callbackMethod = null;
                this._callbackTarget = null;
                return;
            }
            this._context        = new WeakReference(context);
            this._callbackMethod = callback.Method;
            object target = callback.Target;

            this._callbackTarget = ((target != null) ? new WeakReference(target) : ViewManager.StaticWeakRef);
        }
예제 #7
0
        public void EnableCollectionSynchronization()
        {
            string[] stuff   = new[] { "foo", "bar" };
            object   context = new object();
            CollectionSynchronizationCallback callback = (collection, o, method, access) => { };

            BindingBase.EnableCollectionSynchronization(stuff, context, callback);

            CollectionSynchronizationContext syncContext;

            Assert.IsTrue(BindingBase.TryGetSynchronizedCollection(stuff, out syncContext));
            Assert.That(syncContext, Is.Not.Null);
            Assert.AreSame(syncContext.Callback, callback);
            Assert.That(syncContext.ContextReference, Is.Not.Null);
            Assert.That(syncContext.ContextReference.Target, Is.SameAs(context));
        }
예제 #8
0
        /// <summary>
        /// Register a callback used to synchronize access to a given collection.
        /// </summary>
        /// <param name="collection"> The collection that needs synchronized access. </param>
        /// </param name="context"> An arbitrary object.  This object is passed back into
        ///     the callback;  it is not used otherwise.   It provides a way for the
        ///     application to store information it knows at registration time, which it
        ///     can then use at collection-access time.  Typically this information will
        ///     help the application determine the synchronization mechanism used to
        ///     control access to the given collection. </param>
        /// <param name="synchronizationCallback"> The callback to be invoked whenever
        ///     access to the collection is required. </param>
        public static void EnableCollectionSynchronization(
            IEnumerable collection,
            object context,
            CollectionSynchronizationCallback synchronizationCallback)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (synchronizationCallback == null)
            {
                throw new ArgumentNullException("synchronizationCallback");
            }

            ViewManager.Current.RegisterCollectionSynchronizationCallback(
                collection, context, synchronizationCallback);
        }
 internal CollectionSynchronizationContext(object context, CollectionSynchronizationCallback callback)
 {
     ContextReference = new WeakReference(context);
     Callback         = callback;
 }
예제 #10
0
        internal static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback));
        }
예제 #11
0
 internal void RegisterCollectionSynchronizationCallback(
                     IEnumerable collection,
                     object context,
                     CollectionSynchronizationCallback synchronizationCallback)
 {
     _viewManager.RegisterCollectionSynchronizationCallback(collection, context, synchronizationCallback);
 }
        // 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);
                    }
                }
            }
        }
예제 #13
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);
                    }
                }
            }
        }
예제 #14
0
        public SynchronizationInfo(object context, CollectionSynchronizationCallback callback)
        {
            if (callback == null)
            {
                // 80% case:  no callback - use the context as target of lock().
                // For this case, just store the context directly - we ask people
                // not to use a lock object that hold references.
                _context = context;
                _callbackMethod = null;
                _callbackTarget = null;
            }
            else
            {
                // General case: invoke the callback to gain access.
                // In this case, both the context and the callback's target
                // belong to the app and should not be kept alive by WPF.
                _context = new WeakReference(context);
                _callbackMethod = callback.Method;

                // distinguish static methods (target = null) from methods whose
                // target gets GC'd
                object target = callback.Target;
                _callbackTarget = (target != null)? new WeakReference(target) : ViewManager.StaticWeakRef;
            }
        }
		internal CollectionSynchronizationContext(object context, CollectionSynchronizationCallback callback)
		{
			ContextReference = new WeakReference(context);
			Callback = callback;
		}
        /// <summary>
        /// Register a callback used to synchronize access to a given collection.
        /// </summary>
        /// <param name="collection"> The collection that needs synchronized access. </param>
        /// </param name="context"> An arbitrary object.  This object is passed back into
        ///     the callback;  it is not used otherwise.   It provides a way for the
        ///     application to store information it knows at registration time, which it
        ///     can then use at collection-access time.  Typically this information will
        ///     help the application determine the synchronization mechanism used to
        ///     control access to the given collection. </param>
        /// <param name="synchronizationCallback"> The callback to be invoked whenever
        ///     access to the collection is required. </param>
        public static void EnableCollectionSynchronization(
                            IEnumerable collection,
                            object context,
                            CollectionSynchronizationCallback synchronizationCallback)
        {
            if (collection == null)
                throw new ArgumentNullException("collection");
            if (synchronizationCallback == null)
                throw new ArgumentNullException("synchronizationCallback");

            ViewManager.Current.RegisterCollectionSynchronizationCallback(
                collection, context, synchronizationCallback);
        }