private void EndRequest(HttpContext context, IHttpRequest httpRequest, SPChannelWrapper channel)
        {
            try
            {
                //如果通道是监视通道,记录请求。
                if (channel.IsMonitoringRequest.HasValue && channel.IsMonitoringRequest.Value)
                {
                    if (!httpRequest.RequestParams.ContainsKey(Key_EndRequestTime))
                    {
                        httpRequest.RequestParams.Add(Key_EndRequestTime, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    }

                    SPMonitoringRequestWrapper.SaveRequest(httpRequest, channel.Id);
                }
            }
            catch (Exception e)
            {
                logger.Error("日志记录失败:" + e.Message);
            }
        }
        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);
                }
            }
        }
Пример #3
0
        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);
                }
            }
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                IDataAdapter httpRequestLog = GetHttpRequestLog(context);

                //检测是否存在ashx
                if (string.IsNullOrEmpty(httpRequestLog.RequestFileName))
                {
                    LogWarnInfo(httpRequestLog, "请求失败:没有指定ashx路径。\n", 0, 0);

                    return;
                }

                string dataAdaptorUrl = httpRequestLog.GetChannelCode();

                SPChannelWrapper channel = SPChannelWrapper.GetChannelByDataAdaptorUrl(dataAdaptorUrl);

                //如果没有找到通道
                if (channel == null)
                {
                    LogWarnInfo(httpRequestLog, "处理请求失败:无法找到对应的通道。\n", 0, 0);

                    return;
                }

                //如果通道未能运行
                if (channel.ChannelStatus != DictionaryConst.Dictionary_ChannelStatus_Run_Key)
                {
                    LogWarnInfo(httpRequestLog, "请求失败:\n" + "通道“" + channel.Name + "”未运行。\n", channel.Id, 0);

                    context.Response.Write(channel.GetFailedCode(httpRequestLog));

                    return;
                }

                //如果通道是监视通道,记录请求。
                if (channel.IsMonitorRequest)
                {
                    SPMonitoringRequestWrapper.SaveRequest(httpRequestLog, channel);
                }

                //过滤请求
                if (channel.HasFilters)
                {
                    if (channel.CheckRequestIsFilters(httpRequestLog))
                    {
                        LogWarnInfo(httpRequestLog, "请求失败:\n" + "通道“" + channel.Name + "”属于过滤请求。\n", channel.Id, 0);

                        context.Response.Write(channel.GetFailedCode(httpRequestLog));
                    }
                }

                //参数转换
                if (channel.IsParamsConvert)
                {
                    channel.ParamsConvert(httpRequestLog);
                }

                PreProcessRequest(httpRequestLog);

                bool   requestOK;
                string errorMessage;

                RequestErrorType requestError = RecievedRequest(httpRequestLog, channel, out requestOK, out errorMessage);

                //正确数据返回OK
                if (requestOK)
                {
                    context.Response.Write(channel.GetOkCode(httpRequestLog));
                    return;
                }

                //重复数据返回OK
                if (requestError == RequestErrorType.RepeatLinkID)
                {
                    logger.Warn(errorMessage);
                    context.Response.Write(channel.GetOkCode(httpRequestLog));
                    return;
                }

                //其他错误类型记录错误请求
                LogWarnInfo(httpRequestLog, errorMessage, channel.Id, 0);

                context.Response.Write(channel.GetFailedCode(httpRequestLog));

                return;
            }
            catch (Exception ex)
            {
                try
                {
                    IDataAdapter failRequest = GetHttpRequestLog(context);


                    string errorMessage = "处理请求失败:\n错误信息:" + ex.Message;

                    logger.Error(errorMessage + "\n请求信息:\n" + failRequest.RequestData, ex);
                }
                catch (Exception e)
                {
                    logger.Error("处理请求失败:\n错误信息:" + e.Message);
                }
            }
        }