Beispiel #1
0
        public string WriteDataInfoHead(string json)
        {
            ResultInfo resultInfo = new ResultInfo();

            try
            {
                Request      request      = JsonConvert.DeserializeObject <Request>(json);
                string       FilePath     = request.filepath;
                DataHeadInfo dataheadinfo = JsonConvert.DeserializeObject <DataHeadInfo>(request.dataheadinfo);
                bool         item         = citHelper.WriteDataInfoHead(request.filepath, dataheadinfo);

                if (item)
                {
                    resultInfo.flag = 1;
                    resultInfo.msg  = "";
                    resultInfo.data = "";
                }
                else
                {
                    resultInfo.flag = 0;
                    resultInfo.msg  = "更新失败";
                    resultInfo.data = "";
                }
            }
            catch (Exception ex)
            {
                resultInfo.flag = 0;
                resultInfo.msg  = ex.Message;
            }

            return(JsonConvert.SerializeObject(resultInfo));
        }
Beispiel #2
0
        /// <summary>
        /// 创建cit文件并写入头部和通道定义信息
        /// </summary>
        /// <param name="citPath">cit文件路径</param>
        /// <param name="headInfo">文件头部信息</param>
        /// <param name="channelInfo">通道定义信息</param>
        public void WriteCitHeadAndChannelInfo(string citPath, DataHeadInfo headInfo, List <DataChannelInfo> channelInfo)
        {
            CitFileHelper citHelper = new CitFileHelper();

            citHelper.WriteDataInfoHead(citPath, headInfo);
            citHelper.WriteDataChannelInfoHead(citPath, channelInfo);
            citHelper.WriteDataExtraInfo(citPath, "");
        }
Beispiel #3
0
        /// <summary>
        /// 显示文件头信息
        /// </summary>
        /// <param name="headInfo"></param>
        private void ShowHeadInfo(DataHeadInfo headInfo)
        {
            datatypevalue.Text = headInfo.iDataType.ToString();
            cbxFileType.Text   = headInfo.iDataType.ToString();
            if (!string.IsNullOrEmpty(headInfo.sDataVersion))
            {
                dataversionvalue.Text    = headInfo.sDataVersion;
                dataversionnewvalue.Text = headInfo.sDataVersion;
            }
            else
            {
                dataversionvalue.Text    = "";
                dataversionnewvalue.Text = "";
            }
            if (!string.IsNullOrEmpty(headInfo.sTrackCode))
            {
                trackcodevalue.Text    = headInfo.sTrackCode;
                trackcodenewvalue.Text = headInfo.sTrackCode;
            }
            else
            {
                trackcodevalue.Text    = "";
                trackcodenewvalue.Text = "";
            }

            if (!string.IsNullOrEmpty(headInfo.sTrain))
            {
                traincodevalue.Text    = headInfo.sTrain;
                traincodenewvalue.Text = headInfo.sTrain;
            }
            else
            {
                traincodevalue.Text    = "";
                traincodenewvalue.Text = "";
            }

            if (!string.IsNullOrEmpty(headInfo.sTrackName))
            {
                tracknamevalue.Text    = headInfo.sTrackName;
                tracknamenewvalue.Text = headInfo.sTrackName;
            }
            else
            {
                tracknamevalue.Text    = "";
                tracknamenewvalue.Text = "";
            }

            dirvalue.Text  = headInfo.iDir.ToString();
            cbxUpDown.Text = headInfo.iDir.ToString();


            rundirvalue.Text = headInfo.iRunDir.ToString();
            cbxRunDir.Text   = headInfo.iRunDir.ToString();


            kmincvalue.Text = headInfo.iKmInc.ToString();
            cbxKmInc.Text   = headInfo.iKmInc.ToString();
        }
        /// <summary>
        /// 创建波磨波形CIT文件
        /// </summary>
        /// <param name="citFileName">文件名称路径</param>
        /// <param name="dataHeadInfo">文件头信息</param>
        private void CreateWaveCitHeader(string citFileName, DataHeadInfo dataHeadInfo)
        {
            dataHeadInfo.iChannelNumber = 12;

            if (dataHeadInfo.sTrackCode == "\0\0\0\0")
            {
                dataHeadInfo.sTrackCode = "";
            }

            List <DataChannelInfo> channelList = new List <DataChannelInfo>();

            channelList.Add(new DataChannelInfo {
                sID = 1, sNameCh = "Coru_Start", sNameEn = "波磨起始里程", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 2, sNameCh = "Coru_End", sNameEn = "波磨终止里程", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 3, sNameCh = "Coru_RMS", sNameEn = "波磨有效值", fOffset = 0, fScale = 1, sUnit = ""
            });

            channelList.Add(new DataChannelInfo {
                sID = 4, sNameCh = "Coru_Index", sNameEn = "波磨指数", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 5, sNameCh = "Speed", sNameEn = "速度", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 6, sNameCh = "Main_Freq", sNameEn = "主频", fOffset = 0, fScale = 1, sUnit = ""
            });

            channelList.Add(new DataChannelInfo {
                sID = 7, sNameCh = "Wave_Len", sNameEn = "波长", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 8, sNameCh = "ConE_rate", sNameEn = "能量集中率", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 9, sNameCh = "CoruSeg_Len", sNameEn = "波磨区段长度", fOffset = 0, fScale = 1, sUnit = ""
            });

            channelList.Add(new DataChannelInfo {
                sID = 10, sNameCh = "Coru_Orig", sNameEn = "波磨原始波形", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 11, sNameCh = "CoruSeg_mile", sNameEn = "波磨区段里程", fOffset = 0, fScale = 1, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 12, sNameCh = "Len_Data", sNameEn = "数据长度", fOffset = 0, fScale = 1, sUnit = ""
            });

            citHelper.WriteCitFileHeadInfo(citFileName, dataHeadInfo, channelList);

            citHelper.WriteDataExtraInfo(citFileName, "");
        }
Beispiel #5
0
        private void CITForm_Load(object sender, EventArgs e)
        {
            InnerFileOperator.InnerFilePath   = Application.StartupPath + "\\Line.accdb";
            InnerFileOperator.InnerConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=5";
            LoadLineData();

            channelList.Clear();
            string channelXmlPath = Application.StartupPath + "//CitChannel.xml";

            //获得当前运行的Assembly
            Assembly _assembly = Assembly.GetExecutingAssembly();
            Stream   stream    = _assembly.GetManifestResourceStream("BNYTool.CitChannel.xml");

            if (stream != null)
            {
                XmlSerializer _serializer = new XmlSerializer(typeof(List <DataChannelInfo>));
                using (StreamReader reader = new StreamReader(stream))
                {
                    channelList = (List <DataChannelInfo>)_serializer.Deserialize(reader);
                }
            }
            else if (File.Exists(channelXmlPath))
            {
                XmlSerializer _serializer = new XmlSerializer(typeof(List <DataChannelInfo>));
                using (StreamReader reader = new StreamReader(channelXmlPath))
                {
                    channelList = (List <DataChannelInfo>)_serializer.Deserialize(reader);
                }
            }
            else
            {
                MessageBox.Show("配置文件丢失,找不到CitChannel.xml");
            }
            if (!string.IsNullOrEmpty(bnyFilePath))
            {
                FileInfo file = new FileInfo(bnyFilePath);
                dataHead = InitDataHead(file);
                if (dataHead != null)
                {
                    ShowHeadInfo(dataHead);
                }
            }
            Task.Factory.StartNew(() =>
            {
                if (channelList.Count > 0)
                {
                    channelListNew = GetChannelNewInfo(channelList);
                }
            });
        }
Beispiel #6
0
        private DataHeadInfo InitDataHead(FileInfo file)
        {
            DataHeadInfo headInfo = new DataHeadInfo();

            headInfo.iDataType    = 2;
            headInfo.sDataVersion = "0.0.0";
            DateTime dateTime = DateTime.ParseExact(file.Name.Substring(0, 8), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);

            headInfo.sDate = dateTime.ToString("yyyy-MM-dd");
            headInfo.sTime = dateTime.ToString("HH:mm:ss");
            if (file.Name.Contains("上"))
            {
                headInfo.iDir = 1;
                string lineName = file.Name.Substring(8, file.Name.IndexOf("上") - 8);
                if (Lines.ContainsKey(lineName))
                {
                    headInfo.sTrackName = Lines[lineName];
                }
                headInfo.iRunDir = 1;
                headInfo.iKmInc  = 1;
            }
            else if (file.Name.Contains("下"))
            {
                headInfo.iDir = 2;
                string lineName = file.Name.Substring(8, file.Name.IndexOf("下") - 1);
                if (Lines.ContainsKey(lineName))
                {
                    headInfo.sTrackName = Lines[lineName];
                }
                headInfo.iRunDir = 0;
                headInfo.iKmInc  = 0;
            }
            else if (file.Name.Contains("单线"))
            {
                headInfo.iDir = 3;
                string lineName = file.Name.Substring(8, file.Name.IndexOf("单线") - 1);
                if (Lines.ContainsKey(lineName))
                {
                    headInfo.sTrackName = Lines[lineName];
                }
                headInfo.iRunDir = 0;
                headInfo.iKmInc  = 0;
            }
            headInfo.iSmaleRate     = -2000;
            headInfo.fkmFrom        = common.GetBNYStartMile(file.FullName);
            headInfo.fkmTo          = common.GetBNYEndMile(file.FullName);
            headInfo.iChannelNumber = 15;
            return(headInfo);
        }
Beispiel #7
0
        /// <summary>
        /// 获取新的文件头信息
        /// </summary>
        /// <returns></returns>
        private DataHeadInfo GetNewDataHead()
        {
            DataHeadInfo head = new DataHeadInfo();

            head.iDataType    = Convert.ToInt32(cbxFileType.SelectedItem != null ? cbxFileType.SelectedItem.ToString() : "2");
            head.sDataVersion = dataversionnewvalue.Text;
            head.sTrackCode   = trackcodenewvalue.Text;
            head.sTrackName   = tracknamenewvalue.Text;
            head.iDir         = Convert.ToInt32(cbxUpDown.SelectedItem != null ? cbxUpDown.SelectedItem.ToString() : "1");
            head.sTrain       = traincodenewvalue.Text;
            head.iRunDir      = Convert.ToInt32(cbxRunDir.SelectedItem != null ? cbxRunDir.SelectedItem.ToString() : "1");
            head.iKmInc       = Convert.ToInt32(cbxKmInc.SelectedItem != null ? cbxKmInc.SelectedItem.ToString() : "1");

            return(head);
        }
Beispiel #8
0
        public void ConvertTxtToCit(string txtPath, string citPath)
        {
            string channelXmlPath = Application.StartupPath + "//CitChannel.xml";
            List <DataChannelInfo> citChannelInfo = common.GetChannelDefion(channelXmlPath);
            //由于值过大,比例变为1
            //citChannelInfo.Find(p => p.sNameEn == "M").fScale = 1;
            DataHeadInfo headerInfo = new DataHeadInfo();

            headerInfo.iDataType    = 2;
            headerInfo.sDataVersion = "0.0.1";
            headerInfo.sTrackName   = "shuohuang";
            headerInfo.sTrain       = "abcd";
            headerInfo.sTrackCode   = "2302";
            headerInfo.iRunDir      = 0;
            headerInfo.iSmaleRate   = 100;
            string   txtFileName = Path.GetFileNameWithoutExtension(txtPath);
            DateTime dateString  = DateTime.ParseExact(txtFileName.Substring(0, 12), "yyMMddHHmmss", CultureInfo.InvariantCulture);

            headerInfo.sDate          = dateString.ToString("yyyy-MM-dd");
            headerInfo.sTime          = dateString.ToString("HH:mm:ss");
            headerInfo.iChannelNumber = citChannelInfo.Count;
            string xb = txtFileName.Substring(txtFileName.Length - 1).ToLower();

            if (xb == "x")
            {
                headerInfo.iDir   = 2;
                headerInfo.iKmInc = 1;
            }
            else if (xb == "s")
            {
                headerInfo.iDir   = 1;
                headerInfo.iKmInc = 0;
            }
            long   lineCount    = common.GetTextLineCount(txtTxtPath.Text);
            double startMileage = common.GetAppointMileInLine(txtTxtPath.Text, 1);
            double endMileage   = common.GetAppointMileInLine(txtTxtPath.Text, lineCount);

            headerInfo.fkmFrom = (float)startMileage;
            headerInfo.fkmTo   = (float)endMileage;
            List <ChannelNew> channes = new List <ChannelNew>();

            channes = GetChannelNewInfo(citChannelInfo);

            common.WriteCitHeadAndChannelInfo(citPath, headerInfo, citChannelInfo);
            GetTxtDataAndWriteCit(txtTxtPath.Text, citPath, channes);
        }
        /// <summary>
        /// 向idf文件CitFileInfo表中写入cit信息
        /// </summary>
        /// <param name="idfFilePath"></param>
        /// <param name="m_dhi"></param>
        public void WriteTableCitFileInfo(String idfFilePath, DataHeadInfo m_dhi)
        {
            InitDicKmInc();//初始化字典
            InitDicDir();

            try
            {
                using (OleDbConnection sqlconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + idfFilePath + ";Persist Security Info=True"))
                {
                    sqlconn.Open();

                    // 临时修改开始,此处如果m_dhi.sTrackCode是空字符串(检测车软件没有配置好),sqlcom.ExecuteNonQuery()会出错,临时修改为:
                    if (m_dhi.sTrackCode.StartsWith("\0"))
                    {
                        m_dhi.sTrackCode = "0000"; // 这里的值统一设置为0000,对后面的计算不影响
                    }
                    // 临时修改完毕

                    string sSql = String.Format("insert into {0}(Id,LineName,LineCode,LineDir,KmInc,SDate,STime,Train) values( {1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}');",
                                                "CitFileInfo",
                                                1,
                                                m_dhi.sTrackName,
                                                m_dhi.sTrackCode,
                                                dicDir[m_dhi.iDir],
                                                dicKmInc[m_dhi.iKmInc],
                                                m_dhi.sDate,
                                                m_dhi.sTime,
                                                m_dhi.sTrain);

                    OleDbCommand sqlcom = new OleDbCommand(sSql, sqlconn);
                    sqlcom.ExecuteNonQuery();

                    sqlconn.Close();
                }
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("写入{0}文件中的{1}异常", idfFilePath, "CitFileInfo");
                MessageBox.Show(sb.ToString() + "\n" + ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Beispiel #10
0
 private void btnSelectImportPath_Click(object sender, EventArgs e)
 {
     if (folderBrowserImportDialog.ShowDialog() == DialogResult.OK)
     {
         txtExportPath.Text = folderBrowserImportDialog.SelectedPath;
         txtImportPath.Text = folderBrowserImportDialog.SelectedPath;
         fileExportPath     = txtExportPath.Text;
         DirectoryInfo folder = new DirectoryInfo(txtImportPath.Text);
         FileInfo[]    files  = folder.GetFiles("*.bny", SearchOption.TopDirectoryOnly);
         if (files.Count() > 0)
         {
             headInfoList.Clear();
             errorProvider.Clear();
             isCancel = false;
             string error = "";
             foreach (FileInfo file in files)
             {
                 DataHeadInfo headInfo = _citCreater.InitDataHead(file, ref error);
                 if (headInfo != null)
                 {
                     headInfoList.Add(file, headInfo);
                 }
                 else
                 {
                     error += Environment.NewLine;
                 }
             }
             if (!string.IsNullOrEmpty(error))
             {
                 MessageBox.Show(error);
             }
             DisplayFileInfo();
         }
         else
         {
             errorProvider.SetError(txtImportPath, "在目录中找不到BNY文件");
         }
     }
 }
Beispiel #11
0
        public string GetDataInfoHead(string json)
        {
            ResultInfo resultInfo = new ResultInfo();

            try
            {
                Request      request  = JsonConvert.DeserializeObject <Request>(json);
                string       FilePath = request.filepath;
                DataHeadInfo header   = citHelper.GetDataInfoHead(FilePath);
                string       result   = JsonConvert.SerializeObject(header);
                resultInfo.flag = 1;
                resultInfo.msg  = "";
                resultInfo.data = result;
            }
            catch (Exception ex)
            {
                resultInfo.flag = 0;
                resultInfo.msg  = ex.Message;
            }

            return(JsonConvert.SerializeObject(resultInfo));
        }
        /// <summary>
        /// 创建cit文件头
        /// </summary>
        /// <param name="citFileName">cit文件路径</param>
        /// <param name="dataHeadInfo">文件头文件信息</param>
        private void CreateCitHeader(string citFileName, DataHeadInfo dataHeadInfo)
        {
            dataHeadInfo.iChannelNumber = 6;

            if (dataHeadInfo.sTrackCode == "\0\0\0\0")
            {
                dataHeadInfo.sTrackCode = "";
            }

            List <DataChannelInfo> channelList = new List <DataChannelInfo>();

            channelList.Add(new DataChannelInfo {
                sID = 1, sNameCh = "公里", sNameEn = "KM", fOffset = 0, fScale = 1, sUnit = "Km"
            });
            channelList.Add(new DataChannelInfo {
                sID = 2, sNameCh = "米", sNameEn = "M", fOffset = 0, fScale = 4, sUnit = "m"
            });
            channelList.Add(new DataChannelInfo {
                sID = 3, sNameCh = "速度", sNameEn = "SPEED", fOffset = 0, fScale = 10, sUnit = "Km/h"
            });
            //channelList.Add(new DataChannelInfo { sID = 4, sNameCh = "AB_Vt_L_RMS_11corrugationRMS", sNameEn = "AB_Vt_L_RMS_11corrugationRMS", fOffset = 0, fScale = 100, sUnit = "" });
            //channelList.Add(new DataChannelInfo { sID = 5, sNameCh = "AB_Vt_R_RMS_11corrugationRMS", sNameEn = "AB_Vt_R_RMS_11corrugationRMS", fOffset = 0, fScale = 100, sUnit = "" });
            //channelList.Add(new DataChannelInfo { sID = 6, sNameCh = "AB_Lt_L_RMS_11corrugationRMS", sNameEn = "AB_Lt_L_RMS_11corrugationRMS", fOffset = 0, fScale = 100, sUnit = "" });

            channelList.Add(new DataChannelInfo {
                sID = 4, sNameCh = "AB_Vt_L_RMS_11" + "_coru", sNameEn = "AB_Vt_L_RMS_11" + "_coru", fOffset = 0, fScale = 100, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 5, sNameCh = "AB_Vt_R_RMS_11" + "_coru", sNameEn = "AB_Vt_R_RMS_11" + "_coru", fOffset = 0, fScale = 100, sUnit = ""
            });
            channelList.Add(new DataChannelInfo {
                sID = 6, sNameCh = "AB_Lt_L_RMS_11" + "_coru", sNameEn = "AB_Lt_L_RMS_11" + "_coru", fOffset = 0, fScale = 100, sUnit = ""
            });

            citHelper.WriteCitFileHeadInfo(citFileName, dataHeadInfo, channelList);

            citHelper.WriteDataExtraInfo(citFileName, "");
        }
Beispiel #13
0
        public DataHeadInfo InitDataHead(FileInfo file, ref string error)
        {
            DataHeadInfo headInfo = new DataHeadInfo();

            headInfo.iDataType    = 2;
            headInfo.sDataVersion = "0.0.0";
            headInfo.sTrackCode   = "0000";
            headInfo.sTrain       = "1000";
            try
            {
                //DateTime dateTime = DateTime.ParseExact(file.Name.Substring(0, 8), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
                DateTime dateTime = DateTime.ParseExact(file.Name.Split('_')[1], "yyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                headInfo.sDate = dateTime.ToString("yyyy-MM-dd");
                headInfo.sTime = dateTime.ToString("HH:mm:ss");
            }
            catch (Exception)
            {
                error += "无法解析文件:" + file.Name + ",原因:时间格式无效";
                return(null);
            }
            try
            {
                string strackName = file.Name.Split('_')[2];
                strackName = strackName.Substring(0, strackName.IndexOf('.'));
                string lineType = strackName.Substring(3, 1);
                if (lineType == "S")
                {
                    headInfo.iDir       = 1;
                    headInfo.iRunDir    = 1;
                    headInfo.iKmInc     = 1;
                    headInfo.sTrackName = strackName;
                }
                else if (lineType == "X")
                {
                    headInfo.iDir       = 2;
                    headInfo.iRunDir    = 0;
                    headInfo.iKmInc     = 0;
                    headInfo.sTrackName = strackName;
                }

                //string chName = RemoveNumber(file.Name);
                //if (chName.Contains("上行"))
                //{
                //    headInfo.iDir = 1;
                //    headInfo.iRunDir = 1;
                //    headInfo.iKmInc = 1;
                //    string lineName = getName(chName,"上行");
                //    if (Lines.ContainsKey(lineName))
                //    {
                //        headInfo.sTrackName = Lines[lineName] + "S";
                //    }
                //    else
                //    {
                //        error += "找不到线路名:[" + lineName + "]对应的线路代码,请确认!";
                //        return null;
                //    }

                //}
                //else if (chName.Contains("下行"))
                //{
                //    headInfo.iDir = 2;
                //    headInfo.iRunDir = 0;
                //    headInfo.iKmInc = 0;
                //    string lineName = getName(chName, "下行");
                //    if (Lines.ContainsKey(lineName))
                //    {
                //        headInfo.sTrackName = Lines[lineName] + "X";
                //    }
                //    else
                //    {
                //        error += "找不到线路名:[" + lineName + "]对应的线路代码,请确认!";
                //        return null;
                //    }

                //}
                //else if (chName.Contains("单线"))
                //{
                //    headInfo.iDir = 3;
                //    headInfo.iRunDir = 0;
                //    headInfo.iKmInc = 0;
                //    string lineName = getName(chName,"单线");
                //    if (Lines.ContainsKey(lineName))
                //    {
                //        headInfo.sTrackName = Lines[lineName];
                //    }
                //    else
                //    {
                //        error += "找不到线路名:[" + lineName + "]对应的线路代码,请确认!";
                //        return null;
                //    }

                //}
            }
            catch (Exception)
            {
                error += "无法解析文件:" + file.Name + ",原因:找不到上下行或文件名称不标准!";
                return(null);
            }
            headInfo.iSmaleRate = -2000;
            try
            {
                headInfo.fkmFrom = comm.GetBNYStartMile(file.FullName);
                headInfo.fkmTo   = comm.GetBNYEndMile(file.FullName);
            }
            catch (Exception)
            {
                error += "无法解析文件:" + file.Name + ",原因:获取不到开始或结束里程,请确认文件是否合法!";
                return(null);
            }
            headInfo.iChannelNumber = 15;

            return(headInfo);
        }
 /// <summary>
 /// 写入citInfo信息
 /// </summary>
 /// <param name="idfFileName"></param>
 /// <param name="dataHeadInfo"></param>
 private void WriteCitInfoToIdf(string idfFileName, DataHeadInfo dataHeadInfo)
 {
     idfHelper.WriteTableCitFileInfo(idfFileName, dataHeadInfo);
 }
Beispiel #15
0
 /// <summary>
 /// 生成cit文件头信息
 /// </summary>
 /// <param name="citFilePath"></param>
 /// <param name="head"></param>
 /// <param name="channelList"></param>
 /// <param name="dataList"></param>
 private void CreateCitFileHeader(string citFilePath, DataHeadInfo head, List <DataChannelInfo> channelList)
 {
     citHelper.WriteDataInfoHead(citFilePath, head);
     citHelper.WriteDataChannelInfoHead(citFilePath, channelList);
     citHelper.WriteDataExtraInfo(citFilePath, "");
 }
Beispiel #16
0
        /// <summary>
        /// 获取BNY数据并向cit文件中写入数据
        /// </summary>
        /// <param name="channelList"></param>
        private void GetBnyDataAndWriteCit(List <ChannelNew> channelList)
        {
            int[] bnyChannelArr = channelList.Where(s => s.BNYChannelId >= 0).Select(s => s.BNYChannelId).ToArray();

            int  sampleNum     = 1000;
            long startPosition = 0;
            long endPosition   = 0;

            long bnyFileLength = common.GetBNYLastPosition(bnyFilePath);

            int pageCount = Convert.ToInt32(bnyFileLength / (sampleNum * BNYFile.GetChannelSize()));

            List <float[]> bnyList = new List <float[]>();

            try
            {
                using (FileStream fs = new FileStream(createCitFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs, Encoding.Default))
                    {
                        DataHeadInfo           dhi             = citHelper.GetDataInfoHead(createCitFilePath);
                        List <DataChannelInfo> channelInfoList = citHelper.GetDataChannelInfoHead(createCitFilePath);
                        int    iChannelNumberSize = dhi.iChannelNumber * 2;
                        byte[] dataArray          = new byte[iChannelNumberSize];

                        List <Byte> dataList   = new List <Byte>();
                        short       tmpRmsData = 0;;
                        Byte[]      tmpBytes   = new Byte[2];
                        for (int i = 0; i < pageCount; i++)
                        {
                            bnyList       = common.GetBNYData(bnyFilePath, sampleNum, startPosition, ref endPosition);
                            startPosition = endPosition;

                            List <float[]> resultList = new List <float[]>();
                            //Action<float> action = new Action<float>({ });
                            for (int j = 0; j < channelList.Count; j++)
                            {
                                float[] fvalue = new float[sampleNum];

                                if (channelList[j].BNYChannelId >= 0)
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId];
                                }
                                resultList.Add(fvalue);
                            }

                            long iArrayLen = resultList[0].Length;
                            for (int k = 0; k < iArrayLen; k++)
                            {
                                if (citHelper.IsEncrypt(dhi))
                                {
                                    for (int iTmp = 0; iTmp < channelList.Count; iTmp++)
                                    {
                                        if (channelList[iTmp].BNYChannelId > 6)
                                        {
                                            tmpRmsData = (short)((resultList[iTmp][k] / 10 - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                        }
                                        else
                                        {
                                            tmpRmsData = (short)((resultList[iTmp][k] - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                        }
                                        tmpBytes = CitFileHelper.ByteXORByte(BitConverter.GetBytes(tmpRmsData));
                                        dataList.AddRange(tmpBytes);
                                    }
                                }
                                else
                                {
                                    for (int iTmp = 0; iTmp < channelList.Count; iTmp++)
                                    {
                                        try
                                        {
                                            if (channelList[iTmp].BNYChannelId > 6)
                                            {
                                                tmpRmsData = (short)((resultList[iTmp][k] / 10 - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                            }
                                            else
                                            {
                                                tmpRmsData = (short)((resultList[iTmp][k] - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                            }
                                            dataList.AddRange(BitConverter.GetBytes(tmpRmsData));
                                        }
                                        catch (Exception ex)
                                        {
                                            throw ex;
                                        }
                                    }
                                }
                                ///bw.BaseStream.Position = 100;
                                bw.Write(dataList.ToArray());
                                bw.Flush();

                                dataList.Clear();
                            }
                            if (token.IsCancellationRequested)
                            {
                                token.ThrowIfCancellationRequested();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #17
0
        private void BatchExportCitForm_Load(object sender, EventArgs e)
        {
            InnerFileOperator.InnerFilePath   = Application.StartupPath + "\\Line.accdb";
            InnerFileOperator.InnerConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=5";
            AggregateExceptionCatched        += BatchExportCitForm_AggregateExceptionCatched;
            Task task = Task.Factory.StartNew(() => LoadLineData());

            task.ContinueWith((t) =>
            {
                if (t.IsFaulted)
                {
                    MessageBox.Show("错误:" + t.Exception.InnerException.Message);
                }
            }, TaskContinuationOptions.OnlyOnFaulted);



            InitDropdownList();
            //获得当前运行的Assembly
            string channelXmlPath = Application.StartupPath + "//CitChannel.xml";

            citChannelInfo = common.GetChannelDefion(channelXmlPath);
            if (citChannelInfo == null)
            {
                MessageBox.Show("配置文件丢失,找不到CitChannel.xml");
                return;
            }


            if (_isSingle)
            {
                exportCitPath = bnyFileInfo.Name.Replace(".bny", ".cit");


                txtExportPath.Text = bnyFileInfo.FullName.Replace(".bny", ".cit");
                fileExportPath     = txtExportPath.Text;
                this.Height       -= 40;
                for (int i = 0; i < this.Controls.Count; i++)
                {
                    this.Controls[i].Location = new Point(this.Controls[i].Location.X, this.Controls[i].Location.Y - 40);
                }
                groupBox2.Visible        = false;
                btnSelectExportPath.Text = "导出路径";
                labExport.Text           = "选择路径:";
                this.Text = "导出cit文件";
                headInfoList.Clear();
                errorProvider.Clear();
                isCancel = false;
                string error = "";
                try
                {
                    task.Wait();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("获取线路数据时出错:" + ex.Message);
                    return;
                }
                DataHeadInfo headInfo = _citCreater.InitDataHead(bnyFileInfo, ref error);
                if (headInfo != null)
                {
                    headInfoList.Add(bnyFileInfo, headInfo);
                }
                if (!string.IsNullOrEmpty(error))
                {
                    MessageBox.Show(error);
                }
                DisplayFileInfo();
            }
        }
Beispiel #18
0
        private void WriteBnyData(string fileName, string citPath, List <ChannelNew> channelNewList)
        {
            CitFileHelper citHelper = new CitFileHelper();

            using (FileStream fs = new FileStream(citPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
            {
                using (BinaryWriter bw = new BinaryWriter(fs, Encoding.Default))
                {
                    DataHeadInfo           dhi         = citHelper.GetDataInfoHead(citPath);
                    long                   pos         = bw.BaseStream.Length;
                    List <DataChannelInfo> channelList = citHelper.GetDataChannelInfoHead(citPath);
                    int    iChannelNumberSize          = dhi.iChannelNumber * 2;
                    byte[] dataArray = new byte[iChannelNumberSize];

                    List <Byte> dataList   = new List <Byte>();
                    short       tmpRmsData = 0;

                    Byte[] tmpBytes = new Byte[2];
                    while (true)
                    {
                        if (channelDataList.ContainsKey(fileName) && channelDataList[fileName].Count > 0)
                        {
                            List <float[]> channelData = channelDataList[fileName].Dequeue();
                            DateTime       dt2         = DateTime.Now;
                            if (channelData == null || isCancel)
                            {
                                break;
                            }
                            long iArrayLen = channelData[0].Length;
                            for (int k = 0; k < iArrayLen; k++)
                            {
                                if (citHelper.IsEncrypt(dhi))
                                {
                                    for (int iTmp = 0; iTmp < channelNewList.Count; iTmp++)
                                    {
                                        if (channelNewList[iTmp].BNYChannelId > 6)
                                        {
                                            tmpRmsData = (short)((channelData[iTmp][k] / 10 - channelList[iTmp].fOffset) * channelList[iTmp].fScale);
                                        }
                                        else
                                        {
                                            tmpRmsData = (short)((channelData[iTmp][k] - channelList[iTmp].fOffset) * channelList[iTmp].fScale);
                                        }
                                        tmpBytes = CitFileHelper.ByteXORByte(BitConverter.GetBytes(tmpRmsData));
                                        dataList.AddRange(tmpBytes);
                                    }
                                }
                                else
                                {
                                    for (int iTmp = 0; iTmp < channelNewList.Count; iTmp++)
                                    {
                                        try
                                        {
                                            if (channelNewList[iTmp].BNYChannelId > 6)
                                            {
                                                tmpRmsData = (short)((channelData[iTmp][k] / 10 - channelList[iTmp].fOffset) * channelList[iTmp].fScale);
                                            }
                                            else
                                            {
                                                tmpRmsData = (short)((channelData[iTmp][k] - channelList[iTmp].fOffset) * channelList[iTmp].fScale);
                                            }
                                            dataList.AddRange(BitConverter.GetBytes(tmpRmsData));
                                        }
                                        catch (Exception ex)
                                        {
                                            throw ex;
                                        }
                                    }
                                }
                                ///bw.BaseStream.Position = 100;
                                bw.Write(dataList.ToArray());
                                bw.Flush();

                                dataList.Clear();
                            }
                        }
                    }
                    //bw.Close();
                    //DateTime dt3 = DateTime.Now;
                    //Console.WriteLine("two :" + (dt3 - dt2).TotalSeconds.ToString());
                }

                //fs.Close();
            }
        }
Beispiel #19
0
        public double GetAppointMilestone(string citFile, long filePos)
        {
            //当前里程 【公里】
            double currentMilestone = 0;

            float mKm    = 0;
            float mMeter = 0;

            DataHeadInfo fi = citHelper.GetDataInfoHead(citFile);

            FileStream   fs = new FileStream(citFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader br = new BinaryReader(fs, Encoding.Default);

            br.BaseStream.Position = citHelper.GetSamplePointStartOffset(fi.iChannelNumber, DataOffset.ExtraLength);



            int iChannelNumberSize = fi.iChannelNumber * 2;

            byte[] b      = new byte[iChannelNumberSize];
            long   iArray = (br.BaseStream.Length - br.BaseStream.Position) / iChannelNumberSize;

            List <DataChannelInfo> channelList = citHelper.GetDataChannelInfoHead(citFile);
            var kmChannel = channelList.Where(s => s.sID == 1).FirstOrDefault();
            var mChannel  = channelList.Where(s => s.sID == 2).FirstOrDefault();

            //ChannelDefinitionList channelDefintions = new ChannelDefinitionList();
            //channelDefintions.channelDefinitionList = GetChannelDefinitionList(citFile);
            //ChannelDefinition kmChannel = channelDefintions.GetChannelByName("km", "公里");
            //ChannelDefinition mChannel = channelDefintions.GetChannelByName("m", "米");
            if (kmChannel == null)
            {
                throw new Exception("通道定义错误,找不到通道Km");
            }
            if (kmChannel == null)
            {
                throw new Exception("通道定义错误,找不到通道Meter");
            }

            if (br.BaseStream.Position <= filePos && br.BaseStream.Length > filePos)
            {
                br.BaseStream.Position = filePos;

                b = br.ReadBytes(iChannelNumberSize);
                if (Encryption.IsEncryption(fi.sDataVersion))
                {
                    b = Encryption.Translate(b);
                }
                short km = BitConverter.ToInt16(b, 0);
                short m  = BitConverter.ToInt16(b, 2);



                mKm    = km / kmChannel.fScale + kmChannel.fOffset;
                mMeter = m / mChannel.fScale + mChannel.fOffset;
            }
            else if (br.BaseStream.Length >= filePos)
            {
                br.BaseStream.Position = br.BaseStream.Length - iChannelNumberSize;

                b = br.ReadBytes(iChannelNumberSize);
                if (Encryption.IsEncryption(fi.sDataVersion))
                {
                    b = Encryption.Translate(b);
                }
                short km = BitConverter.ToInt16(b, 0);
                short m  = BitConverter.ToInt16(b, 2);

                mKm    = km / kmChannel.fScale + kmChannel.fOffset;
                mMeter = m / mChannel.fScale + mChannel.fOffset;
            }
            else if (br.BaseStream.Position < filePos)
            {
                b = br.ReadBytes(iChannelNumberSize);
                if (Encryption.IsEncryption(fi.sDataVersion))
                {
                    b = Encryption.Translate(b);
                }
                short km = BitConverter.ToInt16(b, 0);
                short m  = BitConverter.ToInt16(b, 2);

                mKm    = km / kmChannel.fScale + kmChannel.fOffset;
                mMeter = m / mChannel.fScale + mChannel.fOffset;
            }

            br.Close();
            fs.Close();

            currentMilestone = mKm + mMeter / 1000;

            return(currentMilestone);
        }
        /// <summary>
        /// 创建cit文件头
        /// </summary>
        /// <param name="citFileName"></param>
        /// <param name="dataHeadInfo"></param>
        /// <param name="channelList"></param>
        private void CreateCitHeader(string citFileName, DataHeadInfo dataHeadInfo, List <DataChannelInfo> channelList)
        {
            citHelper.WriteCitFileHeadInfo(citFileName, dataHeadInfo, channelList);

            citHelper.WriteDataExtraInfo(citFileName, "");
        }