示例#1
0
        public int Subscribe(IBusMember subscriber)
        {
            if (!HandlerExistsFor(subscriber.GetType()))
            {
                throw new ArgumentException(nameof(subscriber), "The argument have no handler");
            }
            if (handlers.FindAll(obj => obj.Instant == subscriber).Count > 0)
            {
                return(subscriber.ID);
            }
            var handerlist = subscriber.GetType().GetMethods().Where(obj => obj.Name == "Handle").ToList();

            foreach (MethodInfo handler in handerlist)
            {
                handlers.Add(new Handler(subscriber, handler));
            }
            busMembers.Add(subscriber);
            return(busMembers.FindIndex(obj => obj == subscriber));
        }
示例#2
0
 public void Unsubscribe(IBusMember subscriber)
 {
     handlers.RemoveAll(obj => obj.Instant == subscriber);
     busMembers.RemoveAll(obj => obj == subscriber);
 }
示例#3
0
 public Message(IBusMember sender, int receiverID)
 {
     SenderID   = sender.ID;
     ReceiverID = receiverID;
 }