Program.cs
5.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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Model;
namespace AGVControl_Steel
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Common.log = new Log("AGVControl_Steel");
Common.log.Info("=====程序开始=====");
if (BLL.RunMode.IsRun())
{
Common.log.Info("=====打开相同的程序,程序结束=====\r\n");
return;
}
ReadConfig();
Application.Run(new FrmMain());
Common.log.Info("=====程序结束=====\r\n");
}
private static bool RunMode()
{
if (BLL.RunMode.IsRun()) return false;
bool rtn = BLL.RunMode.IsAdmin();
if (!rtn) BLL.RunMode.AdminRun();
return rtn;
}
private static void ReadConfig()
{
Common.appConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
Common.FLEET_SEND = Convert.ToBoolean(Common.appConfig.AppSettings.Settings["FLEET_Send"].Value);
Common.BoardURL = Common.appConfig.AppSettings.Settings["Board"].Value;
Common.BoardTimeout = Convert.ToInt32(Common.appConfig.AppSettings.Settings["BoardTimeout"].Value);
Common.WorkTimeout = Convert.ToInt32(Common.appConfig.AppSettings.Settings["WorkTimeout"].Value);
Common.WorkTimeoutDel = Convert.ToBoolean(Common.appConfig.AppSettings.Settings["WorkTimeoutDel"].Value);
Common.WorkAutoDel = Convert.ToBoolean(Common.appConfig.AppSettings.Settings["WorkAutoDel"].Value);
Common.mir = new MiR_API { FleetIP = Common.appConfig.AppSettings.Settings["FLEET_IP"].Value };
ReadAgvInfo();
ReadAgvMission();
ReadAgvLine();
}
private static void ReadAgvInfo()
{
Common.agvInfos = new List<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 != 5) continue;
string isUse = "false";
if (Common.appConfig.AppSettings.Settings[str[1]] == null)
{
Common.appConfig.AppSettings.Settings.Add(str[1], "false");
Common.appConfig.Save();
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
}
else
{
isUse = Common.appConfig.AppSettings.Settings[str[1]].Value;
}
AgvInfo info = new AgvInfo(str[0], str[1], str[2], str[3], str[4])
{
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);
}
private static void ReadAgvMission()
{
Common.agvMissions = new Dictionary<string, 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.mir.MissionList = Common.agvMissions;
Common.log.Info("读取配置文件 " + Common.PATH_AGV_MISSION);
}
private static void ReadAgvLine()
{
Common.agvLines = new List<WorkshopLine>();
string[] lines = System.IO.File.ReadAllLines(Common.PATH_AGV_LINE, System.Text.Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
{
string[] str = lines[i].Split(',');
string[] temp = new string[str.Length - 1];
Array.Copy(str, 1, temp, 0, temp.Length);
WorkshopLine wl = new WorkshopLine
{
Workshop = str[0],
Lines = temp
};
Common.agvLines.Add(wl);
}
Common.log.Info("读取配置文件 " + Common.PATH_AGV_LINE);
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Common.log.Error("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject);
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
Common.log.Error("Application_ThreadException", e.Exception);
}
}
}