Program.cs
4.7 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
using System;
using System.Windows.Forms;
namespace AGVControl_Steel
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
log4net.Config.XmlConfigurator.Configure();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (Asa.WindowsForm.IsRun())
{
MessageBox.Show("IsRun");
return;
}
if (!Asa.WindowsForm.IsAdmin())
{
Asa.WindowsForm.AdminRun();
return;
}
Common.appConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
Common.log = log4net.LogManager.GetLogger("AGVControl_Steel");
Common.log.Info("=====程序开始=====");
ReadConfig();
Common.steelManage = new BLL.SteelManage();
//Common.steelManage.OldSteelWorkLoad();
//Common.steelManage.NewSteelWorkLoad();
Common.control = new BLL.Control();
Common.mir = new Model.MiR_API { FleetIP = Common.appConfig.AppSettings.Settings["FLEET_IP"].Value, MissionList = Common.agvMissions };
Application.Run(new FrmMain());
Common.control.Stop();
Common.log.Info("=====程序结束=====\r\n");
}
private static void ReadConfig()
{
try
{
//AGV小车信息
Common.agvInfos = new System.Collections.Generic.List<Model.AgvInfo>();
string[] lines = System.IO.File.ReadAllLines(Common.PATH_AGV_NAME, System.Text.Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
{
string[] str = lines[i].Split(',');
if (str.Length != 4) continue;
string isUse = "false";
if (Common.appConfig.AppSettings.Settings[str[0]] == null)
{
Common.appConfig.AppSettings.Settings.Add(str[0], "false");
Common.appConfig.Save();
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
}
else
{
isUse = Common.appConfig.AppSettings.Settings[str[0]].Value;
}
Model.AgvInfo info = new Model.AgvInfo
{
FleetID = str[0],
Name = str[1],
IP = str[2],
Authorization = str[3],
IsAuto = Convert.ToBoolean(isUse),
BatteryMax = Convert.ToInt32(Common.appConfig.AppSettings.Settings["AGV_BATTERY_MAX"].Value),
BatteryMin = Convert.ToInt32(Common.appConfig.AppSettings.Settings["AGV_BATTERY_MIN"].Value)
};
Common.agvInfos.Add(info);
}
Common.log.Info("读取配置文件 " + Common.PATH_AGV_NAME);
//AGV任务ID号
Common.agvMissions = new System.Collections.Generic.Dictionary<string, string>();
lines = System.IO.File.ReadAllLines(Common.PATH_AGV_MISSION, System.Text.Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
{
string[] str = lines[i].Split(',');
if (str.Length != 2) continue;
Common.agvMissions.Add(str[0], str[1]);
}
Common.log.Info("读取配置文件 " + Common.PATH_AGV_MISSION);
Common.LINE_NAME_4D = Common.appConfig.AppSettings.Settings["4D_Line"].Value.Split(',');
Common.LINE_NAME_4C = Common.appConfig.AppSettings.Settings["4C_Line"].Value.Split(',');
Common.STORE_NAME = Common.appConfig.AppSettings.Settings["Store"].Value.Split(',');
string id = Common.appConfig.AppSettings.Settings["4D_AGV"].Value;
int idx = Common.agvInfos.FindIndex(match => match.FleetID == id);
if (idx > -1) Common.agvInfos[idx].Workshop = Common.WORKSHOP_4D;
id = Common.appConfig.AppSettings.Settings["4C_AGV"].Value;
idx = Common.agvInfos.FindIndex(match => match.FleetID == id);
if (idx > -1) Common.agvInfos[idx].Workshop = Common.WORKSHOP_4C;
}
catch (Exception ex)
{
Common.log.Error("ReadConfig()", ex);
}
}
}
}