using System;
|
using System.Collections.Generic;
|
using System.IO;
|
|
using HH.WCS.Mobox3.AnGang;
|
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
|
namespace HH.WCS.Mobox3.AnGang.AppStart {
|
public class Settings {
|
/// <summary>
|
/// 配置文件
|
/// </summary>
|
public static Config Config { get; set; }
|
|
/// <summary>
|
/// 库区字典(加载后就不变)
|
/// </summary>
|
public static Dictionary<string, List<string>> AreaMap { get; set; } = new Dictionary<string, List<string>>();
|
|
//public static Snap Snap { get; set; }
|
public static string CaptureUrl { get; set; }
|
|
public static void Init() {
|
// 加载配置文件
|
LoadJson();
|
|
// 针对 Areas 进行转换:将 Config 的 List 加载到 Dict 中
|
LoadAreas();
|
|
//Snap = Config.Snap[0]; // 目前本项目只有一个相机
|
CaptureUrl = Config.CaptureUrl; // 保存图片的根目录
|
}
|
|
private static void LoadJson() {
|
LogHelper.Info("加载配置文件信息 开始");
|
// JSON 文件路径
|
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "./config/config.json");
|
|
try {
|
// 读取 JSON 文件内容
|
string jsonContent = File.ReadAllText(filePath);
|
|
// 反序列化为 Config 对象
|
Config = JsonConvert.DeserializeObject<Config>(jsonContent);
|
}
|
catch (FileNotFoundException) {
|
LogHelper.Info("JSON 文件未找到");
|
}
|
catch (JsonException ex) {
|
LogHelper.Info($"JSON 解析错误: {ex.Message}");
|
}
|
catch (Exception ex) {
|
LogHelper.Info($"发生错误: {ex.Message}");
|
}
|
LogHelper.Info("加载配置文件信息 完成");
|
}
|
|
private static void LoadAreas() {
|
foreach (var area in Config.Areas) {
|
AreaMap.Add(area.Name, area.Codes);
|
}
|
}
|
}
|
}
|