Ejemplo n.º 1
0
 public MessageClient AddSubscriber(IClient client, string messageClientId, string endpointId, MessageDestination messageDestination, Subtopic subtopic, Selector selector)
 {
     lock (_objLock)
     {
         if (subtopic != null)
         {
             MessagingAdapter serviceAdapter = this._messageDestination.ServiceAdapter as MessagingAdapter;
             if ((serviceAdapter != null) && !serviceAdapter.AllowSubscribe(subtopic))
             {
                 ASObject extendedData = new ASObject();
                 extendedData["subtopic"] = subtopic.Value;
                 throw new MessageException(extendedData);
             }
         }
         if (!this._subscribers.Contains(messageClientId))
         {
             MessageClient messageClient = new MessageClient(client, messageDestination.SubscriptionManager, messageClientId, endpointId, messageDestination)
             {
                 Subtopic = subtopic,
                 Selector = selector
             };
             client.RegisterMessageClient(messageClient);
             this.AddSubscriber(messageClient);
             return(messageClient);
         }
         return(this._subscribers[messageClientId] as MessageClient);
     }
 }
        public IList GetSubscribers(IMessage message, bool evalSelector)
        {
            lock (_objLock)
            {
                bool filter = true;
                if (message.headers == null || message.headers.Count == 0)
                {
                    filter = false;
                }

                if (!filter)
                {
                    return(GetSubscribers());
                }
                else
                {
                    Subtopic subtopic = null;
                    if (message.headers.ContainsKey(AsyncMessage.SubtopicHeader))
                    {
                        subtopic = new Subtopic(message.headers[AsyncMessage.SubtopicHeader] as string);
                        MessagingAdapter messagingAdapter = _messageDestination.ServiceAdapter as MessagingAdapter;
                        if (messagingAdapter != null)
                        {
                            if (!messagingAdapter.AllowSend(subtopic))
                            {
                                return(null);
                            }
                        }
                    }

                    ArrayList subscribers = new ArrayList();
                    foreach (MessageClient messageClient in _subscribers.Values)
                    {
                        bool include = true;
                        if (subtopic != null && messageClient.Subtopic != null)
                        {
                            include = include && subtopic.Matches(messageClient.Subtopic);
                        }
                        if (messageClient.Selector != null && evalSelector)
                        {
                            include = include && messageClient.Selector.Evaluate(null, message.headers);
                        }

                        if (include)
                        {
                            subscribers.Add(messageClient.ClientId);
                        }
                    }
                    return(subscribers);
                }
            }
        }
Ejemplo n.º 3
0
 public IList GetSubscribers(IMessage message, bool evalSelector)
 {
     lock (_objLock)
     {
         bool flag = true;
         if ((message.headers == null) || (message.headers.Count == 0))
         {
             flag = false;
         }
         if (!flag)
         {
             return(this.GetSubscribers());
         }
         Subtopic subtopic = null;
         if (message.headers.ContainsKey("DSSubtopic"))
         {
             subtopic = new Subtopic(message.headers["DSSubtopic"] as string);
             MessagingAdapter serviceAdapter = this._messageDestination.ServiceAdapter as MessagingAdapter;
             if ((serviceAdapter != null) && !serviceAdapter.AllowSend(subtopic))
             {
                 return(null);
             }
         }
         ArrayList list = new ArrayList();
         foreach (MessageClient client in this._subscribers.Values)
         {
             bool flag2 = true;
             if ((subtopic != null) && (client.Subtopic != null))
             {
                 flag2 = flag2 && subtopic.Matches(client.Subtopic);
             }
             if ((client.Selector != null) && evalSelector)
             {
                 flag2 = flag2 && client.Selector.Evaluate(null, message.headers);
             }
             if (flag2)
             {
                 list.Add(client.ClientId);
             }
         }
         return(list);
     }
 }
 public MessageClient AddSubscriber(string clientId, string endpointId, Subtopic subtopic, Selector selector)
 {
     lock (_objLock)
     {
         if (subtopic != null)
         {
             MessagingAdapter messagingAdapter = _messageDestination.ServiceAdapter as MessagingAdapter;
             if (messagingAdapter != null)
             {
                 if (!messagingAdapter.AllowSubscribe(subtopic))
                 {
                     ASObject aso = new ASObject();
                     aso["subtopic"] = subtopic.Value;
                     throw new MessageException(aso);
                 }
             }
         }
         if (!_subscribers.Contains(clientId))
         {
             //Set in RtmpService
             MessageClient messageClient = new MessageClient(clientId, _messageDestination, endpointId);
             messageClient.Subtopic = subtopic;
             messageClient.Selector = selector;
             messageClient.AddSubscription(selector, subtopic);
             AddSubscriber(messageClient);
             messageClient.NotifyCreatedListeners();
             return(messageClient);
         }
         else
         {
             MessageClient messageClient = _subscribers[clientId] as MessageClient;
             IClient       client        = FluorineContext.Current.Client;
             if (client != null && !client.Id.Equals(messageClient.Client.Id))
             {
                 throw new MessageException("Duplicate subscriptions from multiple Flex Clients");
             }
             //Reset the endpoint push state for the subscription to make sure its current because a resubscribe could be arriving over a new endpoint or a new session.
             messageClient.ResetEndpoint(endpointId);
             return(messageClient);
         }
     }
 }