WebServer.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. using centralController.model;
  2. using db;
  3. using nettyCommunication;
  4. using parkMonitor.LOG;
  5. using PLCS7;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace centralController.WebServer
  13. {
  14. class MyWebServer : IWebServer
  15. {
  16. private Queue<MessageUTF8> waitToReserveQueue = null;
  17. private Queue<MessageUTF8> reservedQueue = null;
  18. private object waitToReserveLock = new object();
  19. private object reservedLock = new object();
  20. private Communication comm = null;
  21. private Thread receiveMsg = null;
  22. private bool isClosing { get; set; }
  23. /// <summary>
  24. /// 是否正在调用函数进行连接
  25. /// </summary>
  26. private bool connecting { get; set; }
  27. /// <summary>
  28. /// 连接状态
  29. /// </summary>
  30. private bool connected { get; set; }
  31. public void BookFetchRecord()
  32. {
  33. throw new NotImplementedException();
  34. }
  35. public void BookParkRecord()
  36. {
  37. throw new NotImplementedException();
  38. }
  39. /// <summary>
  40. /// 更新预约车车辆状态
  41. /// </summary>
  42. /// <param name="localDB"></param>
  43. /// <param name="state"></param>
  44. /// <param name="orderRecordsID"></param>
  45. /// <param name="license"></param>
  46. /// <returns></returns>
  47. private bool UpdateVehicleState(bool localDB, int state, int orderRecordsID, string license)
  48. {
  49. string vehicleUpdateSql = "";
  50. string vehicleInsertSql = "";
  51. if (orderRecordsID > 0)
  52. {
  53. if (state >= 0)
  54. {
  55. vehicleUpdateSql = "update vehicle set vehiclepParkState = " + state + " ,orderRecordsID = " + orderRecordsID + " where numberPlate = '" + license + "';";
  56. vehicleInsertSql = "insert into vehicle (numberPlate,vehiclepParkState,orderRecordsID) values " +
  57. "('" + license + "'," + state + "," + orderRecordsID + ");";
  58. }
  59. else
  60. {
  61. vehicleUpdateSql = "update vehicle set orderRecordsID = " + orderRecordsID + " where numberPlate = '" + license + "';";
  62. vehicleInsertSql = "insert into vehicle (numberPlate,orderRecordsID) values " +
  63. "('" + license + "'," + orderRecordsID + ");";
  64. }
  65. }
  66. else
  67. {
  68. if (state >= 0)
  69. {
  70. vehicleUpdateSql = "update vehicle set vehiclepParkState = " + state + " where numberPlate = '" + license + "';";
  71. vehicleInsertSql = "insert into vehicle (numberPlate,vehiclepParkState) values " +
  72. "('" + license + "'," + state + ");";
  73. }
  74. else
  75. {
  76. return false;
  77. }
  78. }
  79. List<string> vehicleUpdateList = new List<string>();
  80. List<string> vehicleInsertList = new List<string>();
  81. vehicleUpdateList.Add(vehicleUpdateSql);
  82. vehicleInsertList.Add(vehicleInsertSql);
  83. DBOperation dbHandle = null;
  84. if (localDB)
  85. dbHandle = Monitor.Monitor.localDBOper;
  86. else
  87. dbHandle = Monitor.Monitor.remoteDBOper;
  88. if (!dbHandle.UpdateTransaction(vehicleUpdateList))
  89. {
  90. if (!dbHandle.Insert(vehicleInsertList, out int id))
  91. return false;
  92. else
  93. return true;
  94. }
  95. else return true;
  96. }
  97. /// <summary>
  98. /// 插入预约记录
  99. /// </summary>
  100. /// <param name="localDB"></param>
  101. /// <param name="userID"></param>
  102. /// <param name="parking"></param>
  103. /// <param name="license"></param>
  104. /// <param name="orderTime"></param>
  105. /// <param name="orderLength"></param>
  106. /// <returns></returns>
  107. private bool InsertOrderRecord(bool localDB, string userID, bool parking, string license, string orderTime, int orderLength, out int id)
  108. {
  109. bool result = false;
  110. string orderRecordInsertSql;
  111. if (parking)
  112. {
  113. orderRecordInsertSql = "insert into orderrecords (userID,numberPlate,garageID, bookParkTime, bookHour, bookPrice,bookState) " +
  114. "VALUES (" + userID + ", '" + license + "', '" + Monitor.Monitor.garageID + "', '" + orderTime + "', " + orderLength + ",NULL, '0');";
  115. }
  116. else
  117. {
  118. orderRecordInsertSql = "insert into orderrecords (userID,numberPlate,garageID, bookFetchTime, bookHour, bookPrice,bookState) " +
  119. "VALUES (" + userID + ", '" + license + "', '" + Monitor.Monitor.garageID + "', '" + orderTime + "', " + orderLength + ",NULL, '2');";
  120. }
  121. List<string> orderList = new List<string>();
  122. orderList.Add(orderRecordInsertSql);
  123. if (localDB)
  124. result = Monitor.Monitor.localDBOper.Insert(orderList, out id);
  125. else
  126. result = Monitor.Monitor.remoteDBOper.Insert(orderList, out id);
  127. return result;
  128. }
  129. /// <summary>
  130. /// 找到当前预约记录ID,暂未使用
  131. /// </summary>
  132. /// <param name="localDB"></param>
  133. /// <param name="license"></param>
  134. /// <param name="latestIndex">最近第几条记录,1表示最新一条</param>
  135. /// <returns></returns>
  136. private int FindCurrentOrderRecordID(bool localDB, string license, int latestIndex = 1)
  137. {
  138. int currentID = 0;
  139. int count = 10;
  140. while (count-- > 0 && currentID == 0)
  141. {
  142. List<object[]> orderRecords = Monitor.Monitor.GetOrderRecords(localDB, license, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
  143. if (orderRecords.Count != 0)
  144. {
  145. try
  146. {
  147. currentID = (int)(UInt32)orderRecords[latestIndex - 1][0];
  148. }
  149. catch { }
  150. }
  151. }
  152. return currentID;
  153. }
  154. /// <summary>
  155. /// 预约数据库操作
  156. /// </summary>
  157. /// <param name="localDB"></param>
  158. /// <param name="userID"></param>
  159. /// <param name="parking"></param>
  160. /// <param name="license"></param>
  161. /// <param name="orderTime"></param>
  162. /// <param name="orderLength"></param>
  163. /// <returns></returns>
  164. private bool ReserveDBOperation(bool localDB, string userID, bool parking, string license, string orderTime, int orderLength)
  165. {
  166. UpdateVehicleState(localDB, parking ? 4 : 5, 0, license);
  167. //预约记录插入db
  168. InsertOrderRecord(localDB, userID, parking, license, orderTime, orderLength, out int currentID);
  169. ////查询预约记录id号
  170. //int currentID = FindCurrentOrderRecordID(localDB, license);
  171. if (currentID == 0) { /*反馈web,预约失败*/ return false; }
  172. //更新车辆状态
  173. UpdateVehicleState(localDB, parking ? 4 : 5, currentID, license);
  174. return true;
  175. }
  176. /// <summary>
  177. /// 检查预约指令是否可行
  178. /// </summary>
  179. /// <param name="msg"></param>
  180. /// <returns></returns>
  181. private bool ReservationValidate(MessageUTF8 msg)
  182. {
  183. int allBookableSpace, count;
  184. lock (waitToReserveLock)
  185. {
  186. //可预约车位总数
  187. allBookableSpace = Monitor.Monitor.ins.GetFreeSpaceCount(4);
  188. count = 0;
  189. DateTime start, end;
  190. try
  191. {
  192. start = DateTime.Parse(msg.bookTime);
  193. end = start.AddHours(msg.bookLength);
  194. //Console.WriteLine("--------"+msg.bookTime+","+msg.bookLength);
  195. }
  196. catch { Console.WriteLine("时间解析异常1"); return false; }
  197. Queue<MessageUTF8>.Enumerator enumer = waitToReserveQueue.GetEnumerator();
  198. while (enumer.MoveNext())
  199. {
  200. DateTime tempStart, tempEnd;
  201. try
  202. {
  203. tempStart = DateTime.Parse(enumer.Current.bookTime);
  204. tempEnd = tempStart.AddHours(enumer.Current.bookLength);
  205. //Console.WriteLine("#########" + enumer.Current.bookTime + "," + enumer.Current.bookLength);
  206. }
  207. catch { Console.WriteLine("时间解析异常2"); return false; }
  208. //Console.WriteLine("**********" + start.ToString() + "," + end.ToString() + "," + tempStart.ToString() + "," + tempEnd.ToString());
  209. //Console.WriteLine("**********" + ((tempStart - end).TotalMinutes > 0)+","+ ((start - tempEnd).TotalMinutes > 0));
  210. if (!((tempStart - end).TotalMinutes > 0 || (start - tempEnd).TotalMinutes > 0)) { count += 1; }
  211. }
  212. Queue<MessageUTF8>.Enumerator enumer2 = reservedQueue.GetEnumerator();
  213. while (enumer2.MoveNext())
  214. {
  215. DateTime tempStart, tempEnd;
  216. try
  217. {
  218. tempStart = DateTime.Parse(enumer2.Current.bookTime);
  219. tempEnd = tempStart.AddHours(enumer2.Current.bookLength);
  220. //Console.WriteLine("#########" + enumer.Current.bookTime + "," + enumer.Current.bookLength);
  221. }
  222. catch { Console.WriteLine("时间解析异常2"); return false; }
  223. //Console.WriteLine("**********" + start.ToString() + "," + end.ToString() + "," + tempStart.ToString() + "," + tempEnd.ToString());
  224. //Console.WriteLine("**********" + ((tempStart - end).TotalMinutes > 0)+","+ ((start - tempEnd).TotalMinutes > 0));
  225. if (!((tempStart - end).TotalMinutes > 0 || (start - tempEnd).TotalMinutes > 0)) { count += 1; }
  226. }
  227. }
  228. Console.WriteLine("----------" + msg.context + ":" + allBookableSpace + "," + count);
  229. if (allBookableSpace > count)
  230. return true;
  231. else
  232. return false;
  233. }
  234. /// <summary>
  235. /// 根据消息类型分别处理
  236. /// </summary>
  237. /// <param name="msg"></param>
  238. private void MsgHandling(MessageUTF8 msg)
  239. {
  240. try
  241. {
  242. switch (msg.cmd)
  243. {
  244. //预约停
  245. case "RESERVE":
  246. if (msg.sender != "" && msg.bookTime != "" && msg.bookLength != 0)
  247. {
  248. MessageUTF8 returnMsg = new MessageUTF8();
  249. if (!ReservationValidate(msg))
  250. {
  251. //回复预约失败给web
  252. returnMsg.cmd = "FAILED";
  253. returnMsg.garageID = Monitor.Monitor.garageID;
  254. returnMsg.context = msg.context;
  255. comm.SendMessage(returnMsg);
  256. Monitor.Monitor.SetNotification("车辆" + msg.context + "预约停车,已无可预约车位", parkMonitor.model.TextColor.Warning);
  257. }
  258. else
  259. {
  260. bool DBOperResult = true;
  261. lock (waitToReserveLock)
  262. {
  263. waitToReserveQueue.Enqueue(msg);
  264. }
  265. //预约记录与车辆状态写入数据库
  266. DBOperResult = DBOperResult && ReserveDBOperation(true, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
  267. DBOperResult = DBOperResult && ReserveDBOperation(false, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
  268. //回复成功给web
  269. if (!DBOperResult)
  270. Log.WriteLog(LogType.process, LogFile.WARNING, msg.context+"从"+msg.bookTime+"开始预约"+msg.bookLength+"小时,预约指令数据库操作未获得记录ID");
  271. returnMsg.cmd = "OK";
  272. returnMsg.garageID = Monitor.Monitor.garageID;
  273. returnMsg.context = msg.context;
  274. comm.SendMessage(returnMsg);
  275. Monitor.Monitor.SetNotification("车辆" + msg.context + "预约停车,操作成功", parkMonitor.model.TextColor.Log);
  276. }
  277. }
  278. break;
  279. case "CANCELRESERVE":
  280. //IEqualityComparer<MessageUTF8> comparer ;
  281. //if(waitToReserveQueue.Contains(msg, )
  282. break;
  283. //预约取
  284. case "PREFETCH":
  285. break;
  286. //停车
  287. case "PARK":
  288. //根据号牌寻找对应号牌机编号,找不到则返回失败信息
  289. //判断号牌机编号对应PLC数据块是否空闲,空闲则判断按钮状态并发送停车指令到PLC,否则返回失败信息
  290. break;
  291. //取车
  292. case "FETCH":
  293. break;
  294. //连接断开消息
  295. case "DISCONNECT":
  296. Monitor.Monitor.SetNotification("收到连接断开提示消息", parkMonitor.model.TextColor.Warning);
  297. break;
  298. //更新广告
  299. case "ADVERT":
  300. string adAlert = "";
  301. bool result = Monitor.Monitor.advertMgr.UpdateAdvert(out adAlert);
  302. if (!result)
  303. {
  304. Monitor.Monitor.SetNotification("广告更新失败,请尝试手动更新", parkMonitor.model.TextColor.Warning);
  305. }
  306. else
  307. {
  308. Monitor.Monitor.SetNotification("广告更新成功\n" + adAlert, parkMonitor.model.TextColor.Log);
  309. }
  310. break;
  311. case "RESPONSE":
  312. if (msg.context == "REGSUCCESS")
  313. {
  314. Console.WriteLine("收到web注册指令");
  315. }
  316. else if (msg.context == "HEARTSUCCESS")
  317. {
  318. Console.WriteLine("收到web心跳指令");
  319. }
  320. break;
  321. default:
  322. Monitor.Monitor.SetNotification("接收到无法识别的指令", parkMonitor.model.TextColor.Warning);
  323. break;
  324. }
  325. }
  326. catch (Exception ex) { Console.WriteLine("收消息," + ex.Message + "\n" + ex.StackTrace); }
  327. }
  328. private void SendBookCmd(bool parking, int state)
  329. {
  330. int countdown = 5;
  331. while (countdown-- > 0)
  332. {
  333. if (Monitor.Monitor.mainBlockInfo.bookParkCmd != 0 && countdown>1)
  334. {
  335. Thread.Sleep(300);
  336. if (countdown == 2)
  337. {
  338. Monitor.Monitor.SetNotification("未能获取预约指令位0状态,尝试手动清除", parkMonitor.model.TextColor.Warning);
  339. MainBlockStru mbs = new MainBlockStru
  340. {
  341. centralHearbeat = -1,
  342. bookParkCmd = parking ? (short)0 : (short)-1,
  343. bookFetchCmd = !parking ? (short)0 : (short)-1,
  344. licenseReceived = -1
  345. };
  346. Monitor.Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
  347. Thread.Sleep(500);
  348. }
  349. continue;
  350. }
  351. MainBlockStru mb = new MainBlockStru
  352. {
  353. centralHearbeat = -1,
  354. bookParkCmd = parking ? (short)state : (short)-1,
  355. bookFetchCmd = !parking ? (short)state : (short)-1,
  356. licenseReceived = -1
  357. };
  358. Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
  359. Monitor.Monitor.SetNotification(mb.bookParkCmd + "," + mb.bookFetchCmd + "; 预约停车指令写入PLC", parkMonitor.model.TextColor.Log);
  360. Log.WriteLog(LogType.process, LogFile.INFO, mb.bookParkCmd + "," + mb.bookFetchCmd + "预约停车指令写入PLC");
  361. break;
  362. }
  363. }
  364. /// <summary>
  365. /// 根据时间段处理所有准备预约及已预约指令
  366. /// </summary>
  367. private void ReserveMsgHandling()
  368. {
  369. while (!isClosing)
  370. {
  371. //处理准备预约指令队列
  372. lock (waitToReserveLock)
  373. {
  374. for (int i = 0; i < waitToReserveQueue.Count; i++)
  375. {
  376. try
  377. {
  378. MessageUTF8 msg = waitToReserveQueue.Dequeue();
  379. DateTime startTime = DateTime.Parse(msg.bookTime);
  380. TimeSpan ts = DateTime.Now - startTime;
  381. //达到预约启动时间,放入已预约队列
  382. Console.WriteLine("当前时间差:" + ts.TotalMinutes + ",指令类型:" + msg.cmd);
  383. if (ts.TotalMinutes >= 0)
  384. {
  385. //如果是预约停车,通知PLC减少一个可预约车位数
  386. if (msg.cmd == "RESERVE")
  387. {
  388. SendBookCmd(true, 1);
  389. Monitor.Monitor.SetNotification("通知PLC减少可预约车位", parkMonitor.model.TextColor.Log);
  390. }
  391. reservedQueue.Enqueue(msg);
  392. }
  393. //还未达到启动时间
  394. else
  395. {
  396. waitToReserveQueue.Enqueue(msg);
  397. }
  398. }
  399. catch { }
  400. }
  401. }
  402. lock (reservedLock)
  403. {
  404. for (int i = 0; i < reservedQueue.Count; i++)
  405. {
  406. try
  407. {
  408. MessageUTF8 msg = reservedQueue.Dequeue();
  409. DateTime startTime = DateTime.Parse(msg.bookTime);
  410. TimeSpan ts = DateTime.Now - startTime;
  411. //预约超时
  412. if (ts.TotalMinutes > msg.bookLength * 60)
  413. {
  414. Monitor.Monitor.SetNotification(msg.context + " 预约已超时", parkMonitor.model.TextColor.Warning);
  415. Log.WriteLog(LogType.process, LogFile.INFO, msg.context + " 预约已超时");
  416. //通知PLC将可预约车位数恢复一个
  417. SendBookCmd(true, 2);
  418. //恢复车辆状态
  419. UpdateVehicleState(true, 0, 0, msg.context);
  420. UpdateVehicleState(false, 0, 0, msg.context);
  421. }
  422. else
  423. {
  424. reservedQueue.Enqueue(msg);
  425. }
  426. }
  427. catch { }
  428. }
  429. }
  430. Thread.Sleep(5000);
  431. }
  432. }
  433. /// <summary>
  434. /// 启动消息接收,启动超时指令处理
  435. /// </summary>
  436. /// <param name="port"></param>
  437. /// <returns></returns>
  438. public bool Start(int port)
  439. {
  440. isClosing = false;
  441. connecting = false;
  442. waitToReserveQueue = new Queue<MessageUTF8>();
  443. reservedQueue = new Queue<MessageUTF8>();
  444. //MessageUTF8 message = new MessageUTF8();
  445. //message.context = "sending message test";
  446. //message.cmd = "S";
  447. //message.parkingRecordsID = 1;
  448. //持续进行连接尝试
  449. Task.Factory.StartNew(() =>
  450. {
  451. //初始化后与web持续连接
  452. while (!isClosing)
  453. {
  454. try
  455. {
  456. Connections.close();
  457. Connections.Connection();
  458. connected = true;
  459. comm = new Communication();
  460. break;
  461. }
  462. catch (Exception)
  463. {
  464. connected = false;
  465. Console.WriteLine("服务没有开启,请检查服务器");
  466. }
  467. Thread.Sleep(2000);
  468. }
  469. Connect();
  470. });
  471. //持续接收消息
  472. receiveMsg = new Thread(() =>
  473. {
  474. while (!isClosing)
  475. {
  476. try
  477. {
  478. if (connected && comm != null)
  479. {
  480. byte[] bytes = new byte[256];
  481. MessageUTF8 msg = ((MessageUTF8)comm.ReceiveMessage(out bytes));
  482. //string str = "";
  483. //str = Encoding.Default.GetString(bytes);
  484. //Console.WriteLine(str);
  485. if (msg != null)
  486. {
  487. MsgHandling(msg);
  488. }
  489. //Monitor.Monitor.SetNotification(msg.context);
  490. }
  491. }
  492. catch { Console.WriteLine("线程已中断"); }
  493. }
  494. });
  495. receiveMsg.Start();
  496. //根据所处时间段处理预约指令
  497. Task.Factory.StartNew(() =>
  498. {
  499. ReserveMsgHandling();
  500. });
  501. return true;
  502. }
  503. /// <summary>
  504. /// 停止消息接收模块
  505. /// </summary>
  506. public void Stop()
  507. {
  508. isClosing = true;
  509. Connections.close();
  510. //throw new NotImplementedException();
  511. }
  512. /// <summary>
  513. /// 预约车辆入场检测
  514. /// </summary>
  515. /// <param name="license"></param>
  516. /// <returns></returns>
  517. public bool ReservedCarCheck(string license)
  518. {
  519. //对提前入场车辆,将预约指令丢出
  520. lock (waitToReserveLock)
  521. {
  522. for (int i = 0; i < waitToReserveQueue.Count; i++)
  523. {
  524. MessageUTF8 msg = waitToReserveQueue.Dequeue();
  525. if (msg.context != license)
  526. {
  527. waitToReserveQueue.Enqueue(msg);
  528. }
  529. }
  530. }
  531. //已进入预约状态车辆入场,审核确认后指令丢出
  532. lock (reservedLock)
  533. {
  534. for (int i = 0; i < reservedQueue.Count; i++)
  535. {
  536. MessageUTF8 msg = reservedQueue.Dequeue();
  537. if (msg.context == license)
  538. {
  539. return true;
  540. }
  541. else
  542. {
  543. reservedQueue.Enqueue(msg);
  544. }
  545. }
  546. }
  547. return false;
  548. }
  549. /// <summary>
  550. /// 主动连接web服务器
  551. /// </summary>
  552. public void Connect()
  553. {
  554. //持续判断连接状态并重连
  555. if (!connecting)
  556. {
  557. connecting = true;
  558. int count = 12;
  559. while (!isClosing)
  560. {
  561. //if (receiveMsg != null)
  562. // Console.WriteLine(Connections.isAlive() + ", " + receiveMsg.ThreadState.ToString());
  563. if (Connections.isAlive())
  564. {
  565. if (!connected)
  566. {
  567. comm = new Communication();
  568. Monitor.Monitor.SetNotification("web已连接上", parkMonitor.model.TextColor.Info);
  569. }
  570. connected = true;
  571. if (receiveMsg != null && receiveMsg.ThreadState == ThreadState.Aborted)
  572. {
  573. try
  574. {
  575. receiveMsg.Start();
  576. }
  577. catch (Exception ex) { Console.WriteLine(ex.Message); }
  578. }
  579. }
  580. else
  581. {
  582. if (count == 12 && connected)
  583. Monitor.Monitor.SetNotification("web连接已断开", parkMonitor.model.TextColor.Warning);
  584. else if (count == 0)
  585. break;
  586. connected = false;
  587. count--;
  588. try
  589. {
  590. if (receiveMsg != null && receiveMsg.ThreadState == ThreadState.WaitSleepJoin)
  591. {
  592. receiveMsg.Interrupt();
  593. }
  594. }
  595. catch (Exception ex)
  596. {
  597. Monitor.Monitor.SetNotification("连接断开,终止消息接收线程", parkMonitor.model.TextColor.Log);
  598. }
  599. Console.WriteLine(" 连接关闭,需要重新连接注册");
  600. try
  601. {
  602. Connections.close();
  603. Connections.Connection();
  604. }
  605. catch (Exception)
  606. {
  607. Console.WriteLine("服务没有开启,请检查服务器");
  608. }
  609. }
  610. Thread.Sleep(1000);
  611. }
  612. Monitor.Monitor.SetNotification("重连web服务器超时,请检查网络并手动连接web服务器", parkMonitor.model.TextColor.Error);
  613. connecting = false;
  614. }
  615. else
  616. {
  617. Monitor.Monitor.SetNotification("正在尝试连接,请勿重复点击", parkMonitor.model.TextColor.Warning);
  618. }
  619. }
  620. /// <summary>
  621. /// 获取连接状态
  622. /// </summary>
  623. /// <returns></returns>
  624. public bool GetConnectStatus()
  625. {
  626. return connected;
  627. }
  628. }
  629. }