internal static void RegisterPathListener(SessionBase session, SessionListener listener)
 {
     if (listener.PathInfo.IsDirect)
     {
         listener.HookSession(session, false);
     }
     else
     {
         // Assign it to the appropriate TraitStore
         session.RegisterSessionListenerOnTrait(listener);
     }
 }
        /// <summary>
        /// Propogates the listener toward its final destination of being hooked.
        /// </summary>
        /// <param name="listener">Listener to be hooked</param>
        /// <remarks>
        /// In the case that the "Value" of this trait store is the session to be
        /// hooked, it will be hooked in this method. Otherwise, the listener will
        /// be registered with the value a link in the chain toward hooking the
        /// appropriate session.
        /// </remarks>
        private void PropogateListener(SessionListener listener)
        {
            var value = Value as SessionBase;

            if (listener.PathInfo.IsTargetTrait(this))
            {
                // Hook the change handler
                listener.HookSession(value, false);
            }
            else
            {
                // Register change listener with next session
                value.RegisterSessionListenerOnTrait(listener);
            }
        }
        internal static void RegisterTypeListener(SessionListener listener)
        {
            // Get a single bit number representing the session type.
            ulong key = GetIdentifier(listener.BroadcastingType).sessionOnly;

            // Look for existing sessions that match this type.
            foreach (var session in Sessions)
            {
                if (listener.BroadcastingType.GetTypeInfo().IsAssignableFrom(session.GetType().GetTypeInfo()) &&
                    listener.Matchsession(session))
                {
                    listener.HookSession(session, false);
                }
            }

            // Ensure that this type is in the listener table.
            if (!listenerTypeLookup.ContainsKey(key))
            {
                listenerTypeLookup[key] = new List <SessionListener>();
            }

            // Add the listener to the lookup table.
            listenerTypeLookup[key].Add(listener);
        }