예제 #1
0
        public void OnReceived(Pipe.Request request, byte[] buffer, int length)
        {
            try {
                var data      = Encoding.UTF8.GetString(buffer);
                var arguments = JsonConvert.DeserializeObject <Dictionary <string, object> >(data);
                if ((arguments == null) || (!arguments.ContainsKey("method")))
                {
                    buffer = GetResponse(false, "invalid arguments!");
                    pipe?.Send(buffer, 0, buffer.Length, null);
                    return;
                }

                arguments.Add("context", this);
                var result = MethodUtils.Invoke(GetType(), arguments["method"] as string, arguments);
                if (result != null)
                {
                    buffer = GetResponse(true, result);
                    pipe?.Send(buffer, 0, buffer.Length, null);
                }
            }
            catch (Exception e) {
                buffer = GetResponse(false, e.Message);
                pipe?.Send(buffer, 0, buffer.Length, null);
                Tracker.LogE(e);
            }
        }
예제 #2
0
 /// <summary>
 /// 发送数据线程
 /// </summary>
 /// <param name="state">参数</param>
 private void SendDataThread(object state)
 {
     while (runningFlag)
     {
         var data = queue.Dequeue();
         if (data != null)
         {
             pipe.Send(data.buffer, data.offset, data.length, data.state);
         }
         else
         {
             queue.Wait();
         }
     }
 }