public void InvokeCallBack(int? ackId, JsonEncodedEventMessage value)
 {
     Action<dynamic> target = null;
     if (ackId.HasValue)
     {
         if (this.callBackRegistry.TryRemove(ackId.Value, out target))
         {
             target.Invoke(value);
             //target.BeginInvoke(value, target.EndInvoke, null);
         }
     }
 }
        public void InvokeCallBack(int?ackId, JsonEncodedEventMessage value)
        {
            Action <dynamic> target = null;

            if (ackId.HasValue)
            {
                if (this.callBackRegistry.TryRemove(ackId.Value, out target))
                {
                    target.Invoke(value);
                    //target.BeginInvoke(value, target.EndInvoke, null);
                }
            }
        }
        public static EventMessage Deserialize(string rawMessage)
        {
            EventMessage evtMsg = new EventMessage();

            //  '5:' [message id ('+')] ':' [message endpoint] ':' [json encoded event]
            //   5:1::{"a":"b"}
            evtMsg.RawMessage = rawMessage;
            try
            {
                string[] args = rawMessage.Split(SPLITCHARS, 4);                 // limit the number of pieces
                if (args.Length == 4)
                {
                    int id;
                    if (int.TryParse(args[1], out id))
                    {
                        evtMsg.AckId = id;
                    }
                    evtMsg.Endpoint    = args[2];
                    evtMsg.MessageText = args[3];

                    if (!string.IsNullOrEmpty(evtMsg.MessageText) &&
                        evtMsg.MessageText.Contains("name") &&
                        evtMsg.MessageText.Contains("args"))
                    {
                        evtMsg.Json  = JsonEncodedEventMessage.Deserialize(evtMsg.MessageText);
                        evtMsg.Event = evtMsg.Json.Name;
                    }
                    else
                    {
                        evtMsg.Json = new JsonEncodedEventMessage();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(evtMsg);
        }