private void ClearInvalidWaitingCommand() { if (ParkBuffer.Current != null) { WaitingCommandBLL wb = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect); List <WaitingCommandInfo> wcs = wb.GetAllCommands().QueryObjects; List <EntranceInfo> entrances = ParkBuffer.Current.GetEntrances(); int entranceID = 0; //当前控制器id bool invalidEntrance = false; //当前控制器是否无效控制器 foreach (var wc in wcs) { if (wc.EntranceID != entranceID) { EntranceInfo entrance = entrances.FirstOrDefault(e => e.EntranceID == wc.EntranceID); entranceID = wc.EntranceID; invalidEntrance = entrance == null; } if (invalidEntrance) { wb.Delete(wc); } } } }
private void ExecuteWaitingCommand_Thread() { ClearInvalidWaitingCommand();//清除已删除的控制器的等待命令 WaitingCommandBLL wb = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect); while (true) { List <WaitingCommandInfo> wcs = wb.GetAllCommands().QueryObjects; EntranceBase entrance = null; int entranceID = -1; foreach (var wc in wcs) { if (entranceID != wc.EntranceID) { entrance = GetEntrance(wc.EntranceID); entranceID = wc.EntranceID; } if (entrance != null) { bool ret = false; if (wc.Command == CommandType.DownloadAccesses) { ret = entrance.ApplyAccessSetting(AccessSetting.Current); } else if (wc.Command == CommandType.DownloadHolidays) { ret = entrance.ApplyHolidaySetting(HolidaySetting.Current); } else if (wc.Command == CommandType.DownloadTariffs) { ret = entrance.ApplyTariffSetting(TariffSetting.Current); } else if (wc.Command == CommandType.ClearCard) { ret = entrance.ClearCard(); } else if (wc.Command == CommandType.DeleteCard) { CardInfo card = new CardInfo(); card.CardID = wc.CardID; ret = entrance.DeleteCard(card); } else if (wc.Command == CommandType.AddCard || wc.Command == CommandType.UpateCard) { CardBll cb = new CardBll(AppSettings.CurrentSetting.ParkConnect); CardInfo card = cb.GetCardByID(wc.CardID).QueryObject; if (card != null) { ret = entrance.SaveCard(card, wc.Command == CommandType.AddCard ? ActionType.Add : ActionType.Upate); } else { ret = true; } } if (ret) { wb.Delete(wc); } } } Thread.Sleep(60 * 1000); } }
//private void SyncTime_Thread() //{ // while (true) // { // Thread.Sleep(5 * 60 * 1000); // try // { // foreach (EntranceBase entrance in _Entrances) // { // entrance.SyncTime(); // } // } // catch (Exception ex) // { // Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); // } // } //} private void ExecuteWaitingCommand_Thread() { try { ClearInvalidWaitingCommand();//清除已删除的控制器的等待命令 Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务"); while (true) { try { if (!_WaitingCommandPause && DataBaseConnectionsManager.Current.MasterConnected) { WaitingCommandBLL wb = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect); List <WaitingCommandInfo> wcs = wb.GetAllCommands().QueryObjects; EntranceBase entrance = null; int entranceID = -1; foreach (var wc in wcs) { if (entranceID != wc.EntranceID) { entrance = GetEntrance(wc.EntranceID); entranceID = wc.EntranceID; } if (entrance != null) { bool ret = false; if (wc.Command == CommandType.DownloadAccesses) { ret = entrance.ApplyAccessSetting(AccessSetting.Current); } else if (wc.Command == CommandType.DownloadHolidays) { ret = entrance.ApplyHolidaySetting(HolidaySetting.Current); } else if (wc.Command == CommandType.DownloadTariffs) { ret = entrance.ApplyTariffSetting(TariffSetting.Current); } else if (wc.Command == CommandType.ClearCard) { ret = entrance.ClearCard(); } else if (wc.Command == CommandType.DeleteCard) { CardInfo card = new CardInfo(); card.CardID = wc.CardID; ret = entrance.SaveCard(card, ActionType.Delete); } else if (wc.Command == CommandType.AddCard || wc.Command == CommandType.UpateCard) { CardBll cb = new CardBll(AppSettings.CurrentSetting.CurrentMasterConnect); CardInfo card = cb.GetCardByID(wc.CardID).QueryObject; if (card != null) { ret = entrance.SaveCard(card, wc.Command == CommandType.AddCard ? ActionType.Add : ActionType.Upate, false); } else { ret = true; } } if (ret) { CommandResult dresult = new CommandResult(ResultCode.CannotConnectServer); if (DataBaseConnectionsManager.Current.MasterConnected) { dresult = wb.Delete(wc); } if (AppSettings.CurrentSetting.Debug) { if (dresult.Result == ResultCode.Successful) { string msg = string.Format("控制器{0}[{1}] 命令 {2} {3} 成功,删除命令 {4}", entrance.EntranceName, entrance.EntranceID, wc.Command, wc.CardID, dresult.Result == ResultCode.Successful ? "成功" : dresult.Result.ToString()); Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", msg); } } } } } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务"); } Thread.Sleep(60 * 1000); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务"); } }