Program.cs
4.6 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
using BLL;
using log4net.Config;
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;
XmlConfigurator.Configure();
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 = log4net.LogManager.GetLogger("AgvServer");
Common.log.Info("=====程序开始=====");
ReadConfig();
Common.ReadLinePlace();
Common.mir = new MiR_API();
Common.control = new BLL.Control();
//软件开启时检查小车当前的任务状态
Common.CheckAGVMissionState();
Common.control.Start();
Common.server = new AgvServer();
Common.server.Start();
Common.web = new WebService();
Common.web.Open(Common.appConfig.AppSettings.Settings["WebService"].Value);
Application.Run(new FrmMain());
Common.control.Stop();
Common.server.Stop();
Common.web.Close();
Common.log.Info("=====程序结束=====\r\n");
}
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 != 4) 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], 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.nodeInfo = new List<ClientNode>();
Common.agvProductionLine = new Dictionary<string, string>();
path = Common.CONFIG_PATH + "AgvProductionLine.csv";
line = System.IO.File.ReadAllLines(path);
for (int i = 0; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 3) continue;
Common.agvProductionLine.Add(temp[0], temp[1]);
bool isUse = Convert.ToBoolean(Common.appConfig.AppSettings.Settings[temp[1]].Value);
Common.nodeInfo.Add(new ClientNode(temp[1], temp[2], isUse));
}
Common.itsHttp = Common.appConfig.AppSettings.Settings["ITS"].Value;
}
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);
}
}
}