Exemplo n.º 1
0
        private void Subscribe()
        {
            INotifyPropertyChanged subject = this.Subject;

            if (subject == null)
            {
                return;
            }

            for (int i = 0; i < this.AccessNode.Children.Count; i++)
            {
                PropertyAccessNode propertyNode = (PropertyAccessNode)this.AccessNode.Children[i];

                WeakPropertyChangedEventManager.Register(
                    subject,
                    propertyNode.Property.Name,
                    this,
                    (me, sender, args) => me.OnPropertyChanged(sender, args));
            }

            if (this.Children != null)
            {
                for (int i = 0; i < this.Children.Count; i++)
                {
                    this.Children[i].UpdateSubject(subject);
                }
            }
        }
Exemplo n.º 2
0
 private void RegisterOnPersonName()
 {
     WeakPropertyChangedEventManager.Register(
         _person,
         "Name",
         _listener,
         (me, sender, args) => me.OnPropertyChanged(sender, args));
 }
Exemplo n.º 3
0
                public void Unsubscribe(
                    INotifyPropertyChanged subject,
                    object rootSubject,
                    TListener listener)
                {
                    WeakPropertyChangedEventManager.Unregister(subject, _propertyAccessNode.PropertyName, listener, rootSubject);

                    UnsubscribeFromChildren(listener, subject, rootSubject);
                }
Exemplo n.º 4
0
        public void Unregister_MonitoredPropertyChanged_DoesNotFireCallback()
        {
            RegisterOnPersonName();

            WeakPropertyChangedEventManager.Unregister(_person, "Name", _listener, null);
            _person.Name = "Bob";

            Assert.AreEqual(0, _listener.CallCount);
        }
Exemplo n.º 5
0
                public void Subscribe(INotifyPropertyChanged subject, object rootSubject, TListener listener)
                {
                    WeakPropertyChangedEventManager.Register(
                        subject,
                        rootSubject,
                        _propertyAccessNode.PropertyName,
                        listener,
                        _onChangingCallback,
                        _onChangedCallback);

                    SubscribeToChildren(listener, subject, rootSubject);
                }
        public void Test()
        {
            // Collection with 1 item to make this test simple
            Items = new ContinuousCollection <NotifiableItem>
            {
                new NotifiableItem {
                    TestValue1 = 3, TestValue2 = 10
                },
            };

            // Start with TestValue1
            MaxValueCV = Items.ContinuousMax(item => item.TestValue1, value => Max = value);
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            Console.WriteLine("Max = " + Max);
            Console.WriteLine();

            // Switch to TestValue2
            MaxValueCV = Items.ContinuousMax(item => item.TestValue2, value => Max = value);
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            Console.WriteLine("Max = " + Max);
            Console.WriteLine();
            GC.Collect();
            WeakPropertyChangedEventManager.RemoveCollectedEntries();
            GC.Collect();
            // Now set TestValue1
            Items[0].TestValue1 = 20;
            Console.WriteLine("(BUG)");
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            // BUG: Max is set to 20 when it should be 10
            Console.WriteLine("Max = " + Max);

            Assert.AreEqual(10, Max);

            Console.Write("Hit enter to continue...");
            Console.ReadLine();
        }
Exemplo n.º 7
0
        private void Unsubscribe()
        {
            INotifyPropertyChanged subject = this.Subject;

            if (subject == null)
            {
                return;
            }

            for (int i = 0; i < this.AccessNode.Children.Count; i++)
            {
                PropertyAccessNode propertyNode = (PropertyAccessNode)this.AccessNode.Children[i];

                WeakPropertyChangedEventManager.Unregister(subject, propertyNode.Property.Name, this, null);
            }

            if (this.Children != null)
            {
                for (int i = 0; i < this.Children.Count; i++)
                {
                    this.Children[i].Unsubscribe();
                }
            }
        }
Exemplo n.º 8
0
        public void CleanupReferences()
        {
            RegisterOnPersonName();
            WeakReference personRef = new WeakReference(_person);

            _person = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Assert.IsFalse(personRef.IsAlive);

            WeakPropertyChangedEventManager.RemoveCollectedEntries();
            for (int i = 0; i < 10; i++)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                WeakPropertyChangedEventManager.RemoveCollectedEntries();
            }

            Assert.AreEqual(0, WeakPropertyChangedEventManager.SourceToBridgeTable.Count);
        }