From 2bef545727d046fca53dda88e2c073b3af9429f8 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Thu, 15 Feb 2018 00:44:27 +0100 Subject: [PATCH] Make common configuration file optional. Refers to #29 --- ATxCommon/Serializables/ServiceConfig.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ATxCommon/Serializables/ServiceConfig.cs b/ATxCommon/Serializables/ServiceConfig.cs index 0963d73..a811ec8 100644 --- a/ATxCommon/Serializables/ServiceConfig.cs +++ b/ATxCommon/Serializables/ServiceConfig.cs @@ -281,12 +281,15 @@ namespace ATxCommon.Serializables // behaviour of the .NET XmlSerializer on duplicates: only the first occurrence is // used, all other ones are silentley being discarded - this way we simply append the // contents of the common config file to the host-specific and deserialize then: - var common = XElement.Load(commonFile); - Log.Debug("Loaded common configuration XML file: [{0}]", commonFile); var combined = XElement.Load(specificFile); Log.Debug("Loaded host specific configuration XML file: [{0}]", specificFile); - combined.Add(common.Nodes()); - Log.Trace("Combined XML structure:\n\n{0}\n\n", combined); + // the common configuration file is optional, so check if it exists at all: + if (File.Exists(commonFile)) { + var common = XElement.Load(commonFile); + Log.Debug("Loaded common configuration XML file: [{0}]", commonFile); + combined.Add(common.Nodes()); + Log.Trace("Combined XML structure:\n\n{0}\n\n", combined); + } using (var reader = XmlReader.Create(new StringReader(combined.ToString()))) { Log.Debug("Trying to parse combined XML."); -- GitLab