领胜LDS 键盘AOI检测项目
xcd
2020-07-01 9a9fb7a9e71b45bc3b91a0c48373e12d385680b8
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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
 
namespace Bro.Common.Helper
{
    public class SettingHelper
    {
        const string SETTINGFILE = "Setting.json";
        const string PROPERTY_PRODUCTIONCODES = "ProductionCodes";
        const string PROPERTY_CONFIGPATH = "ConfigPath";
        const string PROPERTY_PROCESSCODES = "ProcessCodes";
        const string PROPERTY_DESCRIPTION = "Description";
        const string PROPERTY_ICONPATH = "IconPath";
 
        static JObject data = null;
        static JObject Data
        {
            get
            {
                if (data == null)
                {
                    string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE);
                    if (File.Exists(configPath))
                    {
                        using (StreamReader reader = new StreamReader(configPath, System.Text.Encoding.UTF8))
                        {
                            string dataStr = reader.ReadToEnd();
                            data = JsonConvert.DeserializeObject<JObject>(dataStr);
                        }
                    }
                }
 
                return data;
            }
        }
 
        public static List<string> GetProductionCodes()
        {
            List<string> codes = new List<string>();
 
            if (Data != null && Data.ContainsKey(PROPERTY_PRODUCTIONCODES))
            {
                codes = Data.Value<JArray>(PROPERTY_PRODUCTIONCODES).ToList().ConvertAll(u => u.ToString());
            }
 
            if (codes.Count == 0)
            {
                codes.Add("Default");
            }
 
            return codes;
        }
 
        public static List<string> GetProcessCodes()
        {
            List<string> codes = new List<string>();
 
            if (Data != null && Data.ContainsKey(PROPERTY_PROCESSCODES))
            {
                codes = Data.Value<JArray>(PROPERTY_PROCESSCODES).ToList().ConvertAll(u => u.ToString());
            }
            return codes;
        }
 
        public static string GetConfigFilePath()
        {
            string path = "";
 
            if (Data != null && Data.ContainsKey(PROPERTY_CONFIGPATH))
            {
                path = Data.Value<string>(PROPERTY_CONFIGPATH);
            }
 
            return path;
        }
 
        public static string GetProgramDescription()
        {
            string desc = "伯肯森自动化技术有限公司";
 
            if (Data != null && Data.ContainsKey(PROPERTY_DESCRIPTION))
            {
                desc = Data.Value<string>(PROPERTY_DESCRIPTION);
            }
 
            return desc;
        }
 
        public static string GetProgramIcon()
        {
            string iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.ico");
 
            if (!File.Exists(iconPath))
            {
                iconPath = "";
            }
 
            if (Data != null && Data.ContainsKey(PROPERTY_ICONPATH))
            {
                iconPath = Data.Value<string>(PROPERTY_ICONPATH);
            }
 
            return iconPath;
        }
    }
}