private void LogWarnInfo(IHttpRequest httpRequest, string errorInfo, int channelID, int clientID) { logger.Warn(errorInfo + "请求信息:\n" + httpRequest.RequestData); if (saveLogFailedRequestToDb) { SPFailedRequestWrapper.SaveFailedRequest(httpRequest, errorInfo, channelID, clientID); } }
public void FromWrapper(SPFailedRequestWrapper wrapper) { this.Id = wrapper.Id; this.RecievedContent = wrapper.RecievedContent; this.RecievedDate = wrapper.RecievedDate; this.RecievedIP = wrapper.RecievedIP; this.RecievedSendUrl = wrapper.RecievedSendUrl; this.ChannelID = wrapper.ChannelID; this.ClientID = wrapper.ClientID; this.FailedMessage = wrapper.FailedMessage; this.IsProcessed = wrapper.IsProcessed; }
public void DeleteRecord(int id) { try { SPFailedRequestWrapper.DeleteByID(id); ScriptManager.AjaxSuccess = true; } catch (Exception ex) { ScriptManager.AjaxSuccess = false; ScriptManager.AjaxErrorMessage = string.Format(ex.Message); return; } }
public SPFailedRequestWrapper ToWrapper() { SPFailedRequestWrapper wrapper = new SPFailedRequestWrapper(); wrapper.Id = this.Id; wrapper.RecievedContent = this.RecievedContent; wrapper.RecievedDate = this.RecievedDate; wrapper.RecievedIP = this.RecievedIP; wrapper.RecievedSendUrl = this.RecievedSendUrl; wrapper.ChannelID = this.ChannelID; wrapper.ClientID = this.ClientID; wrapper.FailedMessage = this.FailedMessage; wrapper.IsProcessed = this.IsProcessed; return(wrapper); }
protected void storeSPFailedRequest_Refresh(object sender, StoreRefreshDataEventArgs e) { int recordCount = 0; string sortFieldName = ""; if (e.Sort != null) { sortFieldName = e.Sort; } int startIndex = 0; if (e.Start > -1) { startIndex = e.Start; } int limit = this.PagingToolBar1.PageSize; int pageIndex = 1; if ((startIndex % limit) == 0) { pageIndex = startIndex / limit + 1; } else { pageIndex = startIndex / limit; } List <QueryFilter> queryFilters = GetQueryFilters(); storeSPFailedRequest.DataSource = SPFailedRequestWrapper.FindAllByOrderByAndFilter(queryFilters, sortFieldName, (e.Dir == SortDirection.DESC), pageIndex, limit, out recordCount); e.TotalCount = recordCount; storeSPFailedRequest.DataBind(); }
protected void btnProcessAll_Click(object sender, AjaxEventArgs e) { string json = e.ExtraParams["Values"]; if (string.IsNullOrEmpty(json)) { return; } Dictionary <string, string>[] datas = JSON.Deserialize <Dictionary <string, string>[]>(json); foreach (Dictionary <string, string> row in datas) { int id = Convert.ToInt32(row["Id"].ToString()); SPFailedRequestWrapper spFailedRequestWrapper = SPFailedRequestWrapper.FindById(id); spFailedRequestWrapper.IsProcessed = true; SPFailedRequestWrapper.Update(spFailedRequestWrapper); } }
public void ProcessRequest(HttpContext context) { try { IHttpRequest httpRequest = new HttpGetPostRequest(context.Request); //context.Request.s //检测是否存在ashx if (string.IsNullOrEmpty(httpRequest.RequestFileName)) { LogWarnInfo(httpRequest, "请求失败:没有指定ashx路径。\n", 0, 0); return; } SPChannelWrapper channel = SPChannelWrapper.GetChannelByPath(Path.GetFileNameWithoutExtension(httpRequest.RequestFileName)); //如果没有找到通道 if (channel == null) { LogWarnInfo(httpRequest, "处理请求失败:无法找到对应的通道。\n", 0, 0); return; } saveLogFailedRequestToDb = channel.LogFailedRequestToDb; //如果通道未能运行 if (channel.CStatus != ChannelStatus.Run) { LogWarnInfo(httpRequest, "请求失败:\n" + "通道“" + channel.Name + "”未运行。\n", channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } //如果通道是监视通道,记录请求。 if (channel.IsMonitoringRequest.HasValue && channel.IsMonitoringRequest.Value) { SPMonitoringRequestWrapper.SaveRequest(httpRequest, channel.Id); } if (channel.Id == 88) { if (httpRequest.RequestParams.ContainsKey("command")) { if (httpRequest.RequestParams["command"].ToString().ToLower().Equals("z6")) { httpRequest.RequestParams["command"] = " 6"; } } if (httpRequest.RequestParams.ContainsKey("command")) { if (httpRequest.RequestParams["command"].ToString().ToLower().Equals("71") && httpRequest.RequestParams["sp_no"].ToString().ToLower().Equals("1066885031")) { httpRequest.RequestParams["command"] = "7"; } } } if (channel.Id == 66) { if (httpRequest.RequestParams.ContainsKey("spnumber") && httpRequest.RequestParams.ContainsKey("momsg")) { if (httpRequest.RequestParams["momsg"].ToString().ToLower().StartsWith("8dm") && httpRequest.RequestParams["spnumber"].ToString().ToLower().Equals("106268001")) { httpRequest.RequestParams["spnumber"] = "106268000"; } } } if (channel.FuzzyCommand.Trim().ToLower().Equals("quantt")) { if (httpRequest.RequestParams.ContainsKey("reportcode")) { if (!string.IsNullOrEmpty(httpRequest.RequestParams["reportcode"].ToString())) { httpRequest.RequestParams.Add("status", httpRequest.RequestParams["reportcode"].ToString().Substring(0, 1)); httpRequest.RequestParams.Add("msg", httpRequest.RequestParams["reportcode"].ToString().Substring(1, httpRequest.RequestParams["reportcode"].ToString().Length - 1)); } } } if (channel.HasConvertRule.HasValue && channel.HasConvertRule.Value) { try { PreProcessRequest(httpRequest.RequestParams, context, channel.FuzzyCommand); } catch (Exception ex) { LogWarnInfo(httpRequest, "数据转换错误:" + ex.Message, channel.Id, 0); } } //如果状态报告通道 if (channel.RecStatReport.HasValue && channel.RecStatReport.Value) { RequestError requestError1 = new RequestError(); bool result1 = false; //分类型请求 if (channel.HasRequestTypeParams.HasValue && channel.HasRequestTypeParams.Value) { //报告状态请求 if (httpRequest.IsRequestContainValues(channel.RequestTypeParamName, channel.RequestReportTypeValue)) { if (httpRequest.IsRequestContainValues(channel.StatParamsName, channel.StatParamsValues)) { result1 = channel.RecState(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString(), out requestError1); } else { //channel.SaveStatReport(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString()); context.Response.Write(channel.GetOkCode(httpRequest)); return; } } //发送数据请求 else if (httpRequest.IsRequestContainValues(channel.RequestTypeParamName, channel.RequestDataTypeValue)) { result1 = channel.ProcessStateRequest(httpRequest, out requestError1); } else { LogWarnInfo(httpRequest, "未知类型请求", channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } } else { if (httpRequest.RequestParams.ContainsKey(channel.StatParamsName.ToLower())) { if (httpRequest.IsRequestContainValues(channel.StatParamsName, channel.StatParamsValues)) { if (channel.StatSendOnce.HasValue && channel.StatSendOnce.Value) { result1 = channel.ProcessRequest(httpRequest, out requestError1); } else { result1 = channel.RecState(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString(), out requestError1); } } else { //channel.SaveStatReport(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString()); context.Response.Write(channel.GetOkCode(httpRequest)); return; } } else { result1 = channel.ProcessStateRequest(httpRequest, out requestError1); } } //正确数据返回OK if (result1) { context.Response.Write(channel.GetOkCode(httpRequest)); return; } //重复数据返回OK if (requestError1.ErrorType == RequestErrorType.RepeatLinkID) { logger.Warn(requestError1.ErrorMessage); context.Response.Write(channel.GetOkCode(httpRequest)); return; } //其他错误类型记录错误请求 LogWarnInfo(httpRequest, requestError1.ErrorMessage, channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } RequestError requestError; bool result = channel.ProcessRequest(httpRequest, out requestError); if (result) { context.Response.Write(channel.GetOkCode(httpRequest)); return; } //重复数据返回OK if (requestError.ErrorType == RequestErrorType.RepeatLinkID) { logger.Warn(requestError.ErrorMessage); context.Response.Write(channel.GetOkCode(httpRequest)); return; } LogWarnInfo(httpRequest, requestError.ErrorMessage, channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); } catch (Exception ex) { try { IHttpRequest failRequest = new HttpGetPostRequest(context.Request); string errorMessage = "处理请求失败:\n错误信息:" + ex.Message; logger.Error(errorMessage + "\n请求信息:\n" + failRequest.RequestData, ex); if (saveLogFailedRequestToDb) { SPFailedRequestWrapper.SaveFailedRequest(failRequest, errorMessage, 0, 0); } } catch (Exception e) { logger.Error("处理请求失败:\n错误信息:" + e.Message); } } }
public void ProcessRequest(HttpContext context) { try { xmlString = HttpXmlPostRequest.GetXmlPostValueFromRequest(context.Request); //logger.Error(xmlString); IHttpRequest httpRequest = new HttpXmlPostRequest(context.Request, xmlString, GetXmlNodeName()); //检测是否存在ashx if (string.IsNullOrEmpty(httpRequest.RequestFileName)) { LogWarnInfo(httpRequest, "请求失败:没有指定ashx路径。\n", 0, 0); return; } SPChannelWrapper channel = SPChannelWrapper.GetChannelByPath(GetChannelCodeName(context)); //如果没有找到通道 if (channel == null) { LogWarnInfo(httpRequest, "处理请求失败:无法找到对应的通道。\n", 0, 0); return; } saveLogFailedRequestToDb = channel.LogFailedRequestToDb; //如果通道未能运行 if (channel.CStatus != ChannelStatus.Run) { LogWarnInfo(httpRequest, "请求失败:\n" + "通道“" + channel.Name + "”未运行。\n", channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } //如果通道是监视通道,记录请求。 if (channel.IsMonitoringRequest.HasValue && channel.IsMonitoringRequest.Value) { SPMonitoringRequestWrapper.SaveRequest(httpRequest, channel.Id); } if (channel.HasConvertRule.HasValue && channel.HasConvertRule.Value) { try { PreProcessRequest(httpRequest.RequestParams, context, channel.FuzzyCommand); } catch (Exception ex) { LogWarnInfo(httpRequest, "数据转换错误:" + ex.Message, channel.Id, 0); } } //如果状态报告通道 if (channel.RecStatReport.HasValue && channel.RecStatReport.Value) { RequestError requestError1 = new RequestError(); bool result1 = false; if (channel.HasRequestTypeParams.HasValue && channel.HasRequestTypeParams.Value) { //报告状态请求 if (httpRequest.IsRequestContainValues(channel.RequestTypeParamName, channel.RequestReportTypeValue)) { if (httpRequest.IsRequestContainValues(channel.StatParamsName, channel.StatParamsValues)) { result1 = channel.RecState(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString(), out requestError1); } else { //channel.SaveStatReport(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString()); context.Response.Write(channel.GetOkCode(httpRequest)); return; } } //发送数据请求 else if (httpRequest.IsRequestContainValues(channel.RequestTypeParamName, channel.RequestDataTypeValue)) { result1 = channel.ProcessStateRequest(httpRequest, out requestError1); } else { LogWarnInfo(httpRequest, "未知类型请求", channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } } else { if (httpRequest.RequestParams.ContainsKey(channel.StatParamsName.ToLower())) { if (httpRequest.IsRequestContainValues(channel.StatParamsName, channel.StatParamsValues)) { if (channel.StatSendOnce.HasValue && channel.StatSendOnce.Value) { result1 = channel.ProcessRequest(httpRequest, out requestError1); } else { result1 = channel.RecState(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString(), out requestError1); } } else { //channel.SaveStatReport(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString()); context.Response.Write(channel.GetOkCode(httpRequest)); return; } } else { result1 = channel.ProcessStateRequest(httpRequest, out requestError1); } } //正确数据返回OK if (result1) { context.Response.Write(channel.GetOkCode(httpRequest)); return; } //重复数据返回OK if (requestError1.ErrorType == RequestErrorType.RepeatLinkID) { logger.Warn(requestError1.ErrorMessage); context.Response.Write(channel.GetOkCode(httpRequest)); return; } //其他错误类型记录错误请求 LogWarnInfo(httpRequest, requestError1.ErrorMessage, channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } RequestError requestError; bool result = channel.ProcessRequest(httpRequest, out requestError); if (result) { context.Response.Write(channel.GetOkCode(httpRequest)); return; } //重复数据返回OK if (requestError.ErrorType == RequestErrorType.RepeatLinkID) { logger.Warn(requestError.ErrorMessage); context.Response.Write(channel.GetOkCode(httpRequest)); return; } LogWarnInfo(httpRequest, requestError.ErrorMessage, channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); } catch (Exception ex) { try { IHttpRequest failRequest = new HttpXmlPostRequest(context.Request, xmlString, GetXmlNodeName()); string errorMessage = "处理请求失败:\n错误信息:" + ex.Message; logger.Error(errorMessage + "\n请求信息:\n" + failRequest.RequestData, ex); if (saveLogFailedRequestToDb) { SPFailedRequestWrapper.SaveFailedRequest(failRequest, errorMessage, 0, 0); } } catch (Exception e) { logger.Error("处理请求失败:\n错误信息:" + e.Message + xmlString); } } }
public void ProcessRequest(HttpContext context) { try { IHttpRequest httpRequest = new HttpSP0025PostRequest(context.Request); //检测是否存在ashx if (string.IsNullOrEmpty(httpRequest.RequestFileName)) { LogWarnInfo(httpRequest, "请求失败:没有指定ashx路径。\n", 0, 0); return; } SPChannelWrapper channel = SPChannelWrapper.GetChannelByPath(httpRequest.GetChannelCode()); bool isReportRequest = false; //如果没有找到通道 if (channel == null) { LogWarnInfo(httpRequest, "处理请求失败:无法找到对应的通道。\n", 0, 0); return; } saveLogFailedRequestToDb = channel.LogFailedRequestToDb; //如果通道未能运行 if (channel.CStatus != ChannelStatus.Run) { LogWarnInfo(httpRequest, "请求失败:\n" + "通道“" + channel.Name + "”未运行。\n", channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } //如果通道是监视通道,记录请求。 if (channel.IsMonitoringRequest.HasValue && channel.IsMonitoringRequest.Value) { SPMonitoringRequestWrapper.SaveRequest(httpRequest, channel.Id); } if (httpRequest.RequestParams.ContainsKey("spnumber")) { if (httpRequest.RequestParams["spnumber"].ToString().ToLower().Equals("91605")) { httpRequest.RequestParams["spnumber"] = "106691605"; } else if (httpRequest.RequestParams["spnumber"].ToString().ToLower().Equals("91608")) { httpRequest.RequestParams["spnumber"] = "106691608"; } else if (httpRequest.RequestParams.ContainsKey("exspnumber") && httpRequest.RequestParams["exspnumber"] != null && !string.IsNullOrEmpty(httpRequest.RequestParams["exspnumber"].ToString())) { httpRequest.RequestParams["spnumber"] = httpRequest.RequestParams["exspnumber"]; } } //如果状态报告通道 if (channel.RecStatReport.HasValue && channel.RecStatReport.Value) { RequestError requestError1 = new RequestError(); bool result1 = false; //分类型请求 if (channel.HasRequestTypeParams.HasValue && channel.HasRequestTypeParams.Value) { //报告状态请求 if (httpRequest.IsRequestContainValues(channel.RequestTypeParamName, channel.RequestReportTypeValue)) { if (httpRequest.IsRequestContainValues(channel.StatParamsName, channel.StatParamsValues)) { isReportRequest = true; result1 = channel.RecState(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString(), out requestError1); } else { //channel.SaveStatReport(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString()); context.Response.Write(channel.GetOkCode(httpRequest)); return; } } //发送数据请求 else if (httpRequest.IsRequestContainValues(channel.RequestTypeParamName, channel.RequestDataTypeValue)) { result1 = channel.ProcessStateRequest(httpRequest, out requestError1); } else { LogWarnInfo(httpRequest, "未知类型请求", channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } } else { if (httpRequest.RequestParams.ContainsKey(channel.StatParamsName.ToLower())) { if (httpRequest.IsRequestContainValues(channel.StatParamsName, channel.StatParamsValues)) { if (channel.StatSendOnce.HasValue && channel.StatSendOnce.Value) { result1 = channel.ProcessRequest(httpRequest, out requestError1); } else { result1 = channel.RecState(httpRequest, httpRequest.RequestParams[channel.StatParamsName.ToLower()].ToString(), out requestError1); } } else { context.Response.Write(channel.GetOkCode(httpRequest)); return; } } else { result1 = channel.ProcessStateRequest(httpRequest, out requestError1); } } //正确数据返回OK if (result1) { if (isReportRequest) { context.Response.Write(string.Format("received commandid={0}", context.Request["commandid"])); return; } context.Response.Write(channel.GetOkCode(httpRequest)); return; } //重复数据返回OK if (requestError1.ErrorType == RequestErrorType.RepeatLinkID) { logger.Warn(requestError1.ErrorMessage); context.Response.Write(channel.GetOkCode(httpRequest)); return; } //其他错误类型记录错误请求 LogWarnInfo(httpRequest, requestError1.ErrorMessage, channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); return; } RequestError requestError; bool result = channel.ProcessRequest(httpRequest, out requestError); if (result) { context.Response.Write(channel.GetOkCode(httpRequest)); return; } //重复数据返回OK if (requestError.ErrorType == RequestErrorType.RepeatLinkID) { logger.Warn(requestError.ErrorMessage); context.Response.Write(channel.GetOkCode(httpRequest)); return; } LogWarnInfo(httpRequest, requestError.ErrorMessage, channel.Id, 0); context.Response.Write(channel.GetFailedCode(httpRequest)); } catch (Exception ex) { try { IHttpRequest failRequest = new HttpGetPostRequest(context.Request); string errorMessage = "处理请求失败:\n错误信息:" + ex.Message; logger.Error(errorMessage + "\n请求信息:\n" + failRequest.RequestData, ex); if (saveLogFailedRequestToDb) { SPFailedRequestWrapper.SaveFailedRequest(failRequest, errorMessage, 0, 0); } } catch (Exception e) { logger.Error("处理请求失败:\n错误信息:" + e.Message); } } }