//接收到客户端发来的数据,并向客户端返回消息 private void RecieveCallBack(Socket RSocket, string msg) { try { //Socket RSocket = (Socket)ar.AsyncState; bool flag = this.Save(msg); //序列化json 并保存到数据库 S_To_C_Data <object> s_to_c_data = new S_To_C_Data <object>(); s_to_c_data.Flag = HandleFlag.PMQC; s_to_c_data.Success = flag; string json = Utility.JsonHelper.JsonSerializer <S_To_C_Data <object> >(s_to_c_data); RSocket.Send(Encoding.Unicode.GetBytes(json), SocketFlags.None); //保存成功返回1 ,反之则0 //把消息输出到页面上 lb_msg.Items.Add(flag ? "保存成功" : "保存失败"); //同时接收客户端回发的数据,用于回发 //RSocket.BeginReceive(MsgBuffer, 0, MsgBuffer.Length, 0, new AsyncCallback(RecieveCallBack), RSocket); } catch (Exception ex) { LogMg.AddError(ex); DEBUG.ThrowException(ex); } }
//接收到客户端发来的数据,并向客户端返回消息 private void RecieveCallBack(Socket RSocket, string msg) { try { //Socket RSocket = (Socket)ar.AsyncState; bool flag = this.Save(msg, RSocket); S_To_C_Data <object> s_to_c_data = new S_To_C_Data <object>(); s_to_c_data.Flag = HandleFlag.Country; s_to_c_data.Success = flag; string json = Utility.JsonHelper.JsonSerializer <S_To_C_Data <object> >(s_to_c_data); RSocket.Send(Encoding.Unicode.GetBytes(json)); } catch (Exception ex) { LogMg.AddError(ex); DEBUG.ThrowException(ex); } }
public static void DownLoad(Socket socket, string json) { S_To_C_Data <ClientConfig> sendObj = new S_To_C_Data <ClientConfig>(); ClientConfig _clientConfig = new ClientConfig(); try { C_To_S_Data <ClientConfig> obj = Utility.JsonHelper.JsonDeserialize <C_To_S_Data <ClientConfig> >(json); Clazz.Config.ClientConfig.XML_Station _station = SysConfig.clientConfig.AllStation.SingleOrDefault(c => c.TransferCode == obj.TransferCode); if (_station == null) { LogMg.AddDebug("TransferCode:" + obj.TransferCode + " 不存在"); } else { _clientConfig.OrgId = SysConfig.clientConfig.GetOrgIdByTransferCode(obj.TransferCode); _clientConfig.StationId = SysConfig.clientConfig.GetStationIdByTransferCode(obj.TransferCode); _clientConfig.ListCountryTest = (from c in SysConfig.clientConfig.AllCountryTest where c.StationUniqueId == _station.UniqueId select new CSDataStandard.Config.CountryTest { NodeId = c.NodeId, TestId = c.TestId, Multiple = c.Multiple }).ToList(); _clientConfig.ListDevice = new List <DeviceControl>(); //(from c in SysConfig.clientConfig.AllDevice // where c.StationUniqueId == _station.UniqueId // select new CSDataStandard.Config.DeviceControl // { // Number = c.Number, // DeviceId = c.DeviceId // }).ToList(); _clientConfig.ListPMQCTest = (from c in SysConfig.clientConfig.AllPMQCTest where c.StationUniqueId == _station.UniqueId select new CSDataStandard.Config.PMQCTest { X = c.X, Y = c.Y, TestId = c.TestId, Id = c.Id, Name = c.Name }).ToList(); _clientConfig.ListMobileDetection = (from c in SysConfig.clientConfig.AllMobileDetection where c.StationUniqueId == _station.UniqueId select new CSDataStandard.Config.MobileDetection { TestId = c.TestId, TestTarger = c.TestTarger }).ToList(); _clientConfig.ListMcgsTest = (from c in SysConfig.clientConfig.AllMCGSTest where c.StationUniqueId == _station.UniqueId select new CSDataStandard.Config.MCGSTest { TestId = c.TestId, ColumnName = c.ColumnName, TestName = c.TestName }).ToList(); } } catch (Exception ex) { LogMg.AddError(ex); } sendObj.Data = new List <ClientConfig>(); sendObj.Data.Add(_clientConfig); //添加数据 sendObj.Flag = CSDataStandard.Enum.HandleFlag.DownLoadConfig; //类型为 下载配置文件 sendObj.Success = true; string sendJSON = Utility.JsonHelper.JsonSerializer(sendObj); socket.Send(Encoding.Unicode.GetBytes(sendJSON)); }