杨前锦
2025-05-26 d0a265713fd18162f3a82bdcd22e267df7298c7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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.YNJT_BZP_GT.util.Settings;
 
namespace HH.WCS.Mobox3.YNJT_BZP_GT.util
{
    public class Settings
    {
        public static string HostToAgvServerUrl { get; set; }
        public static string HASeverUrl { get; set; }
        public static string WMSSeverUrl { 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 == "WMSSeverUrl")
                            {
                                WMSSeverUrl = 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 AlertorDeviceInfo getAlertorAdress(int deviceNo) 
          {
              var alertorDeviceInfo = alertorLightInfos.Where(a => a.deviceNo == deviceNo).FirstOrDefault();
              return alertorDeviceInfo;
          }*/
 
        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; }
        }
 
    }
}