public static FileFormat.AcquisitionInfo FromSPCLogData(string logData) { if (string.IsNullOrWhiteSpace(logData)) { return(null); } FileFormat.AcquisitionInfo retinfo = new FileFormat.AcquisitionInfo(); logData = logData.Replace("\n", ""); logData = logData.Replace("\0", ""); string[] logs = logData.Split('\r'); var props = typeof(FileFormat.AcquisitionInfo).GetProperties(); int tempint; double tempdouble; foreach (var item in props) { //按参数名称在Log中查找,例如:SCANS = 4 string valuestr = logs.FirstOrDefault(p => p.IndexOf(item.Name + " = ") == 0); if (valuestr != null) { valuestr = valuestr.Substring((item.Name + " = ").Length); //去掉前面的名称和' = ', 只保留值 if (item.PropertyType == typeof(int)) { if (int.TryParse(valuestr, out tempint)) { item.SetValue(retinfo, tempint, null); } } else if (item.PropertyType == typeof(double)) { if (double.TryParse(valuestr, out tempdouble)) { item.SetValue(retinfo, tempdouble, null); } } else if (item.PropertyType == typeof(string)) { item.SetValue(retinfo, valuestr, null); } else if (item.PropertyType == typeof(FileFormat.enumIRMODE)) { if (int.TryParse(valuestr, out tempint)) { item.SetValue(retinfo, tempint, null); } item.SetValue(retinfo, (FileFormat.enumIRMODE)tempint, null); } } } return(retinfo); }
/// <summary> /// 生成Acquisition Log Data /// </summary> /// <returns></returns> public static string ToSPCLogData(FileFormat.AcquisitionInfo acquistData) { var props = typeof(FileFormat.AcquisitionInfo).GetProperties(); string retdata = null; int tempint; double tempdouble; foreach (var item in props) { string curstr = null; if (item.PropertyType == typeof(int)) { tempint = (int)item.GetValue(acquistData, null); if (tempint != 0) { curstr = tempint.ToString(); } } else if (item.PropertyType == typeof(double)) { tempdouble = (double)item.GetValue(acquistData, null); if (tempdouble != 0) { curstr = tempdouble.ToString(); } } else if (item.PropertyType == typeof(string)) { curstr = (string)item.GetValue(acquistData, null); } else if (item.PropertyType == typeof(FileFormat.enumIRMODE)) { curstr = ((int)((FileFormat.enumIRMODE)item.GetValue(acquistData, null))).ToString(); } if (!string.IsNullOrWhiteSpace(curstr)) { curstr = item.Name + " = " + curstr; retdata += curstr + "\r\n"; } } return(retdata); }