Beispiel #1
0
 private string _getKeyForInnerHashTable(EventListenerData aEventListenerData)
 {
     //VERY UNIQUE - NICE!
     return(aEventListenerData.EventListener.GetType().FullName + "_" +
            aEventListenerData.EventListener.GetHashCode() + "_" + aEventListenerData.EventName + "_" +
            aEventListenerData.EventDelegate.Method.Name);
 }
Beispiel #2
0
        /// <summary>
        ///     Adds the event listener.
        /// </summary>
        /// <returns>
        ///     The event listener.
        /// </returns>
        /// <param name='aEventNameString'>
        ///     If set to <c>true</c> a event type_string.
        /// </param>
        /// <param name='aEventDelegate'>
        ///     If set to <c>true</c> a event delegate.
        /// </param>
        /// <param name='aEventDispatcherAddMode'>
        ///     If set to <c>true</c> event listening mode.
        /// </param>
        public bool AddEventListener(string aEventNameString,
                                     EventDelegate aEventDelegate,
                                     EventDispatcherAddMode aEventDispatcherAddMode)
        {
            //
            var wasSuccessfulBoolean = false;

            //
            var aIEventListener = _getArgumentsCallee(aEventDelegate);

            //
            if (aIEventListener != null && aEventNameString != null)
            {
                //	OUTER
                var keyForOuterHashTableString = _getKeyForOuterHashTable(aEventNameString);

                Action act = () =>
                {
                    if (!mEventListenerDatasHashtable.ContainsKey(keyForOuterHashTableString))
                    {
                        mEventListenerDatasHashtable.Add(keyForOuterHashTableString,
                                                         new Dictionary <string, EventListenerData>());
                    }

                    //	INNER
                    var innerHashtable    = mEventListenerDatasHashtable[keyForOuterHashTableString];
                    var eventListenerData = new EventListenerData(aIEventListener, aEventNameString,
                                                                  aEventDelegate, aEventDispatcherAddMode);
                    //
                    var keyForInnerHashTableString = _getKeyForInnerHashTable(eventListenerData);
                    if (innerHashtable != null && innerHashtable.ContainsKey(keyForInnerHashTableString))
                    {
                        //THIS SHOULD *NEVER* HAPPEN - REMOVE AFTER TESTED WELL
                        Logger.Info("TODO (FIX THIS): Event Manager: Listener: " + keyForInnerHashTableString +
                                    " is already in list for event: " + keyForOuterHashTableString);
                    }
                    else
                    {
                        //	ADD
                        if (innerHashtable != null)
                        {
                            innerHashtable.Add(keyForInnerHashTableString, eventListenerData);
                        }
                        wasSuccessfulBoolean = true;
                        //Logger.Info ("	ADDED AT: " + keyForInnerHashTable_string + " = " +  eventListenerData);
                    }
                };

                if (keyForOuterHashTableString == mCurrentEventName)
                {
                    mAppendAction.Enqueue(act);
                }
                else
                {
                    act();
                }
            }
            return(wasSuccessfulBoolean);
        }
Beispiel #3
0
 private string _getKeyForInnerHashTable(EventListenerData aEventListenerData)
 {
     //VERY UNIQUE - NICE!
     StringBuilder.Length = 0;
     StringBuilder.Append(aEventListenerData.EventListener.GetType().FullName)
     .Append("_")
     .Append(aEventListenerData.EventListener.GetHashCode())
     .Append("_")
     .Append(aEventListenerData.EventName)
     .Append("_")
     .Append(aEventListenerData.EventDelegate.Method.Name);
     return(StringBuilder.ToString());
 }