using Amazon.Runtime.Internal.Transform; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text.RegularExpressions; using ToolLibrary.LogHelper; using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto; using YunDa.SOMS.IODB; namespace Yunda.SOMS.DataMonitoringServer.SQLiteData { /// /// io数据处理 /// public class IODataHandle { public (int, List) GetIODataDic(string sqlPath) { int index = 0; var fileName = Path.GetFileName(sqlPath); List< IOState> iodic = new List(); try { var match = Regex.Match(fileName, @"\d+"); // 匹配数字 if (match.Success) { index =int.Parse( match.Value); Debug.WriteLine($"文件名中的数字: {match.Value}"); } var datetime = File.GetLastWriteTime(sqlPath); using (var context = new IodbContext(sqlPath)) { // 查询数据 var ios = context.Canioparas.OrderBy(io => io.ParaIndex).ToList(); string lastGroup = null; // 保存上一个 paraGroup Regex regex = new Regex(@"^开入\d"); // 用于匹配 "开入X" 的正则表达式 foreach (var io in ios) { if (!string.IsNullOrWhiteSpace(io.ParaGroup)&& regex.IsMatch(io.ParaGroup)) { iodic.Add( new IOState { Name = io.ParaGroup + io.ParaName, UpdateTime = datetime, Value = io.ParaValue + io.Unit } ); lastGroup = io.ParaGroup; } else if(string.IsNullOrWhiteSpace(io.ParaGroup)) { iodic.Add( new IOState { Name = lastGroup + io.ParaName, UpdateTime = datetime, Value = io.ParaValue + io.Unit } ); } else { iodic.Add( new IOState { Name = io.ParaGroup + io.ParaName, UpdateTime = default, Value = io.ParaValue + io.Unit } ); } } } } catch (Exception ex) { Log4Helper.Error(this.GetType(), "获取装置参数时发生错误", ex); return default; } return (index, iodic); } } }