/// <summary> /// 获取方阻的配置数据。 /// </summary> /// <returns></returns> public static DataFileReadConfig GetResistanceConfig(DateTime startTime) { //1 R_STARTROW 方租数据在文件中的起始行 //2 R_FILEPATH 方租读取的文件存放路径 //3 R_DATACOLUMN 方租数据行中列号 //4 R_SearchPattern 方租文件扩展名 //5 R_IdentityName 方租数据在行中标识符 //6 R_Separator 方租数据在行中分隔符 //7 R_Direction 方租数据的搜索方向 ComputerEntity entity = new ComputerEntity(); DataTable dtComputerUDA = entity.GetComputerInfo(); string startRow = entity.GetComputerUDAAttributeValue(dtComputerUDA, "R_STARTROW"); string filePath = entity.GetComputerUDAAttributeValue(dtComputerUDA, "R_FILEPATH"); string dataColumn = entity.GetComputerUDAAttributeValue(dtComputerUDA, "R_DATACOLUMN"); string identifyName = entity.GetComputerUDAAttributeValue(dtComputerUDA, "R_IdentityName"); string pattern = entity.GetComputerUDAAttributeValue(dtComputerUDA, "R_SearchPattern"); string separator = entity.GetComputerUDAAttributeValue(dtComputerUDA, "R_Separator"); string direction = entity.GetComputerUDAAttributeValue(dtComputerUDA, "R_Direction"); string fileName = string.Empty; pattern = pattern == string.Empty ? "*.*" : pattern; if (!string.IsNullOrEmpty(filePath) && System.IO.Directory.Exists(filePath)) { fileName = GetFileNameByLastTime(filePath, pattern, startTime); } DataFileReadConfig config = new DataFileReadConfig(); config.Column = string.IsNullOrEmpty(dataColumn) ? 9 : Convert.ToInt32(dataColumn); config.StartRow = string.IsNullOrEmpty(startRow) ? 0 : Convert.ToInt32(startRow); config.FileName = fileName; config.IdentityName = string.IsNullOrEmpty(identifyName) ? "POINT" : identifyName; config.Separator = string.IsNullOrEmpty(separator) ? ',' : separator.ToCharArray()[0]; config.SearchPattern = pattern; config.Direction = string.IsNullOrEmpty(direction) ? "F" : direction; if (System.IO.File.Exists(fileName)) { config.FileLastWriteTime = System.IO.File.GetLastWriteTime(fileName); } return(config); }
/// <summary> /// 获取折射率的配置数据。 /// </summary> /// <returns></returns> public static DataFileReadConfig GetRefractionConfig() { //1 A_STARTROW 折射率数据在文件中的起始行 //2 A_FILEPATH 折射率读取的文件存放路径 //3 A_DATACOLUMN 折射率数据行中列号 //4 A_SearchPattern 折射率文件扩展名 //5 A_IdentityName 折射率数据在行中标识符 //6 A_Separator 折射率数据在行中分隔符 //7 A_Direction 折射率数据的搜索方向 ComputerEntity entity = new ComputerEntity(); DataTable dtComputerUDA = entity.GetComputerInfo(); string startRow = entity.GetComputerUDAAttributeValue(dtComputerUDA, "A_STARTROW"); string filePath = entity.GetComputerUDAAttributeValue(dtComputerUDA, "A_FILEPATH"); string dataColumn = entity.GetComputerUDAAttributeValue(dtComputerUDA, "A_DATACOLUMN"); string identifyName = entity.GetComputerUDAAttributeValue(dtComputerUDA, "A_IdentityName"); string pattern = entity.GetComputerUDAAttributeValue(dtComputerUDA, "A_SearchPattern"); string separator = entity.GetComputerUDAAttributeValue(dtComputerUDA, "A_Separator"); string direction = entity.GetComputerUDAAttributeValue(dtComputerUDA, "A_Direction"); string fileName = string.Empty; pattern = pattern == string.Empty ? "*.*" : pattern; if (!string.IsNullOrEmpty(filePath) && System.IO.Directory.Exists(filePath)) { fileName = GetFileNameByLastTime(filePath, pattern); } DataFileReadConfig config = new DataFileReadConfig(); config.Column = string.IsNullOrEmpty(dataColumn) ? 2 : Convert.ToInt32(dataColumn); config.StartRow = string.IsNullOrEmpty(startRow) ? 0 : Convert.ToInt32(startRow); config.FileName = fileName; config.IdentityName = string.IsNullOrEmpty(identifyName) ? "n:" : identifyName; config.Separator = string.IsNullOrEmpty(separator) ? ' ' : separator.ToCharArray()[0]; config.SearchPattern = pattern; config.Direction = string.IsNullOrEmpty(direction) ? "F" : direction; return(config); }
/// <summary> /// 根据配置文件读取数据值集合。 /// </summary> /// <param name="config">配置数据。</param> /// <returns>获取的数据集合。</returns> public IList <DataFileReadValue> Reader(DataFileReadConfig config) { if (string.IsNullOrEmpty(config.FileName)) { throw new NoNullAllowedException("FileName 不能为空。"); } if (!System.IO.File.Exists(config.FileName)) { throw new System.IO.FileNotFoundException(config.FileName); } List <DataFileReadValue> lst = new List <DataFileReadValue>(); List <string> lstFileContent = new List <string>(); using (System.IO.StreamReader reader = new System.IO.StreamReader(config.FileName, Encoding.Default)) { string strLine = string.Empty; while ((strLine = reader.ReadLine()) != null) { if (config.Separator == ' ') { string pattern = string.Format("{0}+", config.Separator); strLine = Regex.Replace(strLine, pattern, config.Separator.ToString()); } lstFileContent.Add(strLine); } } int pointCount = config.PointCount; int startRow = config.StartRow; int count = 0; if (config.Direction == "B")//倒序读取 { if (startRow < 0) { startRow = lstFileContent.Count + startRow; } for (int i = startRow; i < lstFileContent.Count && i >= 0 && count < pointCount; i--) { string[] arr = lstFileContent[i].Split(config.Separator); if (arr.Contains(config.IdentityName)) { DataFileReadValue data = new DataFileReadValue(); if (config.Column < arr.Length) { data.Value = arr[config.Column]; } lst.Insert(0, data); count++; } } } else//正序读取 { if (startRow < 0) { startRow = lstFileContent.Count + startRow; } for (int i = startRow; i < lstFileContent.Count && i >= 0 && count < pointCount; i++) { string[] arr = lstFileContent[i].Split(config.Separator); if (arr.Contains(config.IdentityName)) { DataFileReadValue data = new DataFileReadValue(); if (config.Column < arr.Length) { data.Value = arr[config.Column]; } lst.Add(data); count++; } } } return(lst); }