|
|
@@ -0,0 +1,42 @@
|
|
|
+using System.IO.Abstractions;
|
|
|
+using System.Reflection;
|
|
|
+using System.Text.Json;
|
|
|
+
|
|
|
+namespace Quadarax.Application.QLiberace.Common.Configuration
|
|
|
+{
|
|
|
+ public static class OlbrcConfiguration
|
|
|
+ {
|
|
|
+
|
|
|
+ public static IFileSystem FileSystem { get; set; }
|
|
|
+ public static string ConfigurationFileName{ get; set; }
|
|
|
+
|
|
|
+ static OlbrcConfiguration()
|
|
|
+ {
|
|
|
+ FileSystem = new FileSystem();
|
|
|
+ ConfigurationFileName = "qlbrc.json";
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Settings? Get()
|
|
|
+ {
|
|
|
+ if (!FileSystem.File.Exists(ConfigurationFileName))
|
|
|
+ return null;
|
|
|
+
|
|
|
+ return JsonSerializer.Deserialize<Settings>(FileSystem.File.ReadAllText(ConfigurationFileName));
|
|
|
+ }
|
|
|
+ public static ModuleConfiguration Get(string moduleName)
|
|
|
+ {
|
|
|
+ var result = Get();
|
|
|
+ if (result == null)
|
|
|
+ throw new InvalidOperationException(
|
|
|
+ $"Cannot obtain configuration from file '{ConfigurationFileName}'.");
|
|
|
+ var module = result.Modules.FirstOrDefault(x =>
|
|
|
+ string.Equals(x.Code, moduleName, StringComparison.InvariantCultureIgnoreCase));
|
|
|
+ if (module==null)
|
|
|
+ throw new InvalidOperationException(
|
|
|
+ $"Module '{moduleName}' not found in configuration file '{ConfigurationFileName}'.");
|
|
|
+
|
|
|
+ return module;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|