Exemple #1
0
        private void Translate_Click(object sender, EventArgs e)
        {
            try
            {
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    string        directorypath = folderBrowserDialog.SelectedPath;
                    DirectoryInfo di            = new DirectoryInfo(directorypath);
                    FileInfo[]    fi            = di.GetFiles("NetRecvData*.dat");
                    if (fi.Length == 0)
                    {
                        MessageBox.Show("当前文件夹没有符合格式NetRecvData*.dat的文件!");
                        return;
                    }
                    List <FileInfo>  lf = new List <FileInfo>(fi);
                    DataTimeComparer dc = new DataTimeComparer();
                    lf.Sort(dc);
                    string log = MyExecPath + "\\Msp_LOG";
                    Directory.CreateDirectory(log);
                    string LogPath = log + "\\" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString();
                    ADPathInfo = Directory.CreateDirectory(LogPath);

                    TranslateWorker.RunWorkerAsync(lf);
                }
            }
            catch (Exception xe)
            {
                MessageBox.Show(xe.Message);
            }
        }
Exemple #2
0
        private void FilesWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <FileInfo>  lf = (List <FileInfo>)e.Argument;
            DataTimeComparer dc = new DataTimeComparer();

            lf.Sort(dc);
            BackgroundWorker worker = sender as BackgroundWorker;

            for (int i = 0; i < lf.Count; i++)
            {
                using (BinaryReader br = new BinaryReader(lf[i].OpenRead()))
                {
                    byte[] b = br.ReadBytes((int)lf[i].Length);

                    int    NodeId;
                    string time;
                    byte[] data;

                    if (isCommType)//串口数据
                    {
                        if (DepackData(b, out NodeId, out time, out data))
                        {
                            if (NodeId != 0)//收到的节点号
                            {
                                try
                                {
                                    SourceDataClass.GetData(data);
                                    SourceDataClass.ParseToLst();
                                    if (SourceDataClass.datalist.Count > 0)
                                    {
                                        foreach (string[] s in SourceDataClass.datalist)
                                        {
                                            s[2] = time;
                                        }
                                        DetailLstOfData.AddRange(SourceDataClass.datalist);
                                    }
                                    if (SourceDataClass.statuslist.Count > 0)
                                    {
                                        foreach (string[] s in SourceDataClass.statuslist)
                                        {
                                            s[1] = time;
                                        }

                                        DetailLstOfStatus.AddRange(SourceDataClass.statuslist);
                                    }
                                    TimeLst.Add(time);
                                    TimeData.Add(time, data);
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                    worker.ReportProgress((i + 1) * 100 / lf.Count);
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            FileInfo f = new FileInfo(lf[i].FullName);
                            Debug.WriteLine(lf[i].FullName + "解析错误");
                        }
                    }
                    else//网络数据
                    {
                        try
                        {
                            SourceDataClass.GetData(b);
                            int ret = SourceDataClass.ParseToLst();
                            time = lf[i].LastWriteTime.ToString();
                            if (ret == 1)
                            {
                                time += "(回环应答)";
                            }
                            if (SourceDataClass.datalist.Count > 0)
                            {
                                foreach (string[] s in SourceDataClass.datalist)
                                {
                                    s[2] = time;
                                }
                                DetailLstOfData.AddRange(SourceDataClass.datalist);
                            }
                            if (SourceDataClass.statuslist.Count > 0)
                            {
                                foreach (string[] s in SourceDataClass.statuslist)
                                {
                                    s[1] = time;
                                }

                                DetailLstOfStatus.AddRange(SourceDataClass.statuslist);
                            }
                            TimeLst.Add(time);
                            TimeData.Add(time, b);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.StackTrace);
                            worker.ReportProgress((i + 1) * 100 / lf.Count);
                            continue;
                        }
                    }
                }
                worker.ReportProgress((i + 1) * 100 / lf.Count);
            }
        }