123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Threading;
- using HNWD.Pregrant.BusinessLogic;
- using HNWD.Pregrant.Model;
- using System;
- using HNWD.Pregrant.Common;
- using System.Threading.Tasks;
- using System.Collections.Concurrent;
- namespace HNWD.LatticeScreen.Server
- {
- public class CarouselController
- {
- //private List<LedLatticeScreen> ledLatticeScreenlist = new List<LedLatticeScreen>();
- private Dictionary<string, List<LedLatticeScreen>> ledLatticeScreenlist1 = new Dictionary<string, List<LedLatticeScreen>>();
- //private readonly List<LedLatticeScreen> resledLatticeScreenlist = new List<LedLatticeScreen>();
- private Dictionary<string, List<LedLatticeScreen>> resledLatticeScreenlist1 = new Dictionary<string, List<LedLatticeScreen>>();
- private List<string> partids = new List<string>();
- private bool bWhile = true;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="dataSource">数据库链接字符串</param>
- /// <param name="stayingtime">电话停留时间</param>
- public CarouselController(string dataSource, string stayingtime)
- {
- GlobalConfigureSetting.AddConnectionSetting(dataSource);
- GlobalConfigureSetting.AddCallingStayingTime(stayingtime);
- }
- public void AssignLedLatticeScreen(string partid)
- {
- WD_RunProfileBusinessLogic wd_RunInfo = WD_RunProfileBusinessLogic.GetInstance();
- WD_RunProfileExt wd_ext = wd_RunInfo.QueryAll();
- if (wd_ext.bSuccess && wd_ext.Rows > 0)
- {
- for (int i = 0; i < wd_ext.messageDataList.Count; i++)
- {
- if (wd_ext.messageDataList[i].LEDDeviceFlag == "1")
- {
- this.InitializeList(partid);
- wd_RunInfo.UpdateLedFlag("0");
- }
- else
- {
- // this.InitializeList(partid);
- }
- }
- }
- }
- private void InitializeList(string partid)
- {
- ///保存正在运行的led点阵屏的属性 , 如当前索引值,当前led点阵屏时间戳
- foreach (LedLatticeScreen led in ledLatticeScreenlist1[partid])
- {
- LedLatticeScreen resled3 = this.resledLatticeScreenlist1[partid].Find(f => f.DeviceID.ToString() == led.DeviceID.ToString());
- resled3.CurDisIndex = led.CurDisIndex;
- resled3.secnow1 = led.secnow1;
- resled3.CallingList = led.CallingList;
- }
- this.ledLatticeScreenlist1[partid].Clear();
- WD_DeviceInfoBusinessLogic wd_Device = new WD_DeviceInfoBusinessLogic("0");
- List<WD_DeviceInfo> ls = wd_Device.QueryAll().messageDataList.FindAll(f => f.DEVICE_TYPE == "6" && f.DEVICE_STATUS == "1" && f.PARTID == partid);//取类型为点阵屏以及状态为激活的点阵屏数据
- foreach (WD_DeviceInfo wd in ls)
- {
- LedLatticeScreen led1 = new LedLatticeScreen(wd);
- led1.AddProgram(wd.ID);
- this.ledLatticeScreenlist1[partid].Add(led1);
- if (!this.resledLatticeScreenlist1[partid].Exists(f => f.DeviceID == wd.ID))
- {
- LedLatticeScreen led2 = new LedLatticeScreen(wd);
- this.resledLatticeScreenlist1[partid].Add(led2);
- }
- }
- ///还原正在运行的led点阵屏的属性 , 如当前索引值,当前led点阵屏时间戳
- foreach (LedLatticeScreen led in ledLatticeScreenlist1[partid])
- {
- LedLatticeScreen resled3 = this.resledLatticeScreenlist1[partid].Find(f => f.DeviceID.ToString() == led.DeviceID.ToString());
- led.CurDisIndex = resled3.CurDisIndex;
- led.secnow1 = resled3.secnow1;
- led.CallingList = resled3.CallingList;
- }
- }
- public void AddCallingProgram(string CallId, string CallText, int PartID)
- {
- var partIdStr = PartID.ToString();
- if (!ledLatticeScreenlist1.ContainsKey(partIdStr))
- {
- return;
- }
- for (int i = 0; i < ledLatticeScreenlist1[partIdStr].Count; i++)
- {
- CallingProgram cp = new CallingProgram(ledLatticeScreenlist1[partIdStr][i], CallId);
- cp.SetEntity(new WD_ProgramInfo()
- {
- PROGRAM_TEXT = CallText,
- });
- if (!ledLatticeScreenlist1[partIdStr][i].CallingList.Exists(f => f.CallId == CallId))
- {
- ledLatticeScreenlist1[partIdStr][i].CallingList.Add(cp);
- }
- }
- }
- public void DeleteCallingProgram(string CallId, int PartID)
- {
- for (int i = 0; i < ledLatticeScreenlist1[PartID.ToString()].Count; i++)
- {
- ledLatticeScreenlist1[PartID.ToString()][i].CallingList.Remove(ledLatticeScreenlist1[PartID.ToString()][i].CallingList.Find(f => f.CallId == CallId));
- }
- }
- public void Start()
- {
- WD_DeviceInfoBusinessLogic busloc = new WD_DeviceInfoBusinessLogic("0");
- List<WD_DeviceInfo> lpartids = busloc.QueryPartIDs();
- foreach (WD_DeviceInfo partid in lpartids)
- {
- this.ledLatticeScreenlist1.Add(partid.PARTID, new List<LedLatticeScreen>());
- this.resledLatticeScreenlist1.Add(partid.PARTID, new List<LedLatticeScreen>());
- this.InitializeList(partid.PARTID);
- Thread t1 = new Thread(new ParameterizedThreadStart(doAsync));
- t1.Start((object)partid.PARTID);
- }
- }
- private void doAsync(object partid)
- {
- while (this.bWhile)
- {
- this.AssignLedLatticeScreen(partid.ToString());
- if (ledLatticeScreenlist1[partid.ToString()].Count > 0)
- {
- Parallel.For(0, ledLatticeScreenlist1[partid.ToString()].Count, item =>
- {
- if (ledLatticeScreenlist1[partid.ToString()][item].PingIpOrDomainName())
- {
- ledLatticeScreenlist1[partid.ToString()][item].Start();
- }
- });
- }
- Thread.Sleep(100);
- }
- }
- public void End()
- {
- this.bWhile = false;
- }
- public void Restart()
- {
- this.bWhile = true;
- Start();
- }
- public string GetVersion()
- {
- return "1.0.0.2";
- }
- }
- }
|