Exemple #1
0
        private void SendBackToReg(Message message, Express.IServer server, Express.ChannelReceiveEventArgs e, IProtocolBuffer protocolbuffer, int typeToBack = 0)
        {
            e.Channel.Tag = protocolbuffer;
            var result = GetTyepToBack(message, typeToBack);

            Express.Data data = new Express.Data(result.Array, result.Length);
            data.Tag = result;
            server.Send(data, e.Channel);
        }
Exemple #2
0
        public void Receive(Express.IServer server, Express.ChannelReceiveEventArgs e)
        {
            IProtocolBuffer protocolbuffer;

            if (e.Channel.Tag == null)
            {
                protocolbuffer = ProtocolBufferPool.Default.Pop();
                e.Channel.Tag  = protocolbuffer;
            }
            else
            {
                protocolbuffer = (IProtocolBuffer)e.Channel.Tag;
            }

            int offset = 0;
            int count  = e.Data.Count;

            while (count > 0)
            {
                int readcout = protocolbuffer.Import(e.Data.Array, 0, count);
                if (readcout > 0)
                {
                    SendPosToServer.SubmitBase(protocolbuffer.ToString());
                    try
                    {
                        var message = MessageFactory.MessageFromBuffer(protocolbuffer);
                        if (message != null && message.Body != null)
                        {
                            SaveLogsService.WriteLog("Start : --------------------");
                            SaveLogsService.WriteLog("消息ID : " + message.ID);
                            SaveLogsService.WriteLog("终端SIM : " + message.SIM);
                            SaveMsg(message, server, e, protocolbuffer);
                            SaveLogsService.WriteLog("End : --------------------");
                        }
                    }
                    catch (Exception ex)
                    {
                        SaveLogsService.WriteLog("IProtocolBuffer : " + protocolbuffer);
                        SaveLogsService.WriteLog("errorInfo : " + ex.Message);
                        SaveLogsService.WriteLog("errorInfo : " + ex.StackTrace);
                    }
                    finally
                    {
                        ProtocolBufferPool.Default.Push(protocolbuffer);
                        protocolbuffer = ProtocolBufferPool.Default.Pop();
                    }

                    offset += readcout;
                    count  -= readcout;
                }
            }
        }
Exemple #3
0
        public void Receive(Express.IServer server, Express.ChannelReceiveEventArgs e)
        {
            IProtocolBuffer protocolbuffer;

            if (e.Channel.Tag == null)
            {
                protocolbuffer = ProtocolBufferPool.Default.Pop();
                e.Channel.Tag  = protocolbuffer;
            }
            else
            {
                protocolbuffer = (IProtocolBuffer)e.Channel.Tag;
            }
            int offset = 0; int count = e.Data.Count;

            while (count > 0)
            {
                int readcout = protocolbuffer.Import(e.Data.Array, 0, count);
                if (readcout > 0)
                {
                    Message message = MessageFactory.MessageFromBuffer(protocolbuffer);
                    ProtocolBufferPool.Default.Push(protocolbuffer);
                    protocolbuffer = ProtocolBufferPool.Default.Pop();
                    e.Channel.Tag  = protocolbuffer;
                    IProtocolBuffer result = MessageFactory.MessateToBuffer <CenterResponse>(
                        message.BussinessNO, message.SIM, (m, b) =>
                    {
                        b.BussinessNO = message.BussinessNO;
                        b.ResultID    = message.ID;
                        b.Result      = ResultType.Success;
                    });
                    Beetle.Express.Data data = new Express.Data(result.Array, result.Length);
                    data.Tag = result;
                    server.Send(data, e.Channel);
                    offset += readcout;
                    count  -= readcout;
                }
            }
        }
Exemple #4
0
 private void SaveMsg(Message message, Express.IServer server, Express.ChannelReceiveEventArgs e, IProtocolBuffer protocolbuffer)
 {
     //SaveLogsService.WriteLog("Body类名 : " + message.Packet);
     if (message.Body is ClientRegister)
     {
         var msg = message.GetBody <ClientRegister>();
         SaveLogsService.WriteLog("省ID : " + msg.Province);
         SaveLogsService.WriteLog("市县区ID : " + msg.City);
         SaveLogsService.WriteLog("Color : " + msg.Color);
         SaveLogsService.WriteLog("终端ID : " + msg.DeviceID);
         SaveLogsService.WriteLog("终端型号 : " + msg.DeviceNo);
         SaveLogsService.WriteLog("制造商 : " + msg.Provider);
         SaveLogsService.WriteLog("车辆颜色 : " + msg.Color);
         SendBackToReg(message, server, e, protocolbuffer);
     }
     else if (message.Body is ClientSignature)
     {
         var msg = message.GetBody <ClientSignature>();
         SaveLogsService.WriteLog("Signature : " + msg.Signature);
         SendBackToReg(message, server, e, protocolbuffer, 1);
     }
     else if (message.Body is ClientResponse)
     {
         var msg = message.GetBody <ClientResponse>();
         SaveLogsService.WriteLog("BussinessNO : " + msg.BussinessNO);
         SaveLogsService.WriteLog("ResultID : " + msg.ResultID);
         SaveLogsService.WriteLog("BussinessNO : " + msg.Result);
         SendBackToReg(message, server, e, protocolbuffer, 1);
     }
     else if (message.Body is ClientPostion) //坐标上报
     {
         var postion = message.GetBody <ClientPostion>();
         SaveLogsService.WriteLog("ID : " + message.ID);
         SaveLogsService.WriteLog("SIM : " + message.SIM);
         SaveLogsService.WriteLog("Latitude : " + postion.Latitude);
         SaveLogsService.WriteLog("Longitude : " + postion.Longitude);
         SaveLogsService.WriteLog("speed : " + postion.Speed);
         SaveLogsService.WriteLog("Time : " + postion.Time.ToString("yyyy-MM-dd HH:mm:ss"));
         SaveLogsService.WriteLog("Status : " + (postion.Status.ACC ? "启动" : "关闭"));
         var dto = new PostionDto
         {
             Sim       = message.SIM,
             Latitude  = postion.Latitude.ToString(),
             Longitude = postion.Longitude.ToString(),
             Direction = postion.Direction.ToString(),
             Speed     = postion.Speed.ToString(),
             Time      = postion.Time.ToString("yyyy-MM-dd HH:mm:ss"),
             Status    = postion.Status.ACC.ToString()
         };
         var result = SendPosToServer.SubmitPos(dto);
         if (result != "0")
         {
             SaveLogsService.WriteLog("Upload : " + result);
         }
         SendBackToReg(message, server, e, protocolbuffer, 1);
     }
     else
     {
         //SendBackToReg(message, server, e, protocolbuffer, 1);
     }
 }