using eCIAv2.Library.Config; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace eCIAv2.Library.Services { public class ConfigService { public string ConfigPath { get; private set; } = string.Empty; public eCIAConfig Config = new eCIAConfig(); public eCIAConfig LoadConfig(string configPath) { ConfigPath = configPath; if(File.Exists(configPath) == true) { var configJson = File.ReadAllText(ConfigPath); Config = JsonConvert.DeserializeObject(configJson); LogXnet.WriteLine($"eCIA Config read Success."); LogXnet.WriteLine($"Path:{ConfigPath}"); return Config; } LogXnet.WriteLine($"Config not exist.", LogXLabel.Error); LogXnet.WriteLine($"ConfigPath:{ConfigPath}", LogXLabel.Error); return null; } public eCIAConfig GetConfig() { return Config; } public eCIAChConfig GetConfigByCh(int ch) { if(Config?.Configs?.TryGetValue(ch, out var config) == true) { return config; } LogXnet.WriteLine($"Config CH {ch} not exist.", LogXLabel.Error); return null; } } }