public static Dictionary <int, Measurement> Convert(IODPDataTable dataTable, SectionInfoCollection SectionCollection) { _ = SectionCollection ?? throw new ArgumentNullException(nameof(SectionCollection)); _ = dataTable ?? throw new ArgumentNullException(nameof(dataTable)); Dictionary <int, Measurement> _measurements = new Dictionary <int, Measurement>(); int measurementCount = _measurements.Count + 1; //TODO: Ignore record if error is thrown, ex: offsets with TCON foreach (DataRow record in dataTable.DataTable.Rows) { SectionInfo measurementSectionInfo = new SectionInfo(); try { measurementSectionInfo.Expedition = record[dataTable.ExpeditionColumn].ToString(); measurementSectionInfo.Site = record[dataTable.SiteColumn].ToString(); measurementSectionInfo.Hole = record[dataTable.HoleColumn].ToString(); measurementSectionInfo.Core = record[dataTable.CoreColumn].ToString(); measurementSectionInfo.Type = record[dataTable.TypeColumn].ToString(); measurementSectionInfo.Section = record[dataTable.SectionColumn].ToString(); } catch (Exception) { throw new IndexOutOfRangeException(nameof(record)); } Measurement measurement = new Measurement(measurementSectionInfo); measurement.SectionInfo = SectionCollection.GetExistingElseAddAndGetCurrentSection(measurement.SectionInfo); //CARB files throw error here because there isn't an offset field within the file. Ensure there is. try { if (!string.IsNullOrEmpty(dataTable.OffsetColumn)) { measurement.StartOffset = double.Parse(record[dataTable.OffsetColumn].ToString(), CultureInfo.CurrentCulture); measurement.EndOffset = double.Parse(record[dataTable.OffsetColumn].ToString(), CultureInfo.CurrentCulture); } if (!string.IsNullOrEmpty(dataTable.TopOffsetColumn)) { measurement.StartOffset = double.Parse(record[dataTable.TopOffsetColumn].ToString(), CultureInfo.CurrentCulture); } if (!string.IsNullOrEmpty(dataTable.BottomOffsetColumn)) { measurement.EndOffset = double.Parse(record[dataTable.BottomOffsetColumn].ToString(), CultureInfo.CurrentCulture); } measurement.DataRow = record; _measurements.Add(measurementCount, measurement); measurementCount++; } catch (Exception) { //throw; } } return(_measurements); }
/// <summary> /// Converts an IODPDataTable object into a collection of Lithologic Descriptions /// </summary> /// <param name="dataTable">The datatable to convert</param> /// <returns></returns> public static Dictionary <string, LithologicDescription> ConvertDatatableToDictionary(IODPDataTable dataTable, SectionInfoCollection SectionCollection) { _ = SectionCollection ?? throw new ArgumentNullException(nameof(SectionCollection)); var LithologyCache = new Dictionary <string, LithologicDescription>(); if (dataTable == null) { return(LithologyCache); } //Add a column in the datatable to ensure consistency between files with and without descriptions: dataTable.DataTable.Columns.Add("LithologicID_VP", typeof(string)).SetOrdinal(0); foreach (DataRow dataTableRow in dataTable.DataTable.Rows) { dataTableRow["LithologicID_VP"] = "-1"; if (!Importer.DataRowContainsDescription(dataTableRow, dataTable)) { return(LithologyCache); } if (!Importer.DataRowContainsSampleIDColumn(dataTableRow, dataTable)) { return(LithologyCache); } LithologicDescription description = new LithologicDescription(dataTableRow[dataTable.SampleIDColumn].ToString()); description.SectionInfo = SectionCollection.GetExistingElseAddAndGetCurrentSection(description.SectionInfo); if (!Importer.DescriptionContainsSectionInfo(description)) { return(LithologyCache); } description.DataRow = dataTableRow; double parsedOffset = 0; if (!Importer.DataRowContainsOffsetColumns(dataTableRow, dataTable)) { return(LithologyCache); } if (!Importer.StartOffsetValuesAreValid(dataTableRow, dataTable, ref parsedOffset)) { return(LithologyCache); } description.StartOffset = parsedOffset; if (!Importer.EndOffsetValuesAreValid(dataTableRow, dataTable, ref parsedOffset)) { return(LithologyCache); } description.EndOffset = parsedOffset; LithologicIDGenerator IDGenerator = new LithologicIDGenerator(); IDGenerator.GenerateID(description); if (description.OffsetsSet()) { description.GenerateSubintervals(); } description.DataRow["LithologicID_VP"] = description.LithologicID; //Some descriptions are split in two rows. It's very uncommon, but throws an error //Only selecting the first row, despite the loss of data if (!LithologyCache.ContainsKey(description.LithologicID)) { LithologyCache.Add(description.LithologicID, description); } } return(LithologyCache); }