private void buttonX1_Click(object sender, EventArgs e) { ImgSaveNode imgNode = new ImgSaveNode(); imgNode.minImgTimeStamp = 132430780617149500; imgNode.maxImgTimeStamp = 132430780696989500; imgNode.sKM_Pole = "115600414_K5778_Z2-25_6_13"; imgNode.StationName = "safkw-sadfkji"; imgNode.lstImgId = new System.Collections.Generic.List <string>(); imgNode.lstImgId.Add("123234"); imgNode.lstImgId.Add("345erts"); imgNode.lstImgId.Add("adf2314"); imgNode.lstImgId.Add("abad34123"); imgNode.lstImgId.Add("asdflk192jsdf"); imgNode.lstImgId.Add("3454592jsdf"); string str = ComClassLib.FileOp.JsonHelper.GetJson(imgNode); MessageBox.Show(str); }
//任务1,不断读取MongoDB,并识别杆号变动 private void TaskGetPoleKM() { CallInfo?.Invoke($"T#读取匹配数据!\n"); Int64 imgTimeStamp = 0; ImgSaveNode imgNode = new ImgSaveNode(); imgNode.lstImgId = new List <string>(); while (_taskRunning) { //找到比当前时间戳大的定位信息132430780599149500 132430780617149500 132430780678989500 132430780696989500 List <BsonDocument> lstImgInfos = null; bool IsConnMongoDb = true; try { lstImgInfos = _mongodb.FindDataByLimit(imgTimeStamp, 1000);//132429982497195159 } catch { //MongoDB数据库出错! IsConnMongoDb = false; } if (!IsConnMongoDb) { try { // MongoDB数据库连接不上,重新连接数据库 IsConnMongoDb = _mongodb.Connect(); } catch { IsConnMongoDb = false; } } if (!IsConnMongoDb) { CallInfo?.Invoke("T#重新连接【任务】服务器(数据库)---[失败]。3秒后重试!\n"); Thread.Sleep(3000); continue; } if (lstImgInfos == null & lstImgInfos.Count < 1) { try { CallInfo?.Invoke($"T#等待任务数据,5秒后重试!\n"); Thread.Sleep(5000); } catch { //MongoDB数据库出错。不管! } continue; } #region 读取杆号 string sPoleNum, sStationName; for (int i = 0; i < lstImgInfos.Count; i++) { var imgInfo = lstImgInfos[i]; sPoleNum = imgInfo.GetValue("基础支柱号").AsString; sStationName = imgInfo.GetValue("StationName").AsString; if (imgTimeStamp == 0) //起步 { imgTimeStamp = imgInfo.GetValue("检测时间").AsInt64; imgNode.minImgTimeStamp = imgTimeStamp; imgNode.StationName = CurrStationName; imgNode.sKM_Pole = $"{imgInfo.GetValue("公里标(米)").ToString()}_{sPoleNum}"; //公里标_杆号 CurrPoleNum = sPoleNum; CurrStationName = sStationName; //写入当前站名称 WriteTaskInfo("stationname", CurrStationName); CallInfo?.Invoke($"T#杆号起步读取!" + imgTimeStamp + "s" + lstImgInfos.Count + "条\n"); continue; } else if (CurrPoleNum != sPoleNum) //如果不相等 改变当前支柱号和 获取目录 { imgTimeStamp = imgInfo.GetValue("检测时间").AsInt64; imgNode.maxImgTimeStamp = imgTimeStamp; CurrPoleNum = sPoleNum; lock (obj) { queImgInfo.Enqueue(imgNode); } imgNode = new ImgSaveNode(); imgNode.minImgTimeStamp = imgTimeStamp; //最小和最大有个重叠。 imgNode.StationName = CurrStationName; imgNode.sKM_Pole = $"{imgInfo.GetValue("公里标(米)").ToString()}_{sPoleNum}"; //公里标_杆号 CallInfo?.Invoke($"T#GYK+Pole" + imgNode.sKM_Pole + "\n"); imgNode.lstImgId = new List <string>(); break; } else { imgTimeStamp = imgInfo.GetValue("检测时间").AsInt64;//更新检测时间 } if (!CurrStationName.Equals(sStationName)) { CurrStationName = sStationName; //写入当前站点名称 WriteTaskInfo("stationname", CurrStationName); } } #endregion } }