using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using static HH.WCS.Mobox3.FJJT.util.Settings; namespace HH.WCS.Mobox3.FJJT.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 string OracleServer { get; set; } public static List deviceInfos { get; set; } public static List linePlcInfo { get; set; } public static List plcValue { get; set; } public static List areaPropertyList { get; set; } public static int port { get; set; } public static string WHCode { get; set; } public static string FacCode { get; set; } public static string NDCApiUrl { 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 == "NDCApiUrl") { NDCApiUrl = 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 == "OracleServer") { OracleServer = 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>(keyValue.Value.ToString()); } if (keyValue.Name == "linePlcInfo") { linePlcInfo = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); } if (keyValue.Name == "PlcValue") { plcValue = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); } if (keyValue.Name == "AreaProperty") { areaPropertyList = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); } } } } LogHelper.Info("加载配置文件信息 完成"); } catch (Exception ex) { LogHelper.Error("加载配置文件失败!" + ex.Message, ex); } } /// /// 查询不同容器的存储库区 /// /// /// public static List getCntrAreaList(int cntrType) { return areaPropertyList.Where(a => a.cntrType.Contains(cntrType)).Select(a => a.areaCode).ToList(); } public class AreaProperty { public string areaName { get; set; } public string areaCode { get; set; } public List cntrType { get; set; } // 容器类型 1.胎面;2.胎侧;3.内衬;4.帘布;5.环带;6.冠带;7.钢包 } public class deviceInfo { public string address { get; set; } public string deviceName { get; set; } public string[] deviceNo { get; set; } public string[] TN_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; } } public class LinePlcInfo { public string code { get; set; } public string location { get; set; } public string deviceNo { get; set; } public string address { get; set; } public int writeAddr { get; set; } public int readAddr { get; set; } public string[] useAddrNo { get; set; } public string inLoca { get; set; } public string outLoca { get; set; } public int enable { get; set; } } public class PlcValue { public string address { get; set; } public List read { get; set; } public List write { get; set; } } public class S7Model { /// /// 偏移量 /// public int addr { get; set; } /// /// 类型 /// public string type { get; set; } /// /// 长度 /// public int length { get; set; } /// /// 值 /// public string value { get; set; } } } }