[성현모] DeviceManager, Factory 리팩토링, DIO, Scanner 추가
This commit is contained in:
52
eCIAv2.Library/Services/ConfigService.cs
Normal file
52
eCIAv2.Library/Services/ConfigService.cs
Normal file
@ -0,0 +1,52 @@
|
||||
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<eCIAConfig>(configJson);
|
||||
|
||||
LogXnet.WriteLine($"Config read Success.", LogXLabel.INFO);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user