示例#1
0
 protected void SendResponseEvent(MessageEventArgs messageArgs)
 {
     if (FireResponseEventAsync)
     {
         if (ResponseProcessedCompleted)
             responseProcessedResult = ResponseEvent.BeginInvoke(this, messageArgs, null, null);
         else
             responseQueue.Enqueue(messageArgs);
     }
     else
         ResponseEvent(this, messageArgs);
 }
示例#2
0
        protected void OnResponse(object o, MessageEventArgs e)
        {
            var messagesArray = fastJSON.JSON.Instance.Parse(e.Message()) as ArrayList;

            if (messagesArray == null)
            {
                SendEvent(EventType.NetError, new NetErrorEventArgs("Can't parse server's response. " + e.Message()));
                return;
            }
            foreach (Dictionary<string, object> dictionary in messagesArray)
            {
                if (!dictionary.ContainsKey("cmd"))
                {
                    SendEvent(EventType.NetError, new NetErrorEventArgs(
                                      "Server's response doesn't contain \"cmd\" key, it can't be parsed. " + e.Message()));
                    return;
                }
                try
                {
                    ParseResponse(dictionary, e.Message());
                }
                catch (Exception exception)
                {
                    SendEvent(EventType.NetError, new NetErrorEventArgs("Some error occuried, while parsing:" + exception.Message));
                }
            }
        }
示例#3
0
 protected void ProcessResponse()
 {
     try
     {
         var buffer = Protocol.Receive(stream, tcpClient);
         if (ResponseEvent != null)
         {
             var messageArgs = new MessageEventArgs(buffer, DefaultEncoding);
             SendResponseEvent(messageArgs);
         }
     }
     catch (Exception e)
     {
         if (ResponseErrorEvent != null)
             ResponseErrorEvent(this, new NetErrorEventArgs(e.Message));
     }
 }