commit b10bb2634e9ecc275dae86d67902fb5193a6f6ba
Author: silhavyj <jakub.sil@seznam.cz>
Date:   Fri Apr 22 08:58:50 2022 +0200

    re #9568 Broke config loader down into separate methods.

diff --git a/ld_client/LDClient/Program.cs b/ld_client/LDClient/Program.cs
index c58d5b8..fc2fb03 100644
--- a/ld_client/LDClient/Program.cs
+++ b/ld_client/LDClient/Program.cs
@@ -61,7 +61,5 @@ internal static class Program {
         while (true) {
             Thread.Sleep(MainLoopDelayMs);
         }
-        
-        return 0;
     }
 }
\ No newline at end of file
diff --git a/ld_client/LDClient/network/data/ConnectionStatus.cs b/ld_client/LDClient/network/data/ConnectionStatus.cs
index f5ea275..9cd1ded 100644
--- a/ld_client/LDClient/network/data/ConnectionStatus.cs
+++ b/ld_client/LDClient/network/data/ConnectionStatus.cs
@@ -1,11 +1,12 @@
 ﻿using System.Runtime.Serialization;
 
 namespace LDClient.network.data {
+    
     public enum ConnectionStatus {
+        
         [EnumMember(Value = "connected")]
         Connected,
         [EnumMember(Value = "disconnected")]
         Disconnected
-
     }
 }
diff --git a/ld_client/LDClient/network/data/DebuggerInfo.cs b/ld_client/LDClient/network/data/DebuggerInfo.cs
index cb38d91..9402110 100644
--- a/ld_client/LDClient/network/data/DebuggerInfo.cs
+++ b/ld_client/LDClient/network/data/DebuggerInfo.cs
@@ -4,6 +4,6 @@ namespace LDClient.network.data {
     public class DebuggerInfo {
         
         [JsonPropertyName("serial_number")]
-        public string SerialNumber { get; set; }
+        public string? SerialNumber { get; set; }
     }
 }
diff --git a/ld_client/LDClient/network/data/Payload.cs b/ld_client/LDClient/network/data/Payload.cs
index 57b5755..ae7302a 100644
--- a/ld_client/LDClient/network/data/Payload.cs
+++ b/ld_client/LDClient/network/data/Payload.cs
@@ -4,6 +4,7 @@ using Newtonsoft.Json;
 using JsonSerializer = System.Text.Json.JsonSerializer;
 
 namespace LDClient.network.data {
+    
     [JsonObject(MemberSerialization.OptIn)]
     public class Payload {
 
@@ -14,7 +15,6 @@ namespace LDClient.network.data {
         public string? HostName { get; set; }
 
         [JsonPropertyName("timestamp")]
-        //[Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter), "yyyy-MM-dd HH:mm:ss.ffffff")]
         public string? TimeStamp { get; set; }
 
         [JsonPropertyName("head_device")]
@@ -25,7 +25,6 @@ namespace LDClient.network.data {
         public DebuggerInfo?  BodyDevice { get; set; }
         
         [JsonPropertyName("status")]
-        //[Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))]
         public ConnectionStatus Status { get; set; }
 
 
diff --git a/ld_client/LDClient/utils/ConfigLoader.cs b/ld_client/LDClient/utils/ConfigLoader.cs
index b4ff02f..b57a506 100644
--- a/ld_client/LDClient/utils/ConfigLoader.cs
+++ b/ld_client/LDClient/utils/ConfigLoader.cs
@@ -1,10 +1,12 @@
-﻿using System.Runtime.InteropServices;
-using LDClient.utils.loggers;
+﻿using LDClient.utils.loggers;
 using Microsoft.Extensions.Configuration;
 
 namespace LDClient.utils {
     
     internal class ConfigLoader {
+
+        private const int ErrorExitCode = 1;
+        private const string ConfigFile = "appsettings.json";
         
         private const string LoggingSection = "Logging";
         private const string NetworkSection = "Network";
@@ -24,15 +26,15 @@ namespace LDClient.utils {
 
         #region Api
         
-        public string ApiBaseAddress { get; private set; }
-        public string ApiUsbEndPoint { get; private set; }
+        public string ApiBaseAddress { get; private set; } = null!;
+        public string ApiUsbEndPoint { get; private set; } = null!;
         public uint ApiPort { get; private set; }
 
         #endregion
 
         #region Cache
         
-        public string CacheFileName { get; private set; }
+        public string CacheFileName { get; private set; } = null!;
         public uint MaxRetries { get; private set; }
         public uint MaxEntries { get; private set; }
         public uint RetryPeriod { get; private set; }
@@ -40,13 +42,13 @@ namespace LDClient.utils {
         #endregion
 
         #region Detection
-        public string T32ProcessName { get; private set; }
+        public string T32ProcessName { get; private set; } = null!;
         public uint DetectionPeriod { get; private set; }
-        public string T32InfoLocation { get; private set; }
-        public string F32RemExecutable { get; private set; }
+        public string T32InfoLocation { get; private set; } = null!;
+        public string F32RemExecutable { get; private set; } = null!;
         public uint FetchInfoMaxAttempts { get; private set;  }
         public uint FetchInfoAttemptPeriod { get; private set; }
-        public string[] F32RemArguments { get; private set; }
+        public string[] F32RemArguments { get; private set; } = null!;
         public int T32RemSuccessExitCode { get; private set; }
         public int T32RemWaitTimeoutMs { get; private set; }
 
@@ -54,34 +56,59 @@ namespace LDClient.utils {
 
         public ConfigLoader() {
             var configuration = new ConfigurationBuilder()
-                .AddJsonFile("appsettings.json")
+                .AddJsonFile(ConfigFile)
                 .Build();
-            ReadAllSettings(configuration);
-        }
 
-        private void ReadAllSettings(IConfiguration configuration) {
+            ReadLoggerSection(configuration);
+            ReadApiSection(configuration);
+            ReadCacheSection(configuration);
+            ReadDebuggerSection(configuration);
+            
+            Console.WriteLine("Configuration successfully loaded!");
+        }
 
+        private void ReadLoggerSection(IConfiguration configuration) {
             try {
                 var logging = configuration.GetSection(LoggingSection);
-                //TODO: Exception handling
                 LogChunkSize = int.Parse(logging["LogChunkSize"]);
                 LogChunkMaxCount = int.Parse(logging["LogChunkMaxCount"]);
                 LogArchiveMaxCount = int.Parse(logging["LogArchiveMaxCount"]);
                 LogCleanupPeriod = int.Parse(logging["LogCleanupPeriod"]);
                 LogFlowType = (LogFlow)int.Parse(logging["LogFlowType"]);
                 LogVerbosityType = (LogVerbosity)int.Parse(logging["LogVerbosityType"]);
+            } catch (Exception e) {
+                Console.WriteLine(e.Message);
+                Environment.Exit(ErrorExitCode);
+            }
+        }
 
+        private void ReadApiSection(IConfiguration configuration) {
+            try {
                 var network = configuration.GetSection(NetworkSection);
                 ApiBaseAddress = network["ApiBaseAddress"];
                 ApiUsbEndPoint = network["ApiLDEndPoint"];
                 ApiPort = uint.Parse(network["ApiPort"]);
-                
+            } catch (Exception e) {
+                Console.WriteLine(e.Message);
+                Environment.Exit(ErrorExitCode);
+            }
+        }
+
+        private void ReadCacheSection(IConfiguration configuration) {
+            try {
                 var cache = configuration.GetSection(CacheSection);
                 RetryPeriod = uint.Parse(cache["RetryPeriod"]);
                 MaxEntries = uint.Parse(cache["MaxEntries"]);
                 MaxRetries = uint.Parse(cache["MaxRetries"]);
                 CacheFileName = cache["CacheFileName"];
-                
+            } catch (Exception e) {
+                Console.WriteLine(e.Message);
+                Environment.Exit(ErrorExitCode);
+            }
+        }
+
+        private void ReadDebuggerSection(IConfiguration configuration) {
+            try {
                 var debugger = configuration.GetSection(DdSection);
                 T32ProcessName = debugger["T32ProcessName"];
                 T32InfoLocation = debugger["T32InfoLocation"];
@@ -92,13 +119,9 @@ namespace LDClient.utils {
                 T32RemSuccessExitCode = int.Parse(debugger["T32RemSuccessExitCode"]);
                 T32RemWaitTimeoutMs = int.Parse(debugger["T32RemWaitTimeoutMs"]);
                 F32RemArguments = configuration.GetSection($"{DdSection}:F32RemCommands").GetChildren().Select(key => key.Value).ToArray();
-
-                Console.WriteLine("Configuration successfully loaded!");
-            } catch (FormatException e) {
-                //Console.WriteLine("Error reading app settings");
-                //TODO: remove stacktrace print in production
-                Console.WriteLine("Error during reading of configuration occurred!" + e);
-                throw new IOException("Reading of configuration file failed! " + e);
+            } catch (Exception e) {
+                Console.WriteLine(e);
+                Environment.Exit(ErrorExitCode);
             }
         }
     }
