private async Task <LASSections> GetLASSections(string fileShare, string file) { LASSections lasSections = new LASSections(); string fileText = await fileStorageService.ReadFile(fileShare, file); char[] charSeparators = new char[] { '~' }; string[] sections = fileText.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); foreach (string section in sections) { string flag = section.Substring(0, 1); if (flag == "V") { lasSections.versionInfo = section; } if (flag == "W") { lasSections.wellInfo = section; } if (flag == "C") { lasSections.curveInfo = section; } if (flag == "P") { lasSections.parameterInfo = section; } if (flag == "A") { lasSections.dataInfo = section; } } return(lasSections); }
private void LoadParameterInfo() { DataAccessDef dataType = _dataDef.FirstOrDefault(x => x.DataType == "LogParameter"); if (dataType != null) { LASSections ls = lasSections[0]; string input = null; if (!string.IsNullOrEmpty(ls.parameterInfo)) { if (!LogParmExist()) { DataRow newRow; DataTable dtNew = new DataTable(); string logParmtable = Common.GetTable(dataType.Select); string sqlQuery = $"select * from {logParmtable} where 0 = 1"; SqlDataAdapter logParmAdapter = new SqlDataAdapter(sqlQuery, connectionString); logParmAdapter.Fill(dtNew); int seqNo = 0; StringReader sr = new StringReader(ls.parameterInfo); while ((input = sr.ReadLine()) != null) { LASLine line = DecodeLASLine(input); if (!string.IsNullOrEmpty(line.Mnem)) { seqNo++; newRow = dtNew.NewRow(); newRow["UWI"] = _uwi; newRow["WELL_LOG_ID"] = _logSource; newRow["WELL_LOG_SOURCE"] = "Source"; newRow["PARAMETER_SEQ_NO"] = seqNo; newRow["PARAMETER_TEXT_VALUE"] = line.Data.Trim(); newRow["REPORTED_DESC"] = line.Description.Trim(); newRow["REPORTED_MNEMONIC"] = line.Mnem.Trim(); newRow["ROW_CREATED_BY"] = _dbUserName; newRow["ROW_CHANGED_BY"] = _dbUserName; newRow["ROW_CREATED_DATE"] = DateTime.Now.ToString("yyyy-MM-dd"); newRow["ROW_CHANGED_DATE"] = DateTime.Now.ToString("yyyy-MM-dd"); dtNew.Rows.Add(newRow); } } if (dtNew.Rows.Count > 0) { using (SqlConnection destinationConnection = new SqlConnection(connectionString)) { destinationConnection.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection.ConnectionString)) { bulkCopy.BatchSize = 500; bulkCopy.DestinationTableName = logParmtable; bulkCopy.WriteToServer(dtNew); } } } } } } }
public async Task LoadLASFile(ConnectParameters source, ConnectParameters target, string fileName, string ReferenceTableDefJson) { _logSource = fileName; connectionString = target.ConnectionString; _dataDef = JsonConvert.DeserializeObject <List <DataAccessDef> >(target.DataAccessDefinition); _references = JsonConvert.DeserializeObject <List <ReferenceTable> >(ReferenceTableDefJson); lasAccessJson = JObject.Parse(await fileStorageService.ReadFile("connectdefinition", "LASDataAccess.json")); string lasMappingsStr = await fileStorageService.ReadFile("connectdefinition", "LASDataAccess.json"); lasMappings = JsonConvert.DeserializeObject <LASMappings>(lasMappingsStr); lasSections = new List <LASSections>(); LASSections ls = await GetLASSections(source.Catalog, fileName); lasSections.Add(ls); _dbConn.OpenConnection(target); _dbUserName = _dbConn.GetUsername(); GetVersionInfo(ls.versionInfo); string json = GetHeaderInfo(ls.wellInfo); LoadHeader(json); GetCurveInfo(ls.curveInfo); GetDataInfo(ls.dataInfo); LoadParameterInfo(); LoadLogs(); _dbConn.CloseConnection(); }
public async Task <DataTable> GetLASWellHeaders(ConnectParameters source, ConnectParameters target) { string accessJson = await fileStorageService.ReadFile("connectdefinition", "PPDMDataAccess.json"); _dataDef = JsonConvert.DeserializeObject <List <DataAccessDef> >(accessJson); //lasAccessJson = JObject.Parse(await fileStorageService.ReadFile("connectdefinition", "LASDataAccess.json")); string lasMappingsStr = await fileStorageService.ReadFile("connectdefinition", "LASDataAccess.json"); lasMappings = JsonConvert.DeserializeObject <LASMappings>(lasMappingsStr); List <string> files = new List <string>(); files = await GetLASFileNames(source.Catalog); DataAccessDef dataType = _dataDef.First(x => x.DataType == "WellBore"); string select = dataType.Select; string query = $" where 0 = 1"; _dbConn.OpenConnection(target); DataTable dt = _dbConn.GetDataTable(select, query); foreach (string file in files) { LASSections ls = await GetLASSections(source.Catalog, file); lasSections.Add(ls); GetVersionInfo(ls.versionInfo); string json = GetHeaderInfo(ls.wellInfo); DataRow row = dt.NewRow(); JObject jo = JObject.Parse(json); foreach (JProperty property in jo.Properties()) { string strValue = property.Value.ToString(); if (!string.IsNullOrEmpty(strValue)) { if (row.Table.Columns.Contains(property.Name)) { row[property.Name] = property.Value; } } } dt.Rows.Add(row); } return(dt); }