Program.cs
6.1 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AGVControl
{
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);
//程序只能运行一次
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.Id == current.Id) continue; //自己
if (process.MainModule.FileName == current.MainModule.FileName)
{
//显示已打开的程序
API.ShowWindow(process.MainWindowHandle, API.SW_RESTORE);
API.SwitchToThisWindow(process.MainWindowHandle, true);
return;
}
}
Common.log = new Asa.File.Log(Common.LOG_PATH, "AgvControl");
Common.log.OutString("=====程序开始=====");
ReadConfig();
Common.chargeStatus = new ChargeStatus();
Common.mir = new BLL.MiR_API();
Common.control = new BLL.Control();
Common.control.Start();
Common.server = new BLL.AgvServer();
Common.server.Start();
Application.Run(new FrmMain());
Common.control.Stop();
Common.server.Stop();
Common.mir.Dispose();
Common.log.OutString("=====程序结束=====\r\n");
System.Threading.Thread.Sleep(100);
Common.log.Dispose();
System.Threading.Thread.Sleep(100);
Environment.Exit(0);
}
private static void ReadConfig()
{
string path;
string[] line;
string[] temp;
bool isuse;
Common.appConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
Common.agvInfo = new List<Agv_Info>();
path = Common.CONFIG_PATH + "AgvName.csv";
line = System.IO.File.ReadAllLines(path);
for (int i = 0; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 5) continue;
isuse = Convert.ToBoolean(Common.appConfig.AppSettings.Settings[temp[1]].Value);
Common.agvInfo.Add(new Agv_Info(temp[0], temp[1], temp[2], temp[3], temp[4], isuse));
}
Common.agvMission = new Dictionary<string, string>();
path = Common.CONFIG_PATH + "AgvMission.csv";
line = System.IO.File.ReadAllLines(path);
for (int i = 0; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 2) continue;
Common.agvMission.Add(temp[0], temp[1]);
}
Common.webService = new Dictionary<string, string>();
path = Common.CONFIG_PATH + "Web.csv";
line = System.IO.File.ReadAllLines(path);
for (int i = 0; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 2) continue;
Common.webService.Add(temp[0], temp[1]);
}
Common.nodeInfo = new List<ClientNode>
{
new ClientNode("A1", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["A1"].Value)),
new ClientNode("A2", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["A2"].Value)),
new ClientNode("A3", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["A3"].Value)),
new ClientNode("A4", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["A4"].Value)),
new ClientNode("B1", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["B1"].Value)),
new ClientNode("B2", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["B2"].Value)),
new ClientNode("B3", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["B3"].Value)),
new ClientNode("B4", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["B4"].Value)),
new ClientNode("B5", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["B5"].Value)),
new ClientNode("B6", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["B6"].Value)),
new ClientNode("C1", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C1"].Value)),
new ClientNode("C2", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C2"].Value)),
new ClientNode("C3", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C3"].Value)),
new ClientNode("C4", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C4"].Value)),
new ClientNode("C5", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C5"].Value)),
new ClientNode("C6", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C6"].Value)),
new ClientNode("C7", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C7"].Value)),
new ClientNode("C8", Convert.ToBoolean(Common.appConfig.AppSettings.Settings["C8"].Value))
};
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Common.log.OutError((Exception)e.ExceptionObject);
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
Common.log.OutError(e.Exception);
}
}
}