Beispiel #1
0
        public void RegisterOuterEventSubscriber(string sessionId, string topic, SubscriberLocation location)
        {
            if (subscribers.ContainsKey(sessionId + topic))
            {
                return;
            }

            if (!events.ContainsKey(topic))
            {
                throw new ArgumentException("系统中没有topic为 [" + topic + "] 的事件");
            }
            EventCollector collector;

            if (eventCollectors.ContainsKey(sessionId))
            {
                collector = eventCollectors[sessionId];
            }
            else
            {
                collector = new EventCollector();
                eventCollectors.Add(sessionId, collector);
            }
            collector.RegisterEvent(topic, events[topic].EventInfo, kernel[events[topic].EventInfo.DeclaringType]);
            EventSubscriberInfo subInfo = new EventSubscriberInfo(topic, location, "", "");

            AddEventSubscriber(sessionId + topic, subInfo);
            if (!outerSubscriberMapping.ContainsKey(sessionId))
            {
                outerSubscriberMapping.Add(sessionId, new List <string>());
            }
            outerSubscriberMapping[sessionId].Add(topic);
            AddOuterSubscriberToPublisherInfo(sessionId + topic, subInfo);
            db.Store(new OuterEventInfo(sessionId, topic, location));
        }
Beispiel #2
0
 /// <summary>
 /// 连接到内部事件
 /// </summary>
 public void ConnectInnerEvent()
 {
     foreach (EventPublisherInfo publisher in this.events.Values)
     {
         foreach (string subscriberKey in subscribers.Keys)
         {
             EventSubscriberInfo info = subscribers[subscriberKey];
             if (info.Location == SubscriberLocation.Local && publisher.Topic == info.Topic)
             {
                 try {
                     Delegate handler = Delegate.CreateDelegate(publisher.EventInfo.EventHandlerType, kernel[info.ServiceType], info.MethodInfo);
                     publisher.EventInfo.AddEventHandler(kernel[publisher.EventInfo.DeclaringType], handler);
                     publisher.AddSubscriber(subscriberKey, info);
                 }
                 catch (Exception ex) {
                     throw new Exception("在连接对象[" + info.MethodInfo.DeclaringType.Name +
                                         "]上的订阅者[" + info.Topic + "]到接口[" +
                                         publisher.EventInfo.DeclaringType.ToString() +
                                         "]上定义的事件[" + publisher.EventInfo.Name + "]时发生错误", ex);
                 }
             }
         }
     }
     ReregisterOuterEvent();
 }
 private void AddOuterSubscriberToPublisherInfo(string subscriberKey, EventSubscriberInfo subInfo)
 {
     foreach (EventPublisherInfo publisher in this.events.Values) {
         if (publisher.Topic == subInfo.Topic) {
             publisher.AddSubscriber(subscriberKey, subInfo);
         }
     }
 }
Beispiel #4
0
 private void AddOuterSubscriberToPublisherInfo(string subscriberKey, EventSubscriberInfo subInfo)
 {
     foreach (EventPublisherInfo publisher in this.events.Values)
     {
         if (publisher.Topic == subInfo.Topic)
         {
             publisher.AddSubscriber(subscriberKey, subInfo);
         }
     }
 }
Beispiel #5
0
 private void AddEventSubscriber(string subscriberKey, EventSubscriberInfo subscriber)
 {
     subscribers.Add(subscriberKey, subscriber);
 }
 /// <summary>
 /// 添加订阅者到订阅者数组
 /// </summary>
 /// <param name="subscriberKey">订阅者标识</param>
 /// <param name="subscriber">订阅者信息</param>
 public void AddSubscriber(string subscriberKey, EventSubscriberInfo subscriber)
 {
     subscribers.Add(subscriberKey, subscriber);
 }
 private void AddEventSubscriber(string subscriberKey, EventSubscriberInfo subscriber)
 {
     subscribers.Add(subscriberKey, subscriber);
 }
        public void RegisterOuterEventSubscriber(string sessionId, string topic, SubscriberLocation location)
        {
            if (subscribers.ContainsKey(sessionId + topic)) return;

            if (!events.ContainsKey(topic)) throw new ArgumentException("系统中没有topic为 [" + topic + "] 的事件");
            EventCollector collector;
            if (eventCollectors.ContainsKey(sessionId))
                collector = eventCollectors[sessionId];
            else {
                collector = new EventCollector();
                eventCollectors.Add(sessionId, collector);
            }
            collector.RegisterEvent(topic, events[topic].EventInfo, kernel[events[topic].EventInfo.DeclaringType]);
            EventSubscriberInfo subInfo = new EventSubscriberInfo(topic, location, "", "");
            AddEventSubscriber(sessionId + topic, subInfo);
            if (!outerSubscriberMapping.ContainsKey(sessionId)) outerSubscriberMapping.Add(sessionId, new List<string>());
            outerSubscriberMapping[sessionId].Add(topic);
            AddOuterSubscriberToPublisherInfo(sessionId + topic, subInfo);
            db.Store(new OuterEventInfo(sessionId, topic, location));
        }
 /// <summary>
 /// ��Ӷ����ߵ�����������
 /// </summary>
 /// <param name="subscriberKey">�����߱�ʶ</param>
 /// <param name="subscriber">��������Ϣ</param>
 public void AddSubscriber(string subscriberKey, EventSubscriberInfo subscriber)
 {
     subscribers.Add(subscriberKey, subscriber);
 }