public override RunTaskResult RunTask() { RunTaskResult taskResult = new RunTaskResult() { Success = true, Result = "执行完毕" }; try { AutoMapperConfiguration.Configure(); Config19e config = new Config19e { AppCode19e = CustomConfig["appCode_19e"], IsCloseSync = Convert.ToBoolean(CustomConfig["IsCloseSync19e"]), PerPageSize = CustomConfig["PerPageSize19e"], SafeCode19e = CustomConfig["safeCode_19e"], TimeSpan19e = CustomConfig["timespan_19e"], Username19e = CustomConfig["username_19e"], QueueHost = CustomConfig["queueHost"], QueueName = CustomConfig["queueName"], IsSendPolicyQueue = Boolean.Parse(CustomConfig["isSendPolicyQueue"]) }; IHandlerForPolicy handler = new HandlerFor19eFactory().Create(config); handler.onWorklingMsg += handler_onWorklingMsg; handler.StartHanlerWork(); } catch (Exception ex) { ShowRunningLog("抛出异常:" + ex.Message.ToString()); taskResult = new RunTaskResult { Success = false, Result = ex.Message }; } return(taskResult); }
/// <summary> /// 运行任务 /// </summary> /// <returns></returns> public override RunTaskResult RunTask() { RunTaskResult res = new RunTaskResult(); HttpClient client = new HttpClient(); return(res); }
public override RunTaskResult RunTask() { RunTaskResult taskResult = new RunTaskResult() { Success = true, Result = "执行完毕" }; FlightAirRuleDAL ruleDal = new FlightAirRuleDAL(); try { ruleDal.deleteAllData();//清空所有数据 bool flag = true; int index = 0; while (flag) { getModifyAndRefundStipulatesRequest req = new getModifyAndRefundStipulatesRequest(); req.rowPerPage = 1500; req.rowPerPageSpecified = true; string lastTimeAndId = GetLastUpTimeAndId("AirKGLog"); req.lastSeatId = Convert.ToInt32(lastTimeAndId.Split('|')[1]); req.lastSeatIdSpecified = true; req.lastModifiedAt = lastTimeAndId.Split('|')[0]; getModifyAndRefundStipulatesReply rep = _51bookHelper.getModifyAndRefundStipulates(req) as getModifyAndRefundStipulatesReply; if (rep.returnCode.ToLower() != "s") { ShowRunningLog(rep.returnMessage + "," + rep.returnStackTrace); flag = false; continue; } ShowRunningLog("收到退改签规定包数量:" + rep.modifyAndRefundStipulateList.Length + ",剩余页数:" + rep.leftPages); if (index > 0) { if (rep.leftPages == 0) { ShowRunningLog("剩余页数为0,已经全部取完!"); flag = false; } else { addDb(rep); } } else { addDb(rep); } index++; } SaveLastUpTimeAndId("2000-01-01 00:00:00|0", "AirKGLog"); ruleDal.deleteAllDataForever();//清空所有数据 } catch (Exception ex) { ShowRunningLog("添加航空公司客规失败:" + ex.Message); ruleDal.recoveryAllData(); } return(taskResult); }
public override RunTaskResult RunTask() { DbHelperSQL sql = new DbHelperSQL(this.AppConfig["ConnStr"].ToString()); _51bookHelper helper = new _51bookHelper(this.AppConfig["agencyCode"].ToString(), this.AppConfig["safetyCode"].ToString()); ShowProcessIngLog("读取该任务的配置参数:" + JsonConvert.SerializeObject(this.AppConfig)); RunTaskResult taskResult = new RunTaskResult() { RunStatus = (int)RunStatus.Normal, Message = "执行完毕" }; FlightAirRuleDAL ruleDal = new FlightAirRuleDAL(); try { ShowProcessIngLog("开始清除现有数据"); ruleDal.deleteAllData();//清空所有数据 ShowProcessIngLog("清除现有数据完成"); bool flag = true; int index = 0; while (flag) { getModifyAndRefundStipulatesRequest req = new getModifyAndRefundStipulatesRequest(); req.rowPerPage = 1500; req.rowPerPageSpecified = true; string lastTimeAndId = GetLastUpTimeAndId("AirKGLog"); req.lastSeatId = Convert.ToInt32(lastTimeAndId.Split('|')[1]); req.lastSeatIdSpecified = true; req.lastModifiedAt = lastTimeAndId.Split('|')[0]; ShowProcessIngLog("读取本次要抓取的配置:" + lastTimeAndId); getModifyAndRefundStipulatesReply rep = _51bookHelper.getModifyAndRefundStipulates(req) as getModifyAndRefundStipulatesReply; if (rep.returnCode.ToLower() != "s") { ShowProcessIngLog(rep.returnMessage + "," + rep.returnStackTrace); flag = false; continue; } ShowProcessIngLog("收到退改签规定包数量:" + rep.modifyAndRefundStipulateList.Length + ",剩余页数:" + rep.leftPages); if (index > 0) { if (rep.leftPages == 0) { ShowProcessIngLog("剩余页数为0,已经全部取完!"); flag = false; } else { addDb(rep); } } else { addDb(rep); } index++; } SaveLastUpTimeAndId("2000-01-01 00:00:00|0", "AirKGLog"); ruleDal.deleteAllDataForever();//清空所有数据 } catch (Exception ex) { ShowProcessIngLog("添加航空公司客规失败:" + ex.Message + ",异常:" + JsonConvert.SerializeObject(ex)); ruleDal.recoveryAllData(); taskResult = new RunTaskResult() { RunStatus = (int)RunStatus.Exception, Ex = ex, Message = ex.Message }; } return(taskResult); }
//public List<Policies> ListenQueuePolicy(string queueHost, string queueName) //{ // MessageQueue x = new MessageQueue( ".\\" + queueHost + "\\" + queueName); // System.Messaging.Message myMessage = null; // try // { // myMessage = x.Receive(MessageQueueTransactionType.Single); // myMessage.Formatter = new BinaryMessageFormatter(); // List<Policies> lstPolicies = myMessage.Body as List<Policies>; // return lstPolicies; // } // catch (Exception ex) // { // return new List<Policies>(); // } //} public override RunTaskResult RunTask() { RunTaskResult taskResult = new RunTaskResult() { Success = true, Result = "执行完毕" }; List <Policies> lstPolicies = new List <Policies>(); string queueName = CustomConfig["policyUpdateQueueName"]; string warningQueueName = CustomConfig["warningPolicyUpdateQueueName"]; //预警队列名称 string warningQueueHost = CustomConfig["warningPolicyUpdateQueueHost"]; //预警队列主机 string queueHost = CustomConfig["policyUpdateQueueHost"]; while (true) { try { #region 监听队列 try { ShowRunningLog(DateTime.Now + ":队列监听中..."); MessageQueue x = new MessageQueue(".\\" + queueHost + "\\" + queueName); System.Messaging.Message myMessage = x.Receive(MessageQueueTransactionType.Single); myMessage.Formatter = new BinaryMessageFormatter(); lstPolicies = myMessage.Body as List <Policies>; if (lstPolicies == null || lstPolicies.Count <= 0) { ShowRunningLog(DateTime.Now + ":未从队列中收到任何政策更新包!"); continue; // return taskResult; } } catch (Exception ex) { ShowRunningLog(DateTime.Now + ":监听队列异常:" + JsonConvert.SerializeObject(ex)); taskResult = new RunTaskResult() { Success = false, Result = ex.Message }; // return taskResult; } #endregion #region 过滤掉失败次数大于2次的 ShowRunningLog(DateTime.Now + ":从队列中收到政策:" + lstPolicies.Count + "条!"); List <Policies> lstFailedPolicies = lstPolicies.Where(x => x.Id >= 2).ToList();//找出失败大于等于俩次的条数 if (lstFailedPolicies.Count > 0) { ShowRunningLog(DateTime.Now + ":收到更新政策失败次数超过2次的政策条数:" + lstFailedPolicies.Count + "条,开始发送到预警队列"); bool r = new MessageQueueHelper().SendMsgToQueue(warningQueueName, lstPolicies, MessagePriority.Normal, warningQueueHost); if (r) { ShowRunningLog(DateTime.Now + ":发送到预警队列成功"); continue; } new MessageQueueHelper().SendMsgToQueue(queueName, lstPolicies, MessagePriority.Normal, queueHost); ShowRunningLog(DateTime.Now + ":发送到预警队列失败!重新发送回队列成功!"); } lstPolicies = lstPolicies.Where(x => x.Id < 2).ToList(); if (lstPolicies.Count <= 0) { ShowRunningLog(DateTime.Now + ":失败次数小于2次的政策数为0,不用更新"); continue; //return taskResult; } UploadPolicy(lstPolicies, queueName, queueHost); #endregion } catch (Exception ex) { lstPolicies.ForEach(x => { x.Id += 1; }); ShowRunningLog(DateTime.Now + ":抛出异常:" + JsonConvert.SerializeObject(ex)); new MessageQueueHelper().SendMsgToQueue(queueName, lstPolicies, MessagePriority.Normal, queueHost); //taskResult = new RunTaskResult { Success = false, Result = ex.Message }; } // Thread.Sleep(10 * 1000); } return(taskResult); }
public override RunTaskResult RunTask() { RunTaskResult taskResult = new RunTaskResult() { Success = true, Result = "执行完毕" }; List <Policies> lstPolicies = new List <Policies>(); string queueName = CustomConfig["policyListenQueueName"]; string queueHost = CustomConfig["policyListenQueueHost"]; string updateQueueName = CustomConfig["policyUpdateQueueName"]; string updateQueueHost = CustomConfig["policyUpdateQueueHost"]; while (true) { #region 监听队列 try { MessageQueue x = new MessageQueue(".\\" + queueHost + "\\" + queueName); System.Messaging.Message myMessage = x.Receive(MessageQueueTransactionType.Single); myMessage.Formatter = new BinaryMessageFormatter(); lstPolicies = myMessage.Body as List <Policies>; if (lstPolicies == null || lstPolicies.Count <= 0) { ShowRunningLog("未从队列中收到任何政策更新包!"); continue; } ShowRunningLog("收到监听队列中政策更新包:" + lstPolicies.Count + "条!"); } catch (Exception ex) { ShowRunningLog("监听队列异常:" + JsonConvert.SerializeObject(ex)); taskResult = new RunTaskResult() { Success = false, Result = ex.Message }; // return taskResult; continue; } #endregion try { string responseContent = CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SearchCompleteUploadPolicyUrl"].ToString(), null); if (string.IsNullOrEmpty(responseContent)) { ShowRunningLog("暂未上传过任何政策,不用更新!"); // return taskResult; continue; } CompleteUploadPolicyResponse rep = JsonConvert.DeserializeObject <CompleteUploadPolicyResponse>(responseContent); if (rep.ErrCode == ResultType.Failed || rep.CompleteUploadPolicyCollection == null || rep.CompleteUploadPolicyCollection.Count <= 0) { ShowRunningLog("暂未上传过任何政策,不用更新!"); //return taskResult; continue; } Dictionary <QunarPolicyType, List <Policies> > dic = CoreHelper.ReserveHaveUploadPolicy(lstPolicies, rep.CompleteUploadPolicyCollection); if (dic.Count <= 0) { ShowRunningLog("此次更新包不在上传政策列表中,不用更新!"); // return taskResult; continue; } //在的话发送到更新队列中 List <Policies> lstUpdatePolicies = new List <Policies>(); foreach (KeyValuePair <QunarPolicyType, List <Policies> > item in dic) { ShowRunningLog("收到去哪儿" + item.Key.ToString() + "政策更新包:" + item.Value.Count + "条"); item.Value.ForEach(x => { lstUpdatePolicies.Add(x); }); } new MessageQueueHelper().SendMsgToQueue(updateQueueName, lstUpdatePolicies, MessagePriority.Normal, updateQueueHost); ShowRunningLog("发送更新队列成功!"); continue; } catch (Exception ex) { ShowRunningLog(JsonConvert.SerializeObject(ex)); //return new RunTaskResult() { Success = false, Result = ex.Message }; continue; } } }