Example #1
0
 public string GetSequenceCodes()
 {
     SingletonInfo.GetInstance().SequenceCodes += 1;
     return(SingletonInfo.GetInstance().SequenceCodes.ToString().PadLeft(16, '0'));
 }
Example #2
0
        /// <summary>
        /// 收包及反馈
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="PlatformVerifySignatureresule"></param>
        public void DealTarBack(string filepath, out bool PlatformVerifySignatureresule)
        {
            List <string> AudioFileListTmp = new List <string>(); //收集的音频文件列表

            PlatformVerifySignatureresule = false;                //验签是否通过
            EBD    ebdb     = null;
            string PlayType = "";

            if (File.Exists(filepath))
            {
                try
                {
                    #region 先删除预处理解压缩包中的文件
                    foreach (string xmlfiledel in Directory.GetFileSystemEntries(mainForm.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

                    mainForm.tar.UnpackTarFiles(filepath, mainForm.strBeUnTarFolder);                    //把压缩包解压到专门存放接收到的XML文件的文件夹下

                    string[] xmlfilenames      = Directory.GetFiles(mainForm.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)mainForm.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 = mainForm.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
                    }
                    mainForm.DeleteFolder(mainForm.strBeSendFileMakeFolder);//删除原有XML发送文件的文件夹下的XML
                    #region  最老版本的针对各类消息的反馈
                    if (ebdb != null)
                    {
                        if (ebdb.EBDType == "EBM")
                        {
                            string strMsgType       = ebdb.EBM.MsgBasicInfo.MsgType; //播发类型
                            string strAuxiliaryType = "";
                            if (ebdb.EBM.MsgContent != null)
                            {
                                if (ebdb.EBM.MsgContent.Auxiliary != null)
                                {
                                    strAuxiliaryType = ebdb.EBM.MsgContent.Auxiliary.AuxiliaryType; //实时流播发
                                    if (strAuxiliaryType == "61")
                                    {
                                        PlayType = "1";
                                    }
                                    else
                                    {
                                        PlayType = "2";
                                    }
                                }
                                else
                                {
                                    //有两种情况 停播 文转语
                                    ebdb.EBM.MsgContent.Auxiliary = new Auxiliary();
                                    ebdb.EBM.MsgContent.Auxiliary.AuxiliaryType = "3";
                                    strAuxiliaryType = "3";
                                    ebdb.EBM.MsgContent.Auxiliary.AuxiliaryDesc = "文本转语";
                                    PlayType = "1";
                                }

                                //文转语的情况  只考虑播放
                                if (strMsgType == "1" && PlayType == "1" && ebdb.EBM.MsgContent.Auxiliary.AuxiliaryDesc == "文本转语")
                                {
                                    string[]     pathee = filepath.Split('\\');
                                    string       fill   = pathee[pathee.Length - 1].Split('.')[0];
                                    string       pp     = mainForm.sAudioFilesFolder + "\\" + fill;
                                    RecordDetail tmp    = new RecordDetail();
                                    tmp.SourceTar     = pathee[pathee.Length - 1];
                                    tmp.SourceTarPath = filepath;
                                    tmp.MediumType    = "文本";
                                    tmp.MsgStartTime  = ebdb.EBM.MsgBasicInfo.StartTime;
                                    tmp.MsgEndTime    = ebdb.EBM.MsgBasicInfo.EndTime;
                                    tmp.AreaCode      = ebdb.EBM.MsgContent.AreaCode;
                                    tmp.EventType     = ebdb.EBM.MsgBasicInfo.EventType;
                                    tmp.Severity      = ebdb.EBM.MsgBasicInfo.Severity;
                                    tmp.TextContent   = ebdb.EBM.MsgContent.MsgDesc;
                                    tmp.DealFlag      = 0;
                                    tmp.SenderName    = ebdb.EBM.MsgBasicInfo.SenderName;
                                    tmp.SenderCode    = ebdb.EBM.MsgBasicInfo.SenderCode;
                                    tmp.SendTime      = ebdb.EBM.MsgBasicInfo.SendTime;
                                    tmp.MsgTitle      = ebdb.EBM.MsgContent.MsgTitle;

                                    SingletonInfo.GetInstance().RecordDetailList.Add(tmp);
                                    if (!Directory.Exists(pp))
                                    {
                                        Directory.CreateDirectory(pp);//不存在该路径就创建
                                    }

                                    string docfilepath = pp + "\\" + fill + ".doc";


                                    CreatWord.CreateWordFile(docfilepath, tmp.TextContent);

                                    //FileStream fs = File.Create(pp + "\\" + fill+".txt");    //创建文件
                                    //fs.Close();
                                    //Thread.Sleep(500);
                                    //StreamWriter sw = new StreamWriter(pp + "\\" + fill + ".txt");
                                    //sw.Write(ebdb.EBM.MsgContent.MsgDesc);
                                    //sw.Flush();
                                    //sw.Close();
                                    tmp.SavePath = pp + "\\" + fill + ".doc";
                                    int returncode = SingletonInfo.GetInstance().DataBase.InsertRecorde(tmp);
                                    if (returncode != -1)
                                    {
                                        tmp.RecordId = returncode.ToString();
                                    }
                                    HttpProcessor.MyEvent(tmp);
                                }

                                if (strMsgType == "1" && PlayType == "2")
                                {
                                    string[]     pathee = filepath.Split('\\');
                                    string       fill   = pathee[pathee.Length - 1].Split('.')[0];
                                    string       pp     = mainForm.sAudioFilesFolder + "\\" + fill;
                                    RecordDetail tmp    = new RecordDetail();
                                    tmp.SourceTar     = pathee[pathee.Length - 1];
                                    tmp.SourceTarPath = filepath;
                                    tmp.MediumType    = "mp3";
                                    tmp.MsgStartTime  = ebdb.EBM.MsgBasicInfo.StartTime;
                                    tmp.MsgEndTime    = ebdb.EBM.MsgBasicInfo.EndTime;
                                    tmp.AreaCode      = ebdb.EBM.MsgContent.AreaCode;
                                    tmp.EventType     = ebdb.EBM.MsgBasicInfo.EventType;
                                    tmp.Severity      = ebdb.EBM.MsgBasicInfo.Severity;
                                    tmp.TextContent   = ebdb.EBM.MsgContent.MsgDesc;
                                    tmp.DealFlag      = 0;
                                    tmp.SenderName    = ebdb.EBM.MsgBasicInfo.SenderName;
                                    tmp.SenderCode    = ebdb.EBM.MsgBasicInfo.SenderCode;
                                    tmp.SendTime      = ebdb.EBM.MsgBasicInfo.SendTime;
                                    tmp.MsgTitle      = ebdb.EBM.MsgContent.MsgTitle;
                                    SingletonInfo.GetInstance().RecordDetailList.Add(tmp);
                                    if (!Directory.Exists(pp))
                                    {
                                        Directory.CreateDirectory(pp);//不存在该路径就创建
                                    }
                                    string[] mp3files = Directory.GetFiles(mainForm.strBeUnTarFolder, "*.mp3");
                                    AudioFileListTmp.AddRange(mp3files);
                                    string[] wavfiles = Directory.GetFiles(mainForm.strBeUnTarFolder, "*.wav");
                                    AudioFileListTmp.AddRange(wavfiles);
                                    string savetmp = pp + "\\" + Path.GetFileName(AudioFileListTmp[0]);
                                    System.IO.File.Copy(AudioFileListTmp[0], savetmp, true);
                                    tmp.SavePath = savetmp;
                                    int returncode = SingletonInfo.GetInstance().DataBase.InsertRecorde(tmp);
                                    if (returncode != -1)
                                    {
                                        tmp.RecordId = returncode.ToString();
                                    }
                                    HttpProcessor.MyEvent(tmp);
                                }
                            }
                        }
                    }

                    #endregion
                }
                catch (Exception ep)
                {
                    LogHelper.WriteLog(typeof(HttpProcessor), "处理http异常" + Environment.NewLine + ep.Message);
                }
            }
        }