using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static HH.WCS.ZhongCeJinTan.util.Settings; namespace HH.WCS.ZhongCeJinTan.util { public class Settings { public static string SqlServer { get; set; } public static string TmDeviceIp { get; set; } //hosttoagv鉴权 //public static string AppKey { get; set; } //public static string AppSecret { get; set; } public static int TmDevicePort { get; set; } public static List safetyLocations { get; set; } public static string WcsApiAddres { get; set; } /// /// 空托缓存区 /// public static string EmptyPalletBufferArea { get; set; } /// /// Mes获取物料信息接口地址 /// public static string MesGetItemApi { get; set; } /// /// 配置 /// public static List deviceInfos { get; set; } /// /// 胎面设备配置 /// public static List TmDeviceInfos { get; set; } public static List areaInfos { get; set; } /// /// 优先级配置 /// //public static OutMinutePriority outMinutePriority { get; set; } /// /// NDC地址 /// 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 == "TableName") { var list = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); list.ForEach(a => STAttribute.attributes.Add(a.name, a.code)); } if (keyValue.Name == "SqlServer") { SqlServer = keyValue.Value.ToString(); } if (keyValue.Name == "WcsApiAddres") { WcsApiAddres = keyValue.Value.ToString(); } if (keyValue.Name == "MesGetItemApi") { MesGetItemApi = keyValue.Value.ToString(); } if (keyValue.Name == "NDCApiUrl") { NDCApiUrl = keyValue.Value.ToString(); } if (keyValue.Name == "TmDeviceIp") { TmDeviceIp = keyValue.Value.ToString(); } if (keyValue.Name == "TmDevicePort") { TmDevicePort = (int)keyValue.Value; } if (keyValue.Name == "EmptyPalletBufferArea") { EmptyPalletBufferArea = keyValue.Value.ToString(); } //hosttoagv鉴权 //if (keyValue.Name == "AppKey") //{ // AppKey = keyValue.Value.ToString(); //} //if (keyValue.Name == "AppSecret") //{ // AppSecret = keyValue.Value.ToString(); //} if (keyValue.Name == "SafetyLocation") { safetyLocations = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); } if (keyValue.Name == "TmDevice") { TmDeviceInfos = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); } //if (keyValue.Name == "OutMinutePriority") //{ // outMinutePriority = JsonConvert.DeserializeObject (keyValue.Value.ToString()); //} //if (keyValue.Name == "DeviceInfo") //{ // deviceInfos = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); //} //if (keyValue.Name == "AreaInfo") //{ // areaInfos = JsonConvert.DeserializeObject>(keyValue.Value.ToString()); //} } } } LogHelper.Info("加载配置文件信息 完成"); } catch (Exception ex) { LogHelper.Error("加载配置文件失败!" + ex.Message, ex); } } // "OutMinutePriority": { // "Minute": 10, // "Priority": 1 //}, public class OutMinutePriority { public int Minute { get; set; } public int Priority { get; set; } } public class TmDeviceInfo { public string deviceName { get; set; } public string locCode { get; set; } public int deviceType { get; set; } public int enable { get; set; } public int beginAddr { get; set; } public int writeSafetyAddr { get; set; } public int writeSafetyAddr1 { get; set; } public int readSafetyAddr { get; set; } public int readSafetyAddr1 { get; set; } public int endAddr { 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 areaInfo { public string[] startArea { get; set; } public string[] endArea { get; set; } public string carType { get; set; } } public class safetyLocation { public string name { get; set; } public List Area { get; set; } public int type{ get; set; } } public class TableName { public string name { get; set; } public string code { get; set; } } public class EndLoc { public string[] location; } public class zoneInfo { public string zone { get; set; } public string deviceName { get; set; } /// /// public int zoneType { get; set; } public int[] rows { get; set; } public int bits { get; set; } } public class zoneInfo1 { public string deviceName { get; set; } /// /// 库区列表,按数组下标顺序选择 /// public string[] zone { get; set; } public int zoneType { get; set; } } public class tpZone { public string zone { get; set; } public string deviceName { get; set; } /// /// public int zoneType { get; set; } public int bits { get; set; } public string address { get; set; } } } }