using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using SqlSugar;
|
using SqlSugar.Extensions;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using static HH.WCS.Mobox3.TSSG.util.Settings;
|
|
namespace HH.WCS.Mobox3.TSSG.util
|
{
|
public class Settings
|
{
|
public static string HostToAgvServerUrl { get; set; }
|
public static string HASeverUrl { get; set; }
|
public static string SqlServer { get; set; }
|
public static string SqlServer1 { get; set; }
|
public static List<DeviceInfo> deviceInfos { get; set; }
|
public static int port { get; set; }
|
public static string WHCode { get; set; }
|
public static string FacCode { get; set; }
|
public static string listenAddress { get; set; }
|
public static int WaitTime { get; set; }
|
public static string BufferArea { get; set; }
|
public static List<AgvAlarmNo> agvAlarmNoList { get; set; }
|
public static List<AlertorDeviceInfo> alertorLightInfos { get; set; }
|
|
public static void Init() {
|
LogHelper.Info("加载配置文件信息 开始");
|
try {
|
var jsonFile = System.AppDomain.CurrentDomain.BaseDirectory + "/config/config.json";
|
using (System.IO.StreamReader file = System.IO.File.OpenText(jsonFile)) {
|
using (JsonTextReader reader = new JsonTextReader(file)) {
|
JObject o = (JObject)JToken.ReadFrom(reader);
|
foreach (Newtonsoft.Json.Linq.JProperty keyValue in o.Properties()) {
|
Console.WriteLine(keyValue.Name);
|
if (keyValue.Name == "HostToAgvServerUrl") {
|
HostToAgvServerUrl = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "HASeverUrl") {
|
HASeverUrl = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "SqlServer") {
|
SqlServer = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "SqlServer1") {
|
SqlServer1 = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "WHCode") {
|
WHCode = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "FacCode") {
|
FacCode = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "ApiPort") {
|
port = int.Parse(keyValue.Value.ToString());
|
}
|
if (keyValue.Name == "DeviceInfo") {
|
deviceInfos = JsonConvert.DeserializeObject<List<DeviceInfo>>(keyValue.Value.ToString());
|
}
|
if (keyValue.Name == "ListenAddress")
|
{
|
listenAddress = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "WaitTime")
|
{
|
WaitTime = JsonConvert.DeserializeObject<int>(keyValue.Value.ToString());
|
}
|
if (keyValue.Name == "BufferArea")
|
{
|
BufferArea = keyValue.Value.ToString();
|
}
|
if (keyValue.Name == "AlertorLightDevice")
|
{
|
alertorLightInfos = JsonConvert.DeserializeObject<List<AlertorDeviceInfo>>(keyValue.Value.ToString());
|
}
|
if (keyValue.Name == "AgvAlarmNo")
|
{
|
agvAlarmNoList = JsonConvert.DeserializeObject<List<AgvAlarmNo>>(keyValue.Value.ToString());
|
}
|
}
|
}
|
}
|
LogHelper.Info("加载配置文件信息 完成");
|
}
|
catch (Exception ex) {
|
LogHelper.Error("加载配置文件失败!" + ex.Message, ex);
|
}
|
|
}
|
|
public static DeviceInfo getDeviceInfo(string locCode)
|
{
|
var deviceInfo = deviceInfos.Where(a => a.location.Contains(locCode)).FirstOrDefault();
|
return deviceInfo;
|
}
|
|
public class AgvAlarmNo
|
{
|
public int type { get; set; }
|
public int dex { get; set; }
|
public string code { get; set; }
|
public string name { get; set; }
|
}
|
|
public class AlertorDeviceInfo
|
{
|
public int deviceNo { get; set; }
|
public string address { get; set; }
|
public string turnLight { get; set; }
|
public string offLight { get; set; }
|
}
|
|
public class DeviceInfo
|
{
|
public string address { get; set; }
|
public string deviceName { get; set; }
|
public string[] deviceNo { get; set; }
|
public string[] location { get; set; }
|
|
public int deviceType { get; set; }
|
public int enable { get; set; }
|
}
|
public class TableName
|
{
|
public string name { get; set; }
|
public string code { get; set; }
|
}
|
|
}
|
}
|