private static void CleanupDescriptionFile(string filePath, string exportFilePath, string errorExportFilePath) { var iodpDataTable = Importer.ImportDataTableFromFile(filePath); string currentFileName = Importer.GetFileName(filePath); try { Importer.CheckFile(iodpDataTable); AddMissingColumnsToDescriptionTable(iodpDataTable.DataTable); AddDataToHierarchyColumns(iodpDataTable, Importer.GetFileName(filePath), SectionInfoCollection.ImportAllSections(ConfigurationManager.AppSettings["AllSectionsFile"])); Log.Information($"{currentFileName}: Processed successfully"); } catch (Exception ex) { Log.Warning($"{currentFileName}: {ex.Message}"); exportFilePath = errorExportFilePath; } try { Importer.ExportDataTableAsNewFile(exportFilePath, iodpDataTable.DataTable); } catch (Exception) { throw new Exception($"{currentFileName}: Error exporting to file"); } }
/// <summary> /// Gets a collection of LithologicDescriptions from a corrected file. /// </summary> /// <param name="filename"></param> /// <param name="columnIdentifiers"></param> /// <returns></returns> public static async Task <ICollection <LithologicDescription> > GetDescriptionsFromFileAsync(string filename, [Optional] IntervalHierarchyNames columnIdentifiers) { columnIdentifiers = columnIdentifiers ?? new IntervalHierarchyNames() { Expedition = "Expedition_VP", Site = "Site_VP", Hole = "Hole_VP", Core = "Core_VP", Type = "Type_VP", Section = "Section_VP", Half = "SectionHalf_VP", TopOffset = "TopOffset_VP", BottomOffset = "BottomOffset_VP", ArchiveTextID = "ArchiveSectionTextID_VP", WorkingTextID = "WorkingSectionTextID_VP", ParentTextID = "ParentSectionTextID_VP" }; IODPDataTable iODPDataTable = Importer.ImportDataTableFromFile(filename, columnIdentifiers); ICollection <LithologicDescription> descriptions = new HashSet <LithologicDescription>(); using (DescDBContext dbContext = new DescDBContext()) { try { foreach (DataRow row in iODPDataTable.DataTable.Rows) { SectionInfo section = new SectionInfo(Importer.GetHierarchyValuesFromDataRow(row, columnIdentifiers)); LithologicDescription description = new LithologicDescription(); // description.SectionInfo = section; description.SectionInfo = await DatabaseWorkflowHandler.GetSectionInfoFromDatabaseForIntervalAsync(dbContext, section).ConfigureAwait(true); description.LithologicID = row["LithologicID_VP"].ToString(); description.DataRow = row; description.DescriptionReport = row["Filename_VP"].ToString();; description.StartOffset = double.TryParse(row[columnIdentifiers.TopOffset].ToString(), out double startOffset) ? startOffset : -1; description.EndOffset = double.TryParse(row[columnIdentifiers.BottomOffset].ToString(), out double endOffset) ? endOffset : -1; descriptions.Add(description); } } catch (Exception) { throw new Exception("Error creating lithologic description from data row"); } } return(descriptions); }
/// <summary> /// Asynchronously gets a collection of IODP measurements from a .csv file. /// </summary> /// <param name="filename">The .csv file location</param> /// <param name="columnIdentifiers">Optional parameter which specifies the file's column names</param> /// <returns>A collection of measurements</returns> public static async Task <ICollection <Measurement> > GetMeasurementsFromFileAsync(string filename, [Optional] IntervalHierarchyNames columnIdentifiers) { columnIdentifiers = columnIdentifiers ?? new IntervalHierarchyNames() { Expedition = "Exp", Site = "Site", Hole = "Hole", Core = "Core", Type = "Type", Section = "Sect", Half = "A/W", TopOffset = "Offset (cm)", BottomOffset = "Offset (cm)", ArchiveTextID = "ArchiveSectionTextID_VP", WorkingTextID = "WorkingSectionTextID_VP", ParentTextID = "ParentSectionTextID_VP", SampleID = "Sample", TextID = "Text ID", TestNumber = "Test No.", }; //TODO: need to get this some other way string InstrumentSystem = Importer.GetFileNameWithoutExtension(filename); if (InstrumentSystem == "CARB" || InstrumentSystem == "ICP") { columnIdentifiers.TopOffset = "Top offset on section (cm)"; columnIdentifiers.BottomOffset = "Bot offset on section (cm)"; } IODPDataTable iODPDataTable = Importer.ImportDataTableFromFile(filename, columnIdentifiers); ICollection <Measurement> measurements = new HashSet <Measurement>(); try { foreach (DataRow row in iODPDataTable.DataTable.Rows) { IntervalHierarchyValues parsedValues = Importer.GetHierarchyValuesFromDataRow(row, columnIdentifiers); Measurement measurement = new Measurement(); measurement.SectionInfo = new SectionInfo(parsedValues); //Creating a SectionInfo here that will be used to find the one stored in the DB. measurement.DataRow = row; measurement.InstrumentReport = ""; measurement.InstrumentSystem = InstrumentSystem; measurement.TextID = parsedValues.TextID; measurement.TestNumber = parsedValues.TestNumber; measurement.StartOffset = double.TryParse(row[columnIdentifiers.TopOffset].ToString(), out double startOffset) ? startOffset : -1; measurement.EndOffset = double.TryParse(row[columnIdentifiers.BottomOffset].ToString(), out double endOffset) ? endOffset : -1; measurements.Add(measurement); } } catch (Exception) { throw new Exception("Error creating measurement from data row"); } using (DescDBContext dbContext = new DescDBContext()) { string[] expeditions = measurements.Select(x => x.SectionInfo.Expedition).Distinct().ToArray(); ICollection <SectionInfo> sections; try { sections = await DatabaseWorkflowHandler.GetAllSectionsFromDatabaseForExpeditionAsync(dbContext, expeditions).ConfigureAwait(false); } catch (Exception) { throw new Exception("Could not get sections from the database"); } foreach (var measurement in measurements) { measurement.SectionInfo = DatabaseWorkflowHandler.GetSectionInfoFromCollection(sections, measurement.SectionInfo); } return(measurements); } }