CarouselController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System.Collections.Generic;
  2. using System.Windows.Forms;
  3. using System.Threading;
  4. using HNWD.Pregrant.BusinessLogic;
  5. using HNWD.Pregrant.Model;
  6. using System;
  7. using HNWD.Pregrant.Common;
  8. using System.Threading.Tasks;
  9. using System.Collections.Concurrent;
  10. namespace HNWD.LatticeScreen.Server
  11. {
  12. public class CarouselController
  13. {
  14. //private List<LedLatticeScreen> ledLatticeScreenlist = new List<LedLatticeScreen>();
  15. private Dictionary<string, List<LedLatticeScreen>> ledLatticeScreenlist1 = new Dictionary<string, List<LedLatticeScreen>>();
  16. //private readonly List<LedLatticeScreen> resledLatticeScreenlist = new List<LedLatticeScreen>();
  17. private Dictionary<string, List<LedLatticeScreen>> resledLatticeScreenlist1 = new Dictionary<string, List<LedLatticeScreen>>();
  18. private List<string> partids = new List<string>();
  19. private bool bWhile = true;
  20. /// <summary>
  21. /// 构造函数
  22. /// </summary>
  23. /// <param name="dataSource">数据库链接字符串</param>
  24. /// <param name="stayingtime">电话停留时间</param>
  25. public CarouselController(string dataSource, string stayingtime)
  26. {
  27. GlobalConfigureSetting.AddConnectionSetting(dataSource);
  28. GlobalConfigureSetting.AddCallingStayingTime(stayingtime);
  29. }
  30. public void AssignLedLatticeScreen(string partid)
  31. {
  32. WD_RunProfileBusinessLogic wd_RunInfo = WD_RunProfileBusinessLogic.GetInstance();
  33. WD_RunProfileExt wd_ext = wd_RunInfo.QueryAll();
  34. if (wd_ext.bSuccess && wd_ext.Rows > 0)
  35. {
  36. for (int i = 0; i < wd_ext.messageDataList.Count; i++)
  37. {
  38. if (wd_ext.messageDataList[i].LEDDeviceFlag == "1")
  39. {
  40. this.InitializeList(partid);
  41. wd_RunInfo.UpdateLedFlag("0");
  42. }
  43. else
  44. {
  45. // this.InitializeList(partid);
  46. }
  47. }
  48. }
  49. }
  50. private void InitializeList(string partid)
  51. {
  52. ///保存正在运行的led点阵屏的属性 , 如当前索引值,当前led点阵屏时间戳
  53. foreach (LedLatticeScreen led in ledLatticeScreenlist1[partid])
  54. {
  55. LedLatticeScreen resled3 = this.resledLatticeScreenlist1[partid].Find(f => f.DeviceID.ToString() == led.DeviceID.ToString());
  56. resled3.CurDisIndex = led.CurDisIndex;
  57. resled3.secnow1 = led.secnow1;
  58. resled3.CallingList = led.CallingList;
  59. }
  60. this.ledLatticeScreenlist1[partid].Clear();
  61. WD_DeviceInfoBusinessLogic wd_Device = new WD_DeviceInfoBusinessLogic("0");
  62. List<WD_DeviceInfo> ls = wd_Device.QueryAll().messageDataList.FindAll(f => f.DEVICE_TYPE == "6" && f.DEVICE_STATUS == "1" && f.PARTID == partid);//取类型为点阵屏以及状态为激活的点阵屏数据
  63. foreach (WD_DeviceInfo wd in ls)
  64. {
  65. LedLatticeScreen led1 = new LedLatticeScreen(wd);
  66. led1.AddProgram(wd.ID);
  67. this.ledLatticeScreenlist1[partid].Add(led1);
  68. if (!this.resledLatticeScreenlist1[partid].Exists(f => f.DeviceID == wd.ID))
  69. {
  70. LedLatticeScreen led2 = new LedLatticeScreen(wd);
  71. this.resledLatticeScreenlist1[partid].Add(led2);
  72. }
  73. }
  74. ///还原正在运行的led点阵屏的属性 , 如当前索引值,当前led点阵屏时间戳
  75. foreach (LedLatticeScreen led in ledLatticeScreenlist1[partid])
  76. {
  77. LedLatticeScreen resled3 = this.resledLatticeScreenlist1[partid].Find(f => f.DeviceID.ToString() == led.DeviceID.ToString());
  78. led.CurDisIndex = resled3.CurDisIndex;
  79. led.secnow1 = resled3.secnow1;
  80. led.CallingList = resled3.CallingList;
  81. }
  82. }
  83. public void AddCallingProgram(string CallId, string CallText, int PartID)
  84. {
  85. var partIdStr = PartID.ToString();
  86. if (!ledLatticeScreenlist1.ContainsKey(partIdStr))
  87. {
  88. return;
  89. }
  90. for (int i = 0; i < ledLatticeScreenlist1[partIdStr].Count; i++)
  91. {
  92. CallingProgram cp = new CallingProgram(ledLatticeScreenlist1[partIdStr][i], CallId);
  93. cp.SetEntity(new WD_ProgramInfo()
  94. {
  95. PROGRAM_TEXT = CallText,
  96. });
  97. if (!ledLatticeScreenlist1[partIdStr][i].CallingList.Exists(f => f.CallId == CallId))
  98. {
  99. ledLatticeScreenlist1[partIdStr][i].CallingList.Add(cp);
  100. }
  101. }
  102. }
  103. public void DeleteCallingProgram(string CallId, int PartID)
  104. {
  105. for (int i = 0; i < ledLatticeScreenlist1[PartID.ToString()].Count; i++)
  106. {
  107. ledLatticeScreenlist1[PartID.ToString()][i].CallingList.Remove(ledLatticeScreenlist1[PartID.ToString()][i].CallingList.Find(f => f.CallId == CallId));
  108. }
  109. }
  110. public void Start()
  111. {
  112. WD_DeviceInfoBusinessLogic busloc = new WD_DeviceInfoBusinessLogic("0");
  113. List<WD_DeviceInfo> lpartids = busloc.QueryPartIDs();
  114. foreach (WD_DeviceInfo partid in lpartids)
  115. {
  116. this.ledLatticeScreenlist1.Add(partid.PARTID, new List<LedLatticeScreen>());
  117. this.resledLatticeScreenlist1.Add(partid.PARTID, new List<LedLatticeScreen>());
  118. this.InitializeList(partid.PARTID);
  119. Thread t1 = new Thread(new ParameterizedThreadStart(doAsync));
  120. t1.Start((object)partid.PARTID);
  121. }
  122. }
  123. private void doAsync(object partid)
  124. {
  125. while (this.bWhile)
  126. {
  127. this.AssignLedLatticeScreen(partid.ToString());
  128. if (ledLatticeScreenlist1[partid.ToString()].Count > 0)
  129. {
  130. Parallel.For(0, ledLatticeScreenlist1[partid.ToString()].Count, item =>
  131. {
  132. if (ledLatticeScreenlist1[partid.ToString()][item].PingIpOrDomainName())
  133. {
  134. ledLatticeScreenlist1[partid.ToString()][item].Start();
  135. }
  136. });
  137. }
  138. Thread.Sleep(100);
  139. }
  140. }
  141. public void End()
  142. {
  143. this.bWhile = false;
  144. }
  145. public void Restart()
  146. {
  147. this.bWhile = true;
  148. Start();
  149. }
  150. public string GetVersion()
  151. {
  152. return "1.0.0.2";
  153. }
  154. }
  155. }