private void RaiseClientUnsubscribed(string responseReceiverId, IEnumerable <string> messageTypeIds)
 {
     using (EneterTrace.Entering())
     {
         if (ClientUnsubscribed != null && messageTypeIds != null && messageTypeIds.Any())
         {
             SubscribeInfoEventArgs anEvent = new SubscribeInfoEventArgs(responseReceiverId, messageTypeIds);
             try
             {
                 ClientUnsubscribed(this, anEvent);
             }
             catch (Exception err)
             {
                 EneterTrace.Warning(TracedObject + ErrorHandler.DetectedException, err);
             }
         }
     }
 }
        private void Subscribe(string responseReceiverId, string[] messageTypes)
        {
            using (EneterTrace.Entering())
            {
                List <string> aMessagesToSubscribe = new List <string>(messageTypes);

                using (ThreadLock.Lock(mySubscribtions))
                {
                    // Subscribe only messages that are not subscribed yet.
                    foreach (TSubscription aSubscription in mySubscribtions)
                    {
                        if (aSubscription.ReceiverId == responseReceiverId &&
                            aMessagesToSubscribe.Contains(aSubscription.MessageTypeId))
                        {
                            aMessagesToSubscribe.Remove(aSubscription.MessageTypeId);
                        }
                    }

                    // Subscribe
                    foreach (string aMessageType in aMessagesToSubscribe)
                    {
                        mySubscribtions.Add(new TSubscription(aMessageType, responseReceiverId));
                    }
                }

                if (ClientSubscribed != null && aMessagesToSubscribe.Count > 0)
                {
                    SubscribeInfoEventArgs anEvent = new SubscribeInfoEventArgs(responseReceiverId, aMessagesToSubscribe);
                    try
                    {
                        ClientSubscribed(this, anEvent);
                    }
                    catch (Exception err)
                    {
                        EneterTrace.Warning(TracedObject + ErrorHandler.DetectedException, err);
                    }
                }
            }
        }