예제 #1
0
        public DeepTracker Deactivate()
        {
            lock (_propertyChangedRegistry)
            {
                _propertyChangedRegistry.Clear();
                _propertyChangedSubscriptions.UnsubscribeAll();
            }

            lock (_collectionChangedRegistry)
            {
                _collectionChangedRegistry.Clear();
                _collectionChangedSubscriptions.UnsubscribeAll();
            }

            lock (_attachmentObjectRegistry)
            {
                _attachmentObjectRegistry.Clear();
            }

            var source = _sourceReference.Target;

            if (source != null)
            {
                var args = new ObjectDetachedEventArgs(Routes.Empty, source);
                _configuration.Raise(this, args);
            }

            IsActive = false;
            return(this);
        }
예제 #2
0
        private void RemoveBranch(Route contextRoute)
        {
            lock (_propertyChangedRegistry)
            {
                foreach (var pair in _propertyChangedRegistry.Remove(contextRoute, true))
                {
                    var args = new PropertyDetachedEventArgs(pair.Key, pair.Value.Item1, pair.Value.Item2);
                    _configuration.Raise(this, args);

                    _propertyChangedSubscriptions.Unsubscribe(pair.Value.Item1);
                }
            }

            lock (_collectionChangedRegistry)
            {
                foreach (var pair in _collectionChangedRegistry.Remove(contextRoute, false))
                {
                    var collection = pair.Value.Item1.Target as IEnumerable;
                    _collectionChangedSubscriptions.Unsubscribe(collection);

                    if (collection == null)
                    {
                        continue;
                    }

                    var args = new CollectionDetachedEventArgs(pair.Key, collection);
                    _configuration.Raise(this, args);
                }
            }

            lock (_attachmentObjectRegistry)
            {
                foreach (var pair in _attachmentObjectRegistry.Remove(contextRoute, false))
                {
                    var attachedObject = pair.Value.Target;
                    if (attachedObject != null)
                    {
                        var objectDetachedEventArgs = new ObjectDetachedEventArgs(pair.Key, attachedObject);
                        _configuration.Raise(this, objectDetachedEventArgs);
                    }
                }
            }
        }