Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/PipingCalculationGroupReader.cs =================================================================== diff -u -rd8d7d3d24763ec06d36322d9a57996a83a64653b -rd770836b6de01fc7535db4a73f7b1257d4b08fd1 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/PipingCalculationGroupReader.cs (.../PipingCalculationGroupReader.cs) (revision d8d7d3d24763ec06d36322d9a57996a83a64653b) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/PipingCalculationGroupReader.cs (.../PipingCalculationGroupReader.cs) (revision d770836b6de01fc7535db4a73f7b1257d4b08fd1) @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml; using System.Xml.Linq; using System.Xml.Schema; using Core.Common.IO.Exceptions; @@ -55,6 +56,29 @@ { IOUtils.ValidateFilePath(xmlFilePath); + ValidateFileExists(xmlFilePath); + + XDocument xmlDocument = LoadDocument(xmlFilePath); + + ValidateToSchema(xmlDocument); + } + + /// + /// Reads the piping configuration from the XML and creates a collection of corresponding . + /// + /// A collection of read . + public IEnumerable Read() + { + return Enumerable.Empty(); + } + + /// + /// Validates whether a file exists at the provided . + /// + /// The file path to validate. + /// Thrown when no file is found. + private static void ValidateFileExists(string xmlFilePath) + { if (!File.Exists(xmlFilePath)) { string message = new FileReaderErrorMessageBuilder(xmlFilePath).Build(CoreCommonUtilsResources.Error_File_does_not_exist); @@ -63,20 +87,32 @@ } /// - /// Reads a piping configuration from XML and creates a collection of corresponding . + /// Loads a XML document from the provided . /// - /// A collection of read . - public IEnumerable Read() + /// The file path to load the XML document from. + /// Thrown when the XML document cannot be loaded. + private static XDocument LoadDocument(string xmlFilePath) { - return Enumerable.Empty(); + try + { + return XDocument.Load(xmlFilePath); + } + catch (Exception exception) + when (exception is ArgumentNullException + || exception is XmlException + || exception is InvalidOperationException) + { + string message = new FileReaderErrorMessageBuilder(xmlFilePath).Build(CoreCommonUtilsResources.Error_General_IO_Import_ErrorMessage); + throw new CriticalFileReadException(message, exception); + } } /// /// Validates the provided XML document based on a predefined XML Schema Definition (XSD). /// /// The XML document to validate. /// Thrown when the provided XML document does not match the predefined XML Schema Definition (XSD). - private void ValidateToSchema(XDocument document) + private static void ValidateToSchema(XDocument document) { XmlSchemaSet schema = LoadXmlSchema(); @@ -90,10 +126,10 @@ } } - private XmlSchemaSet LoadXmlSchema() + private static XmlSchemaSet LoadXmlSchema() { - var schemaFile = AssemblyUtils.GetAssemblyResourceStream(GetType().Assembly, - "Ringtoets.Piping.IO.Readers.XMLPipingConfigurationSchema.xsd"); + Stream schemaFile = AssemblyUtils.GetAssemblyResourceStream(typeof(PipingCalculationGroupReader).Assembly, + "Ringtoets.Piping.IO.Readers.XMLPipingConfigurationSchema.xsd"); var xmlSchema = new XmlSchemaSet(); xmlSchema.Add(XmlSchema.Read(schemaFile, null));