public string EBMStateResponse(EBD ebdsr) { StringBuilder sbEBMState = new StringBuilder(); Random rd = new Random(); string responsestr = ""; responsestr = Header(ebdsr, "EBMStateResponse"); sbEBMState.Append("<EBMStateResponse>"); sbEBMState.Append("<MsgID>" + ebdsr.EBM.MsgID + "</MsgID>"); sbEBMState.Append("<CoveragePercent>" + rd.Next(60, 80).ToString() + "</CoveragePercent>"); #region Coverage if (ebdsr.EBM.Coverage != null) { sbEBMState.Append("<Coverage>"); for (int i = 0; i < ebdsr.EBM.Coverage.Area.Count; i++) { sbEBMState.Append("<Area>"); sbEBMState.Append("<AreaName>" + ebdsr.EBM.Coverage.Area[i].AreaName.ToString() + "</AreaName>"); sbEBMState.Append("<AreaCode>" + ebdsr.EBM.Coverage.Area[i].AreaCode + "</AreaCode>"); sbEBMState.Append("</Area>"); } sbEBMState.Append("</Coverage>"); } #endregion End sbEBMState.Append("</EBMStateResponse>"); sbEBMState.Append("</EBD>"); responsestr = responsestr + sbEBMState.ToString(); return(responsestr); }
public string DeviceStateResponse(EBD ebdsr, List <Device> lDevState) { StringBuilder sbDevState = new StringBuilder(); string responsestr = ""; responsestr = Header(ebdsr, "DeviceStateReport"); sbDevState.Append("<DeviceStateReport>"); #region Device if (lDevState.Count > 0) { for (int l = 0; l < lDevState.Count; l++) { sbDevState.Append("<Device>"); sbDevState.Append("<DeviceID>" + lDevState[l].DeviceID + "</DeviceID>"); sbDevState.Append("<DeviceCategory>Term</DeviceCategory>"); sbDevState.Append("<DeviceType>TN5415E</DeviceType>"); sbDevState.Append("<DeviceName>音柱</DeviceName>"); sbDevState.Append("<DeviceState>" + lDevState[l].DeviceState + "</DeviceState>"); sbDevState.Append("</Device>"); } } #endregion End sbDevState.Append("</DeviceStateReport>"); sbDevState.Append("</EBD>"); responsestr = responsestr + sbDevState.ToString(); return(responsestr); }
public string TermBRDResponse(EBD ebdsr, List <TermBRD> lt) { StringBuilder sbTerm = new StringBuilder(); string responsestr = Header(ebdsr, "TermBRDReport"); sbTerm.Append("<TermBRDReport>"); sbTerm.Append("<RPTStartTime>" + ebdsr.DataRequest.StartTime + "</RPTStartTime>"); sbTerm.Append("<RPTEndTime>" + ebdsr.DataRequest.EndTime + "</RPTEndTime>"); #region Term if (lt.Count > 0) { for (int l = 0; l < lt.Count; l++) { sbTerm.Append("<TermBRD>"); sbTerm.Append("<TermBRDID>" + lt[l].TermBRDID + "</TermBRDID>"); sbTerm.Append("<SourceType>" + lt[l].SourceType + "</SourceType>"); sbTerm.Append("<SourceID>" + lt[l].SourceID + "</SourceID>"); sbTerm.Append("<MsgID>" + lt[l].MsgID + "</MsgID>"); sbTerm.Append("<DeviceID>" + lt[l].DeviceID + "</DeviceID>"); sbTerm.Append("<BRDTime>" + lt[l].BRDTime + "</BRDTime>"); sbTerm.Append("<ResultCode>" + "1" + "</ResultCode>"); sbTerm.Append("<ResultDesc>" + "播出正常" + "</ResultDesc>"); sbTerm.Append("</TermBRD>"); } } #endregion End sbTerm.Append("</TermBRDReport>"); sbTerm.Append("</EBD>"); responsestr = responsestr + sbTerm.ToString(); return(responsestr); }
public string PlatformBRDResponse(EBD ebdsr, List <PlatformBRD> lP) { StringBuilder sbPlat = new StringBuilder(); string responsestr = Header(ebdsr, "PlatformBRDReport"); sbPlat.Append("<PlatformBRDReport>"); sbPlat.Append("<RPTStartTime>" + ebdsr.DataRequest.StartTime + "</RPTStartTime>"); sbPlat.Append("<RPTEndTime>" + ebdsr.DataRequest.EndTime + "</RPTEndTime>"); #region PlatformBRD if (lP.Count > 0) { for (int i = 0; i < lP.Count; i++) { sbPlat.Append("<PlatformBRD>"); sbPlat.Append("<PlatformBRDID>111</PlatformBRDID>"); sbPlat.Append("<SourceType>111</SourceType>"); sbPlat.Append("<SourceID>111</SourceID>"); sbPlat.Append("<MsgID>111</MsgID>"); sbPlat.Append("<Sender>111</Sender>"); sbPlat.Append("<UnitId>111</UnitId>"); sbPlat.Append("<UnitName>111</UnitName>"); sbPlat.Append("<PersonID>111</PersonID>"); sbPlat.Append("<PersonName>111</PersonName>"); sbPlat.Append("<BRDStartTime>111</BRDStartTime>"); sbPlat.Append("<BRDEndTime>111</BRDEndTime>"); sbPlat.Append("<AudioFileURL>" + "" + "</AudioFileURL>"); sbPlat.Append("</PlatformBRD>"); } } sbPlat.Append("</PlatformBRDReport>"); sbPlat.Append("</EBD>"); responsestr = responsestr + sbPlat.ToString(); #endregion End return(responsestr); }
public string DeviceInfoResponse(EBD ebdsr, List <Device> lDev) { StringBuilder sbDevInfo = new StringBuilder(); string responsestr = Header(ebdsr, "DeviceInfoReport"); sbDevInfo.Append("<DeviceInfoReport>"); sbDevInfo.Append("<RPTStartTime>" + ebdsr.DataRequest.StartTime + "</RPTStartTime>"); sbDevInfo.Append("<RPTEndTime>" + ebdsr.DataRequest.EndTime + "</RPTEndTime>"); #region DeviceInfo if (lDev.Count > 0) { for (int l = 0; l < lDev.Count; l++) { sbDevInfo.Append("<Device>"); sbDevInfo.Append("<DeviceID>" + lDev[l].DeviceID + "</DeviceID>"); sbDevInfo.Append("<DeviceCategory>Term</DeviceCategory>"); sbDevInfo.Append("<DeviceType>TN5415E</DeviceType>"); sbDevInfo.Append("<DeviceName>音柱</DeviceName>"); sbDevInfo.Append("<AreaCode>" + lDev[l].AreaCode + "</AreaCode>"); sbDevInfo.Append("<AdminLevel>村级</AdminLevel>"); sbDevInfo.Append("</Device>"); } } #endregion End sbDevInfo.Append("</DeviceInfoReport>"); sbDevInfo.Append("</EBD>"); responsestr = responsestr + sbDevInfo.ToString(); return(responsestr); }
/// <summary> /// 通用反馈 收到tar就回 /// </summary> private void CurrencyTarBack(EBD ebdb) { try { ServerForm.DeleteFolder(ServerForm.strBeSendFileMakeFolder);//删除原有XML发送文件的文件夹下的XML XmlDocument xmlDoc = new XmlDocument(); responseXML rp = new responseXML(); rp.SourceAreaCode = ServerForm.strSourceAreaCode; rp.SourceType = ServerForm.strSourceType; rp.SourceName = ServerForm.strSourceName; rp.SourceID = ServerForm.strSourceID; rp.sHBRONO = ServerForm.strHBRONO; Random rd = new Random(); string fName = "10" + rp.sHBRONO + GetSequenceCodes(); xmlDoc = rp.CurrencyReback(ebdb, "EBDResponse", fName); string xmlSignFileName = "\\EBDB_" + fName + ".xml"; CreateXML(xmlDoc, ServerForm.strBeSendFileMakeFolder + xmlSignFileName); //进行签名 // ServerForm.mainFrm.GenerateSignatureFile(ServerForm.strBeSendFileMakeFolder, fName); 测试注释20180812 ServerForm.tar.CreatTar(ServerForm.strBeSendFileMakeFolder, ServerForm.sSendTarPath, fName);//使用新TAR string sSendTarName = ServerForm.sSendTarPath + "\\EBDT_" + fName + ".tar"; FileStream fsSnd = new FileStream(sSendTarName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fsSnd); //时间戳 int datalen = (int)fsSnd.Length + 2; int bufferLength = 4096; long offset = 0; //开始上传时间 writeHeader(datalen.ToString(), "EBDT_" + fName + ".tar"); byte[] buffer = new byte[4096]; //已上传的字节数 int size = br.Read(buffer, 0, bufferLength); while (size > 0) { outputStream.Write(buffer, 0, size); offset += size; size = br.Read(buffer, 0, bufferLength); } outputStream.Write(Encoding.UTF8.GetBytes(sEndLine), 0, 2); outputStream.Flush(); //提交写入的数据 fsSnd.Close(); //测试注释 20180608 幺蛾子 } catch (Exception esb) { Console.WriteLine("401:" + esb.Message); } }
public string Header(EBD ebdHeader, string strEBDType) { StringBuilder sbHeader = new StringBuilder(); sbHeader.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sbHeader.Append("<EBD xmlns=\"http://www.w3.org/2001/XMLSchema\">"); sbHeader.Append("<Version>1.0</Version>"); sbHeader.Append("<EBDID>" + ebdHeader.EBDID + "</EBDID>"); sbHeader.Append("<EBDType>" + strEBDType + "</EBDType>"); sbHeader.Append("<Source>"); sbHeader.Append("<SourceType>" + SourceType + "</SourceType>"); sbHeader.Append("<SourceName>" + SourceName + "</SourceName>"); sbHeader.Append("<SourceID>" + SourceID + "</SourceID>"); sbHeader.Append("</Source>"); sbHeader.Append("<EBDTime>" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</EBDTime>"); sbHeader.Append("<RelatedEBD>"); sbHeader.Append("<EBDID>" + ebdHeader.EBDID + "</EBDID>"); sbHeader.Append("</RelatedEBD>"); return(sbHeader.ToString()); }
/// <summary> /// 收包及反馈 /// </summary> /// <param name="filepath"></param> /// <param name="PlatformVerifySignatureresule"></param> public void DealTarBack(string filepath, out bool PlatformVerifySignatureresule) { PlatformVerifySignatureresule = false;//验签是否通过 EBD ebdb = null; if (File.Exists(filepath)) { try { #region 先删除预处理解压缩包中的文件 foreach (string xmlfiledel in Directory.GetFileSystemEntries(ServerForm.strBeUnTarFolder)) { if (File.Exists(xmlfiledel)) { FileInfo fi = new FileInfo(xmlfiledel); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } File.Delete(xmlfiledel);//直接删除其中的文件 } } #endregion End ServerForm.tar.UnpackTarFiles(filepath, ServerForm.strBeUnTarFolder); //把压缩包解压到专门存放接收到的XML文件的文件夹下 string[] xmlfilenames = Directory.GetFiles(ServerForm.strBeUnTarFolder, "*.xml"); //从解压XML文件夹下获取解压的XML文件名 string sTmpFile = string.Empty; string sAnalysisFileName = ""; string sSignFileName = ""; //签名模块 20180820 //if (mainForm.m_UsbPwsSupport == "1") //{ // if (xmlfilenames.Length < 2)//没有签名文件 // PlatformVerifySignatureresule = false; //} for (int i = 0; i < xmlfilenames.Length; i++) { sTmpFile = Path.GetFileName(xmlfilenames[i]); if (sTmpFile.ToUpper().IndexOf("EBDB") > -1 && sTmpFile.ToUpper().IndexOf("EBDS_EBDB") < 0) { sAnalysisFileName = xmlfilenames[i]; } //else if (sTmpFile.ToUpper().IndexOf("EBDS_EBDB") > -1)//签名文件 //{ // sSignFileName = xmlfilenames[i];//签名文件 //} } if (!string.IsNullOrWhiteSpace(sAnalysisFileName)) { using (FileStream fsr = new FileStream(sAnalysisFileName, FileMode.Open)) { StreamReader sr = new StreamReader(fsr, Encoding.UTF8); string xmlInfo = sr.ReadToEnd(); xmlInfo = xmlInfo.Replace("xmlns:xs", "xmlns"); sr.Close(); xmlInfo = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlInfo); xmlInfo = XmlSerialize.GetLowOrderASCIICharacters(xmlInfo); ebdb = XmlSerialize.DeserializeXML <EBD>(xmlInfo); } } string myEBDType = string.Empty; if (ebdb != null) { myEBDType = ebdb.EBDType; } // if (!string.IsNullOrWhiteSpace(sSignFileName) && myEBDType != "ConnectionCheck") if (myEBDType != "ConnectionCheck") { //读取xml中的文件,转换为byte字节 byte[] xmlArray = File.ReadAllBytes(sAnalysisFileName); PlatformVerifySignatureresule = true; //验签结果 #region 签名处理 暂时先注释 20180820 //Console.WriteLine("开始验证签名文件!"); //using (FileStream SignFs = new FileStream(sSignFileName, FileMode.Open)) //{ // StreamReader signsr = new StreamReader(SignFs, Encoding.UTF8); // string xmlsign = signsr.ReadToEnd(); // signsr.Close(); // responseXML signrp = new responseXML();//签名回复 // XmlDocument xmlSignDoc = new XmlDocument(); // try // { // int nDeviceHandle = (int)ServerForm.mainFrm.phDeviceHandle; // xmlsign = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlsign); // xmlsign = XmlSerialize.GetLowOrderASCIICharacters(xmlsign); // Signature sign = XmlSerialize.DeserializeXML<Signature>(xmlsign); // xmlsign = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlsign); // xmlsign = XmlSerialize.GetLowOrderASCIICharacters(xmlsign); // string PucStr = sign.SignatureValue; // byte[] pucsingVi = Encoding.UTF8.GetBytes(sign.SignatureValue); // //0是签名通过 // var result = ServerForm.mainFrm.usb.PlatformVerifySignature(nDeviceHandle, 1, xmlArray, xmlArray.Length, pucsingVi); // PlatformVerifySignatureresule = result == 0; // Log.Instance.LogWrite(PlatformVerifySignatureresule ? "签名验证成功" : "签名验证失败-" + result); // } // catch (Exception ex) // { // Log.Instance.LogWrite("签名文件错误:" + ex.Message); // } //} //Console.WriteLine("结束验证签名文件!"); #endregion End #region 通用反馈 CurrencyTarBack(ebdb); #endregion } ServerForm.DeleteFolder(ServerForm.strBeSendFileMakeFolder);//删除原有XML发送文件的文件夹下的XML } catch (Exception ep) { Log.Instance.LogWrite("处理http异常" + Environment.NewLine + ep.Message); } } }
/// <summary> /// /// </summary> /// <param name="filepath"></param> /// <param name="PlatformVerifySignatureresule"></param> public void DealTarBack(string filepath, out bool PlatformVerifySignatureresule) { PlatformVerifySignatureresule = false;//验签是否通过 EBD ebdb = null; if (File.Exists(filepath)) { try { #region 先删除预处理解压缩包中的文件 foreach (string xmlfiledel in Directory.GetFileSystemEntries(ServerForm.strBeUnTarFolder)) { if (File.Exists(xmlfiledel)) { FileInfo fi = new FileInfo(xmlfiledel); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } File.Delete(xmlfiledel);//直接删除其中的文件 } } #endregion End ServerForm.tar.UnpackTarFiles(filepath, ServerForm.strBeUnTarFolder); //把压缩包解压到专门存放接收到的XML文件的文件夹下 string[] xmlfilenames = Directory.GetFiles(ServerForm.strBeUnTarFolder, "*.xml"); //从解压XML文件夹下获取解压的XML文件名 string sTmpFile = string.Empty; string sAnalysisFileName = ""; string sSignFileName = ""; #region 测试注释 20180812 //if (mainForm.m_UsbPwsSupport == "1") //{ // if (xmlfilenames.Length < 2)//没有签名文件 // PlatformVerifySignatureresule = false; //} PlatformVerifySignatureresule = true; #endregion for (int i = 0; i < xmlfilenames.Length; i++) { sTmpFile = Path.GetFileName(xmlfilenames[i]); if (sTmpFile.ToUpper().IndexOf("EBDB") > -1 && sTmpFile.ToUpper().IndexOf("EBDS_EBDB") < 0) { sAnalysisFileName = xmlfilenames[i]; } //else if (sTmpFile.ToUpper().IndexOf("EBDS_EBDB") > -1)//签名文件 //{ // sSignFileName = xmlfilenames[i];//签名文件 //} } if (!string.IsNullOrWhiteSpace(sAnalysisFileName)) { using (FileStream fsr = new FileStream(sAnalysisFileName, FileMode.Open)) { StreamReader sr = new StreamReader(fsr, Encoding.UTF8); string xmlInfo = sr.ReadToEnd(); xmlInfo = xmlInfo.Replace("xmlns:xs", "xmlns"); sr.Close(); xmlInfo = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlInfo); xmlInfo = XmlSerialize.GetLowOrderASCIICharacters(xmlInfo); ebdb = XmlSerialize.DeserializeXML <EBD>(xmlInfo); } } string myEBDType = string.Empty; if (ebdb != null) { myEBDType = ebdb.EBDType; } if (!string.IsNullOrWhiteSpace(sSignFileName) && myEBDType != "ConnectionCheck") { //读取xml中的文件,转换为byte字节 byte[] xmlArray = File.ReadAllBytes(sAnalysisFileName); //#region 签名处理 //Console.WriteLine("开始验证签名文件!"); //using (FileStream SignFs = new FileStream(sSignFileName, FileMode.Open)) //{ // StreamReader signsr = new StreamReader(SignFs, Encoding.UTF8); // string xmlsign = signsr.ReadToEnd(); // signsr.Close(); // responseXML signrp = new responseXML();//签名回复 // XmlDocument xmlSignDoc = new XmlDocument(); // try // { // int nDeviceHandle = (int)ServerForm.mainFrm.phDeviceHandle; // xmlsign = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlsign); // xmlsign = XmlSerialize.GetLowOrderASCIICharacters(xmlsign); // Signature sign = XmlSerialize.DeserializeXML<Signature>(xmlsign); // xmlsign = XmlSerialize.ReplaceLowOrderASCIICharacters(xmlsign); // xmlsign = XmlSerialize.GetLowOrderASCIICharacters(xmlsign); // string PucStr = sign.SignatureValue; // byte[] pucsingVi = Encoding.UTF8.GetBytes(sign.SignatureValue); // //0是签名通过 // var result = ServerForm.mainFrm.usb.PlatformVerifySignature(nDeviceHandle, 1, xmlArray, xmlArray.Length, pucsingVi); // PlatformVerifySignatureresule = result == 0; // Log.Instance.LogWrite(PlatformVerifySignatureresule ? "签名验证成功" : "签名验证失败-" + result); // } // catch (Exception ex) // { // Log.Instance.LogWrite("签名文件错误:" + ex.Message); // } //} //Console.WriteLine("结束验证签名文件!"); //#endregion End #region 通用反馈 CurrencyTarBack(ebdb); #endregion } ServerForm.DeleteFolder(ServerForm.strBeSendFileMakeFolder);//删除原有XML发送文件的文件夹下的XML if (!PlatformVerifySignatureresule && myEBDType != "ConnectionCheck") { #region //这里加个失败的反馈 try { XmlDocument xmlDoc = new XmlDocument(); responseXML rp = new responseXML(); rp.SourceAreaCode = ServerForm.strSourceAreaCode; rp.SourceType = ServerForm.strSourceType; rp.SourceName = ServerForm.strSourceName; rp.SourceID = ServerForm.strSourceID; rp.sHBRONO = ServerForm.strHBRONO; Random rd = new Random(); // string fName = "10" + rp.sHBRONO + "00000000000" + rd.Next(100, 999).ToString(); string fName = "10" + rp.sHBRONO + "0000000000000" + rd.Next(100, 999).ToString(); xmlDoc = rp.VerifySignatureError(ebdb, "EBDResponse", fName); string xmlSignFileName = "\\EBDB_" + fName + ".xml"; CreateXML(xmlDoc, ServerForm.strBeSendFileMakeFolder + xmlSignFileName); //进行签名 // ServerForm.mainFrm.GenerateSignatureFile(ServerForm.strBeSendFileMakeFolder, fName); 测试注释20180812 ServerForm.tar.CreatTar(ServerForm.strBeSendFileMakeFolder, ServerForm.sSendTarPath, fName);//使用新TAR string sSendTarName = ServerForm.sSendTarPath + "\\EBDT_" + fName + ".tar"; FileStream fsSnd = new FileStream(sSendTarName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fsSnd); //时间戳 int datalen = (int)fsSnd.Length + 2; int bufferLength = 4096; long offset = 0; //开始上传时间 writeHeader(datalen.ToString(), "EBDT_" + fName + ".tar"); byte[] buffer = new byte[4096]; //已上传的字节数 int size = br.Read(buffer, 0, bufferLength); while (size > 0) { outputStream.Write(buffer, 0, size); offset += size; size = br.Read(buffer, 0, bufferLength); } outputStream.Write(Encoding.UTF8.GetBytes(sEndLine), 0, 2); outputStream.Flush();//提交写入的数据 fsSnd.Close(); } catch (Exception esb) { Console.WriteLine("401:" + esb.Message); } #endregion return; } } catch (Exception ep) { Log.Instance.LogWrite("处理http异常" + Environment.NewLine + ep.Message); } } }