Esempio n. 1
0
        private static LASLine DecodeLASLine(string input)
        {
            LASLine line = new LASLine();
            string  flag = input.Substring(0, 1);

            if (flag != "#")
            {
                int firstDot = input.IndexOf(".");
                if (firstDot > 0)
                {
                    line.Mnem = input.Substring(0, firstDot);
                    line.Mnem = line.Mnem.Trim();
                    input     = input.Substring(firstDot + 1);
                    int firstSpace = input.IndexOf(" ");
                    line.Unit = "";
                    if (firstSpace > 0)
                    {
                        line.Unit = input.Substring(0, firstSpace);
                        input     = input.Substring(firstSpace);
                    }
                    int lastColon = input.LastIndexOf(":");
                    if (lastColon > 0)
                    {
                        line.Data = input.Substring(0, lastColon);
                        line.Data = line.Data.Trim();
                        input     = input.Substring(lastColon + 1);
                    }
                    line.Description = input;
                    line.Description = line.Description.Trim();
                    return(line);
                }
            }

            return(line);
        }
Esempio n. 2
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void GetVersionInfo(string versionInfo)
        {
            string input        = null;
            bool   versionFound = false;

            StringReader sr = new StringReader(versionInfo);

            while ((input = sr.ReadLine()) != null)
            {
                LASLine line = DecodeLASLine(input);
                if (line.Mnem == "VERS")
                {
                    if (line.Data.Substring(0, 3) != "2.0")
                    {
                        throw new System.Exception("LAS file version not supported");
                    }
                    versionFound = true;
                }
                if (line.Mnem == "WRAP")
                {
                    if (line.Data != "NO")
                    {
                        throw new System.Exception("LAS file wrap is not supported");
                    }
                }
            }
            if (!versionFound)
            {
                throw new System.Exception("LAS file is missing the version tag");
            }
        }
Esempio n. 4
0
        private void GetCurveInfo(string curveInfo)
        {
            DataAccessDef dataType          = _dataDef.First(x => x.DataType == "Log");
            Dictionary <string, string> log = new Dictionary <string, string>();

            string[] attributes = Common.GetAttributes(dataType.Select);
            foreach (string attribute in attributes)
            {
                log.Add(attribute.Trim(), "");
            }

            string       input = null;
            StringReader sr    = new StringReader(curveInfo);

            while ((input = sr.ReadLine()) != null)
            {
                LASLine line = DecodeLASLine(input);
                if (!string.IsNullOrEmpty(line.Mnem))
                {
                    log["CURVE_ID"] = line.Mnem.Trim();
                    _logNames.Add(line.Mnem.Trim());
                    log["UWI"] = _uwi;
                    var json = JsonConvert.SerializeObject(log, Formatting.Indented);
                }
            }
        }
Esempio n. 5
0
        private void GetHeaderInfo(string wellInfo)
        {
            LASHeaderMappings           headMap  = new LASHeaderMappings();
            DataAccessDef               dataType = _dataDef.First(x => x.DataType == "WellBore");
            string                      input    = null;
            Dictionary <string, string> header   = new Dictionary <string, string>();

            string[] attributes = Common.GetAttributes(dataType.Select);
            foreach (string attribute in attributes)
            {
                header.Add(attribute.Trim(), "");
            }
            header["FINAL_TD"]          = "99999.0";
            header["SURFACE_LATITUDE"]  = "99999.0";
            header["SURFACE_LONGITUDE"] = "99999.0";
            header["DEPTH_DATUM_ELEV"]  = "99999.0";
            header["GROUND_ELEV"]       = "99999.0";
            header["ASSIGNED_FIELD"]    = "UNKNOWN";
            header["OPERATOR"]          = "UNKNOWN";
            header["DEPTH_DATUM"]       = "UNKNOWN";
            header["CURRENT_STATUS"]    = "UNKNOWN";
            header.Add("API", "");
            StringReader sr = new StringReader(wellInfo);

            while ((input = sr.ReadLine()) != null)
            {
                LASLine line = DecodeLASLine(input);
                if (!string.IsNullOrEmpty(line.Mnem))
                {
                    try
                    {
                        string key = headMap[line.Mnem];
                        header[key] = line.Data;
                        if (key == "NULL")
                        {
                            _nullRepresentation = line.Data;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (string.IsNullOrEmpty(header["UWI"]))
            {
                header["UWI"] = header["API"];
            }
            if (string.IsNullOrEmpty(header["UWI"]))
            {
                header["UWI"] = header["LEASE_NAME"] + "-" + header["WELL_NAME"];
            }
            string json = JsonConvert.SerializeObject(header, Formatting.Indented);

            _uwi = header["UWI"];
            LoadHeader(json);
        }
Esempio n. 6
0
        private void GetCurveInfo(string curveInfo)
        {
            string       input = null;
            StringReader sr    = new StringReader(curveInfo);

            while ((input = sr.ReadLine()) != null)
            {
                LASLine line = DecodeLASLine(input);
                if (!string.IsNullOrEmpty(line.Mnem))
                {
                    _logNames.Add(line.Mnem.Trim());
                    _mnemInfo.Add(new LASLine
                    {
                        Mnem        = line.Mnem.Trim(),
                        Unit        = line.Unit.Trim(),
                        Data        = line.Data.Trim(),
                        Description = line.Description
                    });
                }
            }
        }
Esempio n. 7
0
        private string GetHeaderInfo(string wellInfo)
        {
            LASHeaderMappings           headMap  = new LASHeaderMappings();
            DataAccessDef               dataType = _dataDef.First(x => x.DataType == "WellBore");
            string                      input    = null;
            Dictionary <string, string> header   = new Dictionary <string, string>();

            string[]         attributes          = Common.GetAttributes(dataType.Select);
            ColumnProperties attributeProperties = CommonDbUtilities.GetColumnSchema(_dbConn, dataType.Select);

            foreach (string attribute in attributes)
            {
                header.Add(attribute.Trim(), "");
            }
            header["ASSIGNED_FIELD"] = "UNKNOWN";
            header["OPERATOR"]       = "UNKNOWN";
            header["DEPTH_DATUM"]    = "UNKNOWN";
            header["CURRENT_STATUS"] = "UNKNOWN";
            header["ROW_CREATED_BY"] = _dbUserName;
            header["ROW_CHANGED_BY"] = _dbUserName;
            header.Add("API", "");
            StringReader   sr          = new StringReader(wellInfo);
            List <LASLine> headerMnems = new List <LASLine>();

            while ((input = sr.ReadLine()) != null)
            {
                LASLine line = DecodeLASLine(input);
                if (!string.IsNullOrEmpty(line.Mnem))
                {
                    headerMnems.Add(line);
                }
            }
            foreach (var line in headerMnems)
            {
                WellMapping mapping = lasMappings.WellMappings.FirstOrDefault(s => s.LASMnem == line.Mnem);
                if (mapping != null)
                {
                    string value = mapping.DBMnem;
                    header[value] = line.Data;
                    if (value == "NULL")
                    {
                        _nullRepresentation = line.Data;
                    }
                }
            }
            foreach (var alternativeKey in lasMappings.AlernativeKeys)
            {
                if (!string.IsNullOrEmpty(header["UWI"]))
                {
                    break;
                }
                string[] keys      = alternativeKey.Key.Split(',');
                string   seperator = "";
                foreach (var key in keys)
                {
                    LASLine line = headerMnems.FirstOrDefault(s => s.Mnem == key.Trim());
                    if (line != null)
                    {
                        if (!string.IsNullOrEmpty(line.Data))
                        {
                            header["UWI"] = seperator + line.Data;
                            seperator     = "-";
                        }
                    }
                }
            }
            foreach (string item in attributes)
            {
                string attribute     = item.Trim();
                string attributeType = attributeProperties[attribute];
                if (attributeType.Contains("nvarchar"))
                {
                    int?length = Regex.Match(attributeType, @"\d+").Value.GetIntFromString();
                    if (length != null)
                    {
                        header[attribute] = header[attribute].Truncate(length.GetValueOrDefault());
                    }
                }
            }
            string json = JsonConvert.SerializeObject(header, Formatting.Indented);

            _uwi = header["UWI"];
            return(json);
        }
Esempio n. 8
0
        private void LoadLogs()
        {
            DataRow        newRow;
            DataTable      dtNew                = new DataTable();
            DataAccessDef  dataType             = _dataDef.First(x => x.DataType == "LogCurve");
            string         select               = dataType.Select;
            string         logCurvetable        = Common.GetTable(select);
            string         sqlQuery             = $"select * from {logCurvetable} where 0 = 1";
            SqlDataAdapter logCurveValueAdapter = new SqlDataAdapter(sqlQuery, connectionString);

            logCurveValueAdapter.Fill(dtNew);

            _logCurveList = GetLogCurveList();
            _logList      = GetLogList();

            DataTable lgNew = new DataTable();

            dataType = _dataDef.First(x => x.DataType == "Log");
            select   = dataType.Select;
            string logTable = Common.GetTable(select);

            sqlQuery = $"select * from {logTable} where 0 = 1";
            SqlDataAdapter logValueAdapter = new SqlDataAdapter(sqlQuery, connectionString);

            logValueAdapter.Fill(lgNew);
            int logCount = _logNames.Count();

            GetIndexValues();
            for (int k = 1; k < logCount; k++)
            {
                string logName = Common.FixAposInStrings(_logNames[k]);
                dtNew = LoadLogCurve(logName, k, dtNew);
                if (!_logList.Contains(logName))
                {
                    LASLine mnemInfoItem = _mnemInfo.First(x => x.Mnem == logName);
                    string  description  = "";
                    if (mnemInfoItem != null)
                    {
                        description = mnemInfoItem.Description;
                    }
                    newRow                        = lgNew.NewRow();
                    newRow["UWI"]                 = _uwi;
                    newRow["CURVE_ID"]            = logName;
                    newRow["NULL_REPRESENTATION"] = _nullRepresentation;
                    newRow["VALUE_COUNT"]         = "-99999.0";
                    newRow["MAX_INDEX"]           = "-99999.0";
                    newRow["MIN_INDEX"]           = "-99999.0";
                    newRow["SOURCE"]              = _logSource;
                    newRow["REPORTED_DESC"]       = description;
                    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");
                    lgNew.Rows.Add(newRow);
                    _logList.Add(logName);
                }
            }

            using (SqlConnection destinationConnection =
                       new SqlConnection(connectionString))
            {
                destinationConnection.Open();

                using (SqlBulkCopy bulkCopy =
                           new SqlBulkCopy(destinationConnection.ConnectionString))
                {
                    bulkCopy.BatchSize            = 500;
                    bulkCopy.DestinationTableName = logTable;
                    bulkCopy.WriteToServer(lgNew);
                    bulkCopy.DestinationTableName = logCurvetable;
                    bulkCopy.WriteToServer(dtNew);
                }
            }
        }