Tjiny
2025-05-20 74938606dd1dd8d7d77f053492b987f96a867338
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
using System;
using System.Collections.Generic;
using HH.WCS.Mobox3.Template.Entity.Dto;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
 
namespace HH.WCS.Mobox3.Template.Util.Helper
{
    public class Settings
    {
        public static string HostToAgvServerUrl { get; set; }
        public static string HASeverUrl { get; set; }
        public static string SqlServer { get; set; }
        public static string WMSBaseUrl { get; set; }
        public static string FourWayCarBaseUrl { get; set; }
        public static int port { get; set; }
        
        /// <summary>
        /// 输送线线体配置
        /// </summary>
        public static List<ConveyorlinesInfoDto> ConveyorlinesInfos { 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 == "FourWayCarBaseUrl") 
                            {
                                FourWayCarBaseUrl = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "WMSBaseUrl") 
                            {
                                WMSBaseUrl = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "HASeverUrl") {
                                HASeverUrl = keyValue.Value.ToString();
                            } 
                            if (keyValue.Name == "SqlServer") {
                                SqlServer = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "ApiPort") {
                                port = int.Parse(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "ConveyorlinesInfos") {
                                ConveyorlinesInfos = JsonConvert.DeserializeObject<List<ConveyorlinesInfoDto>>(keyValue.Value.ToString());
                            }
                        }
                    }
                }
                LogHelper.Info("加载配置文件信息 完成");
            }
            catch (Exception ex) {
                LogHelper.Error("加载配置文件失败!" + ex.Message, ex);
            }
 
        }
    }
}