Exemplo n.º 1
0
        public void Register(IMessageSubscriber Subscriber)
        {
            SubscriberInfo subInfo = GetInfoFor(Subscriber);

            if (subInfo == null)
            {
                subInfo = new SubscriberInfo(Subscriber);
            }
            else
            {
                _Logger.LogAt(LogLevel.LL_DebugFramework,
                              "Already had a subscriber for same instance: " + subInfo.ToString()
                              );
                return;
            }

            _Logger.LogAt(LogLevel.LL_Info, "Creating Group: " + subInfo.SubscriberType.Name);
            _MessageHandlers.CreateGroup(subInfo);

            _Logger.LogAt(LogLevel.LL_DebugFramework, "START --Adding Handlers--");
            foreach (HandlerInfo info in FindHandlers(subInfo))
            {
                _Logger.LogAt(LogLevel.LL_DebugFramework, "Handler: " + info.ToString()
                              );
                _MessageHandlers.ToGroup(
                    subInfo,
                    (Groups <SubscriberInfo, HandlerInfo> .Members handlers) => { handlers.Add(info); }
                    );
            }
            _Logger.LogAt(LogLevel.LL_DebugFramework, "END --Adding Handlers--");
        }
Exemplo n.º 2
0
        // ----- PRIVATE -------

        private SubscriberInfo GetInfoFor(IMessageSubscriber Subscriber)
        {
            SubscriberInfo result = null;

            // Could have Group of Groups - type hierarchy above subscriber...
            //_MessageHandlers.ForMembersOfGroup(Subscriber.GetType(), (SubscriberInfo info) =>
            //{
            //});
            _MessageHandlers.EachGroupDo((SubscriberInfo info) =>
            {
                if (info.Instance == Subscriber)
                {
                    result = info;
                }
            });
            return(result);
        }
Exemplo n.º 3
0
        private IEnumerable <HandlerInfo> FindHandlers(SubscriberInfo SubInfo)
        {
            HandlerInfo handlerInfo = null;

            MethodInfo[] methods = SubInfo.SubscriberType.GetMethods(
                BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.FlattenHierarchy
                );

            //_Logger.LogAt(LogLevel.LL_DebugFramework, "FindHandlers - "+methods.Length + " methods to process.");

            foreach (MethodInfo mthd in methods)
            {
                //_Logger.LogAt(LogLevel.LL_DebugFramework, "Method: " + mthd.Name);
                object[] attribs = mthd.GetCustomAttributes(typeof(SubscribeToAttribute), false);
                if (attribs != null && attribs.Length > 0)
                {
                    //_Logger.LogAt(LogLevel.LL_DebugFramework, "Found" + attribs.Length + " SubscribeTo attributes.");
                    foreach (object attr in attribs)
                    {
                        SubscribeToAttribute subTo = attr as SubscribeToAttribute;

                        if (subTo != null)
                        {
                            _Logger.LogAt(LogLevel.LL_DebugFramework, subTo.ToString());
                            Delegate       del     = Delegate.CreateDelegate(typeof(MessageHandler), SubInfo.Instance, mthd, false);
                            MessageHandler handler = (MessageHandler)del;
                            if (handler != null)
                            {
                                handlerInfo = new HandlerInfo(subTo);
                                handlerInfo.UpdateHandler(handler);
                                yield return(handlerInfo);
                            }
                        }
                        else
                        {
                            _Logger.LogAt(LogLevel.LL_DebugFramework, "SubscribeTo was NULL");
                        }
                    }
                }
            }
            yield break;
        }
Exemplo n.º 4
0
        public void Deregister(IMessageSubscriber Subscriber)
        {
            SubscriberInfo info = GetInfoFor(Subscriber);

            _MessageHandlers.DestroyGroup(info);
        }
Exemplo n.º 5
0
        public void UndoObserver(IMessageSubscriber Observer, IMessageSubscriber ObservedObject)
        {
            SubscriberInfo Info = GetInfoFor(Observer);

            Info.ClearObservedObject(ObservedObject);
        }
Exemplo n.º 6
0
        public void MakeObserver(IMessageSubscriber Observer, IMessageSubscriber ObservedObject)
        {
            SubscriberInfo Info = GetInfoFor(Observer);

            Info.SetObservedObject(ObservedObject);
        }