//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服务"); } }
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服务"); // } //} private void ExecuteWaitingCommand_Thread() { try { //开始前先等待10分钟,用于等待硬件设备连接状态检测完成 Thread.Sleep(10 * 60 * 1000); 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.GetWaitingCommands().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 && entrance.Status != EntranceStatus.OffLine) { 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.DownloadKeySetting) { ret = entrance.ApplyKeySetting(KeySetting.Current); } else if (wc.Command == CommandType.ClearCard) { ret = entrance.ClearCard(); } else if (wc.Command == CommandType.DeleteCard) { //由于命令执行前已删除了卡片信息,所以如果是车牌名单时,cardid保存的是车牌名单的车牌号 CardInfo card = new CardInfo(); card.ListType = wc.CardIDType.HasValue && wc.CardIDType.Value == 1 ? CardListType.CarPlate : CardListType.Card; if (card.IsCardList) { card.CardID = wc.CardID; } else { card.CarPlate = 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); } 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); } } } else { CommandResult dresult = new CommandResult(ResultCode.CannotConnectServer); if (DataBaseConnectionsManager.Current.MasterConnected) { wc.Status = WaitingCommandStatus.Fail; dresult = wb.Update(wc); } } } } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } Thread.Sleep(5 * 60 * 1000); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "WaitingCommand服务异常终止"); } }