Ejemplo n.º 1
0
            /// <summary>
            /// Removes a listener from the inner list of listeners.
            /// </summary>
            /// <param name="rootObjectHashCode"><paramref name="listener"/>s root object hash code.</param>
            /// <param name="listener">The listener to remove.</param>
            internal static void RemoveListener(int rootObjectHashCode, NestedMarkupExtension listener)
            {
                if (listener == null)
                {
                    return;
                }

                lock (listenersLock)
                {
                    if (!listeners.ContainsKey(rootObjectHashCode))
                    {
                        return;
                    }

                    foreach (var wr in listeners[rootObjectHashCode].ToList())
                    {
                        var targetReference = wr.Target;
                        if (targetReference == null)
                        {
                            listeners[rootObjectHashCode].Remove(wr);
                        }
                        else if ((NestedMarkupExtension)targetReference == listener)
                        {
                            listeners[rootObjectHashCode].Remove(wr);
                        }
                    }

                    if (listeners[rootObjectHashCode].Count == 0)
                    {
                        listeners.Remove(rootObjectHashCode);
                    }
                }
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Adds a listener to the inner list of listeners.
            /// </summary>
            /// <param name="rootObjectHashCode"><paramref name="listener"/>s root object hash code.</param>
            /// <param name="listener">The listener to add.</param>
            internal static void AddListener(int rootObjectHashCode, NestedMarkupExtension listener)
            {
                if (listener == null)
                {
                    return;
                }

                lock (listenersLock)
                {
                    // Do we have a listeners list for this root object yet, if not add it.
                    if (!listeners.ContainsKey(rootObjectHashCode))
                    {
                        listeners[rootObjectHashCode] = new List <WeakReference>();
                    }

                    // Check, if this listener already was added.
                    foreach (var wr in listeners[rootObjectHashCode].ToList())
                    {
                        var targetReference = wr.Target;
                        if (targetReference == null)
                        {
                            listeners[rootObjectHashCode].Remove(wr);
                        }
                        else if (targetReference == listener)
                        {
                            return;
                        }
                        else
                        {
                            var existing = (NestedMarkupExtension)targetReference;
                            var targets  = existing.GetTargetObjectsAndProperties();

                            foreach (var target in targets)
                            {
                                if (listener.IsConnected(target))
                                {
                                    listeners[rootObjectHashCode].Remove(wr);
                                    break;
                                }
                            }
                        }
                    }

                    // Add it now.
                    listeners[rootObjectHashCode].Add(new WeakReference(listener));
                }
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Fire the event.
 /// </summary>
 /// <param name="sender">The markup extension that reached an enpoint.</param>
 /// <param name="args">The event args containing the endpoint information.</param>
 internal static void Invoke(NestedMarkupExtension sender, EndpointReachedEventArgs args)
 {
     lock (listenersLock)
     {
         foreach (var wr in listeners.ToList())
         {
             var targetReference = wr.Target;
             if (targetReference != null)
             {
                 ((NestedMarkupExtension)targetReference).OnEndpointReached(sender, args);
             }
             else
             {
                 listeners.Remove(wr);
             }
         }
     }
 }
Ejemplo n.º 4
0
            /// <summary>
            /// Adds a listener to the inner list of listeners.
            /// </summary>
            /// <param name="listener">The listener to add.</param>
            internal static void AddListener(NestedMarkupExtension listener)
            {
                if (listener == null)
                {
                    return;
                }

                lock (listenersLock)
                {
                    // Check, if this listener already was added.
                    foreach (var wr in listeners.ToList())
                    {
                        var targetReference = wr.Target;
                        if (targetReference == null)
                        {
                            listeners.Remove(wr);
                        }
                        else if (targetReference == listener)
                        {
                            return;
                        }
                        else
                        {
                            var existing = (NestedMarkupExtension)targetReference;
                            var targets  = existing.GetTargetObjectsAndProperties();

                            foreach (var target in targets)
                            {
                                if (listener.IsConnected(target))
                                {
                                    listeners.Remove(wr);
                                    break;
                                }
                            }
                        }
                    }

                    // Add it now.
                    listeners.Add(new WeakReference(listener));
                }
            }
        /// <summary>
        /// An event handler that is called from the static <see cref="EndpointReachedEvent"/> class.
        /// </summary>
        /// <param name="sender">The markup extension that reached an enpoint.</param>
        /// <param name="args">The event args containing the endpoint information.</param>
        private void OnEndpointReached(NestedMarkupExtension sender, EndpointReachedEventArgs args)
        {
            if (args.Handled)
            {
                return;
            }

            var path = GetPathToEndpoint(args.Endpoint);

            if (path == null)
            {
                return;
            }

            if ((this != sender) && !UpdateOnEndpoint(path.EndPoint))
            {
                return;
            }

            args.EndpointValue = UpdateNewValue(path);
            args.Handled       = true;
        }
Ejemplo n.º 6
0
            /// <summary>
            /// Removes a listener from the inner list of listeners.
            /// </summary>
            /// <param name="listener">The listener to remove.</param>
            internal static void RemoveListener(NestedMarkupExtension listener)
            {
                if (listener == null)
                {
                    return;
                }

                lock (listenersLock)
                {
                    foreach (var wr in listeners.ToList())
                    {
                        var targetReference = wr.Target;
                        if (targetReference == null)
                        {
                            listeners.Remove(wr);
                        }
                        else if ((NestedMarkupExtension)targetReference == listener)
                        {
                            listeners.Remove(wr);
                        }
                    }
                }
            }
Ejemplo n.º 7
0
            /// <summary>
            /// Fire the event.
            /// </summary>
            /// <param name="rootObjectHashCode"><paramref name="sender"/>s root object hash code.</param>
            /// <param name="sender">The markup extension that reached an end point.</param>
            /// <param name="args">The event args containing the endpoint information.</param>
            internal static void Invoke(int rootObjectHashCode, NestedMarkupExtension sender, EndpointReachedEventArgs args)
            {
                lock (listenersLock)
                {
                    // Do nothing if we don't have this root object hash.
                    if (!listeners.ContainsKey(rootObjectHashCode))
                    {
                        return;
                    }

                    foreach (var wr in listeners[rootObjectHashCode].ToList())
                    {
                        var targetReference = wr.Target;
                        if (targetReference is NestedMarkupExtension)
                        {
                            ((NestedMarkupExtension)targetReference).OnEndpointReached(sender, args);
                        }
                        else
                        {
                            listeners[rootObjectHashCode].Remove(wr);
                        }
                    }
                }
            }