using System;
|
using System.Collections.Generic;
|
using System.IO;
|
|
using HH.WCS.Mobox3.AnGang;
|
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
|
// 根据 JSON 文件 生成对应的 C# 对象;网址:https://json2csharp.com/
|
|
namespace HH.WCS.Mobox3.AnGang {
|
public class Settings {
|
public static string WebApiUrl { get; set; }
|
public static string RCSApiUrl { get; set; }
|
public static string NDCApiUrl { get; set; }
|
public static string SqlServer { get; set; }
|
public static string TCPServerIP { get; set; }
|
public static int TCPServerPort { get; set; }
|
//public static List<Config.Area> Areas { get; set; }
|
public static List<List<string>> Areas { get; set; } = new List<List<string>>();
|
public static List<Config.Snap> Snaps { get; set; }
|
public static string CaptureUrl { get; set; }
|
|
/// <summary>
|
/// 库区字典(加载后就不变)
|
/// </summary>
|
//public static Dictionary<string, List<string>> AreaMap { get; set; } = new Dictionary<string, List<string>>();
|
|
public static void Init() {
|
// 加载配置文件
|
LoadJson();
|
|
// 针对 Areas 进行转换:将 Config 的 List 加载到 Dict 中
|
//LoadAreas();
|
}
|
|
private static void LoadJson() {
|
LogHelper.Info("加载配置文件信息 开始");
|
// JSON 文件路径
|
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "./config/config.json");
|
|
try {
|
// 读取 JSON 文件内容
|
string jsonContent = File.ReadAllText(filePath);
|
|
// 反序列化为 Root 对象
|
var root = JsonConvert.DeserializeObject<Config.Root>(jsonContent);
|
|
WebApiUrl = root.WebApiUrl;
|
RCSApiUrl = root.RCSApiUrl;
|
NDCApiUrl = root.NDCApiUrl;
|
SqlServer = root.SqlServer;
|
TCPServerIP = root.TCPServerIP;
|
TCPServerPort = root.TCPServerPort;
|
//Areas = root.Areas;
|
foreach (var item in root.Areas) {
|
Areas.Add(item.Codes);
|
}
|
Snaps = root.Snaps;
|
CaptureUrl = root.CaptureUrl;
|
|
}
|
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 Areas) {
|
// AreaMap.Add(area.Name, area.Codes);
|
//}
|
}
|
}
|
|
public class Config {
|
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
|
public class Area {
|
public string Name { get; set; }
|
public List<string> Codes { get; set; }
|
}
|
|
public class Root {
|
public string WebApiUrl { get; set; }
|
public string RCSApiUrl { get; set; }
|
public string NDCApiUrl { get; set; }
|
public string SqlServer { get; set; }
|
public string TCPServerIP { get; set; }
|
public int TCPServerPort { get; set; }
|
public List<Area> Areas { get; set; }
|
public List<Snap> Snaps { get; set; }
|
public string CaptureUrl { get; set; }
|
}
|
|
public class Snap {
|
public string Ip { get; set; }
|
public int Port { get; set; }
|
public string Name { get; set; }
|
public string Pwd { get; set; }
|
}
|
}
|
|
public class TaskName {
|
public const string 产品入库 = "产品入库";
|
public const string 产品部分出库 = "产品部分出库";
|
public const string 产品部分回库 = "产品部分回库";
|
public const string 盘点理货出库 = "盘点理货出库";
|
public const string 盘点理货回库 = "盘点理货回库";
|
}
|
}
|