ALineManager.cs
11.5 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
public class LineManager
{
private static bool isInit = false;
public static bool IsConnectServer = !ConfigAppSettings.GetValue(Setting_Init.http_server).Equals("");
public static LineBean Line = null;
public static Line_Config Config = null;
public static Dictionary<int, DeviceConfig> allConfigMap = null;
public LineManager()
{
}
public static void CheckEnum(Type type)
{
if (type.IsEnum)
{
List<int> valueList = new List<int>();
foreach (int item in Enum.GetValues(type))
{
if (valueList.Contains(item))
{
LogUtil.error( type.Name + "枚举值:" + item + "重复存在,请检查代码!程序退出。");
Application.Exit();
break;
}
valueList.Add(item);
}
}
}
public static bool Init()
{
try
{
if (!isInit)
{
Dictionary<int, MoveEquip_Config> moveECMap = null;
Dictionary<int, FeedingEquip_Config> feedingECMap = null;
Dictionary<int, ProvidingEquip_Config> providingECMap = null;
Dictionary<int, DischargeLine_Config> disChargeLineMap = null;
DeviceConfig.SubDIList = new Dictionary<int, Dictionary<string, ConfigIO>>();
DeviceConfig.SubDOList = new Dictionary<int, Dictionary<string, ConfigIO>>();
DeviceConfig.ProIOIpMap = new Dictionary<string, string>();
DeviceConfig.ProRFIpMap = new Dictionary<string, string>();
moveECMap = new Dictionary<int, MoveEquip_Config>();
feedingECMap = new Dictionary<int, FeedingEquip_Config>();
providingECMap = new Dictionary<int, ProvidingEquip_Config>();
disChargeLineMap = new Dictionary<int, DischargeLine_Config>();
allConfigMap = new Dictionary<int, DeviceConfig>();
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
if (server.Equals(""))
{
IsConnectServer = false;
}
else
{
IsConnectServer = true;
}
CheckEnum(typeof(LineMoveStep));
CheckEnum(typeof(LineStatus));
CheckEnum(typeof(LineRunStatus));
isInit = true;
string lineType = ConfigAppSettings.GetValue(Setting_Init.Line_Type);
LogUtil.info( " 类型=" + lineType + ",开始加载 配置");
if (lineType == DeviceType.Line)
{
string appPath = Application.StartupPath;
string CID = ConfigAppSettings.GetValue(Setting_Init.Line_CID);
string linefilePath = appPath + ConfigAppSettings.GetValue(Setting_Init.ConfigPath_Line);
Config = CSVConfigReader.LoadLineConfig(0, CID, DeviceType.Line, linefilePath);
allConfigMap.Add(0, Config);
int moveEquipCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_moveEquip_count);
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_MoveEquip);
for (int i = 1; i <= moveEquipCount; i++)
{
string nameStr = i.ToString().PadLeft(2, '0');
string config = appPath + moveEquipConfig.Replace(".csv", "_" + nameStr + ".csv");
MoveEquip_Config moveConfig = CSVConfigReader.LoadMoveConfig(i,DeviceType.MoveEquip, config);
int subType = i;
// moveConfig.SetIO(subType);
moveECMap.Add(i, moveConfig);
// allConfigMap.Add(subType, moveConfig);
}
foreach (int i in moveECMap.Keys)
{
int subType = i;
moveECMap[i].SetIO(subType);
allConfigMap.Add(subType, moveECMap[i]);
}
int feedingEquipCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_feedingEquip_count);
string feedingEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_FeedingEquip);
for (int i = 1; i <= feedingEquipCount; i++)
{
int subType = 100 + i;
string config = appPath + feedingEquipConfig.Replace(".csv", "_" + i + ".csv");
FeedingEquip_Config moveConfig = CSVConfigReader.LoadFeedingConfig(subType,DeviceType.FeedingEquip, config);
moveConfig.SetIO(subType);
feedingECMap.Add(subType, moveConfig);
allConfigMap.Add(subType, moveConfig);
}
int providingEquipCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_providingEquip_count);
string providingEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_ProvidingEquip);
for (int i = 1; i <= providingEquipCount; i++)
{
int subType = 200 + i;
string config = appPath + providingEquipConfig.Replace(".csv", "_" + i + ".csv");
ProvidingEquip_Config moveConfig = CSVConfigReader.LoadProvidingConfig(subType,DeviceType.ProvidingEquip, config);
moveConfig.SetIO(subType);
providingECMap.Add(subType, moveConfig);
allConfigMap.Add(subType, moveConfig);
}
int dislineCount = ConfigAppSettings.GetIntValue(Setting_Init.Line_dischargeLine_count);
string dischargeLineConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_DischargeLine);
for (int i = 1; i <= dislineCount; i++)
{
int subType = 300 + i;
string config = appPath + dischargeLineConfig.Replace(".csv", "_" + i + ".csv");
DischargeLine_Config moveConfig = CSVConfigReader.LoadDischargeLineConfig(subType,DeviceType.DischargeLine, config);
moveConfig.SetIO(subType);
disChargeLineMap.Add(subType, moveConfig);
allConfigMap.Add(subType, moveConfig);
}
Config.SetIO(1000);
Line = new LineBean(Config, moveECMap, feedingECMap, providingECMap, disChargeLineMap);
LogUtil.info( "加载 完成!");
return true;
}
}
else if (Line != null)
{
return true;
}
}
catch (Exception ex)
{
LogUtil.error("出错:"+ ex);
MessageBox.Show(ex.ToString(), "加载配置错误(请检查配置)");
Application.Exit();
}
return false;
}
public static void SaveMoveEquipConfig(MoveEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_MoveEquip);
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + config.Id.ToString().PadLeft(2,'0') + ".csv");
allConfigMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config,typeof(MoveEquip_Config));
if (!result)
{
LogUtil.error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LogUtil.error("出错:"+ ex);
}
}
public static void SaveFeedingEquipConfig(FeedingEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_FeedingEquip);
int id = config.Id - 100;
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + id+ ".csv");
allConfigMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config,typeof(FeedingEquip_Config));
if (!result)
{
LogUtil.error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LogUtil.error("出错:"+ ex);
}
}
public static void SaveProvidingEquipConfig(ProvidingEquip_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_ProvidingEquip);
int id = config.Id - 200;
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + id + ".csv");
allConfigMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config,typeof(ProvidingEquip_Config));
if (!result)
{
LogUtil.error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LogUtil.error("出错:"+ ex);
}
}
public static void SaveDischargeLineConfig(DischargeLine_Config config)
{
try
{
//位置配置到文件中
string appPath = Application.StartupPath;
string moveEquipConfig = ConfigAppSettings.GetValue(Setting_Init.ConfigPath_DischargeLine);
int id = config.Id - 300;
string configStr = appPath + moveEquipConfig.Replace(".csv", "_" + id + ".csv");
// disChargeLineMap[config.Id] = config;
allConfigMap[config.Id] = config;
bool result = CSVConfigReader.SaveConfig(configStr, config, typeof(DischargeLine_Config));
if (!result)
{
LogUtil.error("保存配置文件失败:" + configStr);
}
}
catch (Exception ex)
{
LogUtil.error("出错:"+ ex);
}
}
}
}