Index: Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs =================================================================== diff -u -r3937c582facb03372a3676b1ebf0ef158005a9ab -r24a4e65f8626b984a0345e3b3b505c768da360f3 --- Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs (.../ConfigurationReader.cs) (revision 3937c582facb03372a3676b1ebf0ef158005a9ab) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs (.../ConfigurationReader.cs) (revision 24a4e65f8626b984a0345e3b3b505c768da360f3) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml; @@ -39,8 +40,9 @@ /// /// The type of calculation items read from XML. public abstract class ConfigurationReader + where TCalculationItem : IReadCalculationItem { - protected readonly XDocument xmlDocument; + private readonly XDocument xmlDocument; /// /// Creates a new instance of . @@ -69,6 +71,22 @@ } /// + /// Reads the configuration from the XML and creates a collection of corresponding . + /// + /// A collection of read . + public IEnumerable Read() + { + return ParseReadCalculationItems(xmlDocument.Root?.Elements()); + } + + /// + /// Parses a read calculation element. + /// + /// The read calculation element to parse. + /// A parsed . + protected abstract TCalculationItem ParseReadCalculation(XElement calculationElement); + + /// /// Validates whether a file exists at the provided . /// /// The file path to validate. @@ -152,5 +170,27 @@ throw new CriticalFileReadException(message); } } + + private IEnumerable ParseReadCalculationItems(IEnumerable elements) + { + foreach (XElement element in elements) + { + if (element.Name == ConfigurationSchemaIdentifiers.CalculationElement) + { + yield return ParseReadCalculation(element); + } + + if (element.Name == ConfigurationSchemaIdentifiers.FolderElement) + { + yield return ParseReadCalculationGroup(element); + } + } + } + + private ReadCalculationGroup ParseReadCalculationGroup(XElement folderElement) + { + return new ReadCalculationGroup(folderElement.Attribute(ConfigurationSchemaIdentifiers.NameAttribute)?.Value, + ParseReadCalculationItems(folderElement.Elements())); + } } } \ No newline at end of file