// Copyright (C) Stichting Deltares 2020. All rights reserved. // // This file is part of the application DAM - Clients Library. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Linq; using Deltares.Geotechnics.IO.Importers; using Deltares.Geotechnics.Soils; using Deltares.Standard.Language; using Deltares.Standard.Logging; namespace Deltares.Dam.Data.StiImporter { /// /// Reader to read the contents of a sti file. /// public class StiFileReader { /// /// Reads the from a sti file. /// /// The file path to read from. /// A . /// Thrown when /// could not be read successfully. /// This only reads the names and the geometry of the soil layers. public SoilProfile2D ReadSoilProfile(string filePath) { var validator = new StiFileValidator(filePath); var validationMessages = validator.Validate(); if (validationMessages.Any()) { foreach (string message in validationMessages) { LogManager.Add(new LogMessage(LogMessageType.Error, this, message)); } string errorMessageFormat = LocalizationManager.GetTranslatedText(this, "ReadUnsupportedStiFile"); string errorMessage = string.Format(errorMessageFormat, filePath); throw new StiFileReadException(errorMessage); } try { var soilProfileImporter = new SoilProfile2DFromDSerieFileImporter(); SoilProfile2D soilProfile = soilProfileImporter.ConvertToSoilProfile2D(filePath); return soilProfile; } catch (Exception e) { string errorMessageFormat = LocalizationManager.GetTranslatedText(this, "ReadStiFileFailed"); string errorMessage = string.Format(errorMessageFormat, filePath, e.Message); throw new StiFileReadException(errorMessage, e); } } } }