Program.cs
5.8 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
using BLL;
using log4net.Config;
using log4net.Util.TypeConverters;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
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.logTextBox = new TextBox();
//Common.missionView = new DataGridView();
Common.missionManager = new MissionManager();
Common.log = log4net.LogManager.GetLogger("AgvServer");
Common.log.Info("=====程序开始=====");
ReadConfig();
Common.ReadLinePlace();
Common.mir = new MiR_API();
Common.control = new BLL.Control();
//获取节点位置
Common.GetNodesPosition();
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;
string rfid = "";
Common.appConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
Common.agvInfo = new List<Agv_Info>();
path = Common.CONFIG_PATH + SettingString.FileName_AGV;
line = System.IO.File.ReadAllLines(path, Encoding.UTF8);
for (int i = 1; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 5) continue;
//string val = Common.appConfig.AppSettings.Settings[temp[1]].Value;
bool.TryParse(Common.ReadIni(temp[1], SettingString.IsUse), out isuse); //Convert.ToBoolean(val.Split(',')[0]);
rfid = Common.ReadIni(temp[1], SettingString.RFID); //val.Split(',')[1];
Common.agvInfo.Add(new Agv_Info(temp[0], temp[1], temp[2], temp[3], temp[4], isuse, rfid));
}
Common.agvMission = new Dictionary<string, string>();
Common.showNameMissionName = new Dictionary<string, string>();
path = Common.CONFIG_PATH + SettingString.FileName_AgvMission;
line = System.IO.File.ReadAllLines(path, Encoding.UTF8);
for (int i = 1; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 3) continue;
Common.agvMission.Add(temp[1], temp[2]);
Common.showNameMissionName.Add(temp[0], temp[1]);
}
Common.nodeInfo = new List<ClientNode>();
path = Common.CONFIG_PATH + SettingString.FileName_AgvProductionLine;
line = System.IO.File.ReadAllLines(path, Encoding.GetEncoding("gb2312"));
for (int i = 1; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 6) continue;
Boolean.TryParse(Common.ReadIni(temp[1], SettingString.IsUse), out bool isUse);
Int32.TryParse(Common.ReadIni(temp[1], SettingString.EmptyShelfCnt), out int emptyShelfCnt);
if (temp[1].Equals("A5"))
{
Common.nodeInfo.Add(new DoubleLineNodeFor4C(temp[1], temp[2], temp[3], temp[0], temp[4], temp[5], isUse, emptyShelfCnt));
}
else if (temp[1].Equals("A6"))
{
Common.nodeInfo.Add(new DoubleLineNodeFor4D(temp[1], temp[2], temp[3], temp[0], temp[4], temp[5], isUse, emptyShelfCnt));
}
else
Common.nodeInfo.Add(new ClientNode(temp[1], temp[2], temp[3], temp[0], temp[4], temp[5], isUse, emptyShelfCnt));
}
Common.chargeStatus = new ChargeStatus();
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);
}
}
}