Weighing: Restructure class structure
This commit is contained in:
		@@ -4,6 +4,31 @@ using System.Linq;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Elwig.Helpers {
 | 
			
		||||
 | 
			
		||||
    public record struct ScaleConfig {
 | 
			
		||||
        public string Id;
 | 
			
		||||
        public string? Type;
 | 
			
		||||
        public string? Model;
 | 
			
		||||
        public string? Connection;
 | 
			
		||||
        public string? Empty;
 | 
			
		||||
        public string? Filling;
 | 
			
		||||
        public string? Limit;
 | 
			
		||||
        public string? Log;
 | 
			
		||||
        public string? _Log;
 | 
			
		||||
 | 
			
		||||
        public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, string? log) {
 | 
			
		||||
            Id = id;
 | 
			
		||||
            Type = type;
 | 
			
		||||
            Model = model;
 | 
			
		||||
            Connection = cnx;
 | 
			
		||||
            Empty = empty;
 | 
			
		||||
            Filling = filling;
 | 
			
		||||
            Limit = limit;
 | 
			
		||||
            _Log = log;
 | 
			
		||||
            Log = log != null ? Path.Combine(App.DataPath, log) : null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class Config {
 | 
			
		||||
 | 
			
		||||
        private readonly string FileName;
 | 
			
		||||
@@ -11,8 +36,8 @@ namespace Elwig.Helpers {
 | 
			
		||||
        public string DatabaseFile = App.DataPath + "database.sqlite3";
 | 
			
		||||
        public string? DatabaseLog = null;
 | 
			
		||||
        public string? Branch = null;
 | 
			
		||||
        public IList<string?[]> Scales;
 | 
			
		||||
        private readonly List<string?[]> ScaleList = [];
 | 
			
		||||
        public IList<ScaleConfig> Scales;
 | 
			
		||||
        private readonly List<ScaleConfig> ScaleList = [];
 | 
			
		||||
        private static readonly string[] trueValues = ["1", "true", "yes", "on"];
 | 
			
		||||
 | 
			
		||||
        public Config(string filename) {
 | 
			
		||||
@@ -34,12 +59,10 @@ namespace Elwig.Helpers {
 | 
			
		||||
            ScaleList.Clear();
 | 
			
		||||
            Scales = ScaleList;
 | 
			
		||||
            foreach (var s in scales) {
 | 
			
		||||
                string? scaleLog = config[$"scale.{s}:log"];
 | 
			
		||||
                if (scaleLog != null) scaleLog = Path.Combine(App.DataPath, scaleLog);
 | 
			
		||||
                ScaleList.Add([
 | 
			
		||||
                ScaleList.Add(new(
 | 
			
		||||
                    s, config[$"scale.{s}:type"], config[$"scale.{s}:model"], config[$"scale.{s}:connection"],
 | 
			
		||||
                    config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"], scaleLog
 | 
			
		||||
                ]);
 | 
			
		||||
                    config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"], config[$"scale.{s}:log"]
 | 
			
		||||
                ));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -51,11 +74,11 @@ namespace Elwig.Helpers {
 | 
			
		||||
            file.Write($"\r\n[database]\r\nfile = {DatabaseFile}\r\n");
 | 
			
		||||
            if (DatabaseLog != null) file.Write($"log = {DatabaseLog}\r\n");
 | 
			
		||||
            foreach (var s in ScaleList) {
 | 
			
		||||
                file.Write($"\r\n[scale.{s[0]}]\r\ntype = {s[1]}\r\nmodel = {s[2]}\r\nconnection = {s[3]}\r\n");
 | 
			
		||||
                if (s[4] != null) file.Write($"empty = {s[4]}\r\n");
 | 
			
		||||
                if (s[5] != null) file.Write($"filling = {s[5]}\r\n");
 | 
			
		||||
                if (s[6] != null) file.Write($"limit = {s[6]}\r\n");
 | 
			
		||||
                if (s[7] != null) file.Write($"log = {s[7]}\r\n");
 | 
			
		||||
                file.Write($"\r\n[scale.{s.Id}]\r\ntype = {s.Type}\r\nmodel = {s.Model}\r\nconnection = {s.Connection}\r\n");
 | 
			
		||||
                if (s.Empty != null) file.Write($"empty = {s.Empty}\r\n");
 | 
			
		||||
                if (s.Filling != null) file.Write($"filling = {s.Filling}\r\n");
 | 
			
		||||
                if (s.Limit != null) file.Write($"limit = {s.Limit}\r\n");
 | 
			
		||||
                if (s._Log != null) file.Write($"log = {s._Log}\r\n");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user