public bool ProcessStatusReport(IDataAdapter httpRequestLog, bool statusOk, out RequestErrorType requestError, out string errorMessage) { requestError = RequestErrorType.NoError; errorMessage = ""; string linkid = GetLinkID(httpRequestLog); if (string.IsNullOrEmpty(linkid)) { requestError = RequestErrorType.NoLinkID; errorMessage = " 通道 ‘" + Name + "’ 请求失败:没有LinkID ."; return(false); } if (!statusOk) { return(true); } SPRecordWrapper record = SPRecordWrapper.FindByChannelIDAndLinkID(linkid, this); if (!record.IsStatOK) { record.IsStatOK = statusOk; SPRecordWrapper.Update(record); record.SycnToClient(); return(true); } return(false); }
private void OnRetryPolicyDecision(IRetryPolicyMetrics metricsRegistry, RequestErrorType reason) { metricsRegistry.Total.Increment(); switch (reason) { case RequestErrorType.Unavailable: metricsRegistry.Unavailable.Increment(); break; case RequestErrorType.ReadTimeOut: metricsRegistry.ReadTimeout.Increment(); break; case RequestErrorType.WriteTimeOut: metricsRegistry.WriteTimeout.Increment(); break; case RequestErrorType.Other: case RequestErrorType.Aborted: case RequestErrorType.Unsent: case RequestErrorType.ClientTimeout: metricsRegistry.Other.Increment(); break; default: throw new ArgumentOutOfRangeException(nameof(reason), reason, null); } }
public void ConvertsToEnumCorrectly(RequestErrorType errorType, string input) { var json = $"{{\"Error\":\"{input}\"}}"; var result = JsonSerializer.Deserialize <RequestErrorConverterTestClass>(json); result.Error.Should().Be(errorType); }
private void BeIsErrorResultForPath(string path, RequestErrorType type) { Subject.Should().BeOfType <BadRequestObjectResult>() .Which.Value.Should().BeAssignableTo <IList <RequestError> >() .Which.Should().ContainSingle() .Which.Should().BeEquivalentTo(new RequestError { Error = type, Path = path }); }
public void ConvertsToStringCorrectly(RequestErrorType errorType, string expected) { var obj = new RequestErrorConverterTestClass { Error = errorType }; var result = JsonSerializer.Serialize(obj); result.Should().Be($"{{\"Error\":\"{expected}\"}}"); }
private void GetCommonMeta(string ric) { // For the sake of conciseness both data and error callbacks are specified as lambda expressions. this.metadataRequest = DataServices.Instance.TimeSeries.Metadata.GetCommonData(ric, metaDatas => { var meta = metaDatas; }, error => { RequestErrorType errorType = error.Type; string errorMessage = error.Message; MessageBox.Show(errorMessage, errorType.ToString()); }); }
public static Tuple <string, string> GetUploadErrorMessage(RequestErrorType errorType, Type errorResourceType) { Tuple <string, string> errorMessage = null; if (errorResourceType != null) { errorMessage = errorType switch { RequestErrorType.FileType => new Tuple <string, string>("File", CommonHelper.GetResourceMessage("Must_Be_Csv_Validation_Message", errorResourceType)), RequestErrorType.FileSize => new Tuple <string, string>("File", string.Format(CommonHelper.GetResourceMessage("File_Size_Too_Large_Validation_Message", errorResourceType), Constants.MaxFileSizeInMb)), RequestErrorType.NotSpecified => null, _ => null }; } return(errorMessage); }
public void OnRequestError(Host host, RequestErrorType errorType, RetryDecision.RetryDecisionType decision) { var nodeMetrics = _manager.GetOrCreateNodeMetrics(host); OnRequestError(nodeMetrics.Errors, errorType); switch (decision) { case RetryDecision.RetryDecisionType.Retry: OnRetryPolicyDecision(nodeMetrics.Retries, errorType); break; case RetryDecision.RetryDecisionType.Ignore: OnRetryPolicyDecision(nodeMetrics.Ignores, errorType); break; } }
protected override RequestErrorType RecievedRequest(IDataAdapter httpRequestLog, SPChannelWrapper channel, out bool requestOK, out string errorMessage) { RequestType requestType = channel.GetRequestType(httpRequestLog); RequestErrorType requestError = RequestErrorType.NoError; errorMessage = ""; requestOK = false; if (requestType == RequestType.DataReport) { bool statusOk = true; if (channel.IsStateReport && (channel.StateReportType == DictionaryConst.Dictionary_ChannelStateReportType_SendTwiceTypeRequest_Key || channel.StateReportType == DictionaryConst.Dictionary_ChannelStateReportType_SendTwice_Key)) { statusOk = false; } requestOK = channel.ProcessRequest(httpRequestLog, statusOk, out requestError, out errorMessage); } else if (requestType == RequestType.StatusReport) { bool statusOk = channel.GetStatus(httpRequestLog); requestOK = channel.ProcessStatusReport(httpRequestLog, statusOk, out requestError, out errorMessage); } else if (requestType == RequestType.DataStatusReport) { bool statusOk = channel.GetStatus(httpRequestLog); requestOK = channel.ProcessRequest(httpRequestLog, statusOk, out requestError, out errorMessage); } return(requestError); }
private void OnRequestError(IRequestErrorMetrics metricsRegistry, RequestErrorType errorType) { switch (errorType) { case RequestErrorType.Unavailable: metricsRegistry.Unavailable.Increment(); break; case RequestErrorType.ReadTimeOut: metricsRegistry.ReadTimeout.Increment(); break; case RequestErrorType.WriteTimeOut: metricsRegistry.WriteTimeout.Increment(); break; case RequestErrorType.Other: metricsRegistry.Other.Increment(); break; case RequestErrorType.Aborted: metricsRegistry.Aborted.Increment(); break; case RequestErrorType.Unsent: metricsRegistry.Unsent.Increment(); break; case RequestErrorType.ClientTimeout: metricsRegistry.ClientTimeout.Increment(); break; default: throw new ArgumentOutOfRangeException(nameof(errorType), errorType, null); } }
protected override RequestErrorType RecievedRequest(IDataAdapter httpRequestLog, SPChannelWrapper channel, out bool requestOK, out string errorMessage) { RequestType requestType = channel.GetRequestType(httpRequestLog); RequestErrorType requestError = RequestErrorType.NoError; errorMessage = ""; requestOK = false; int feetime = Convert.ToInt32(channel.GetFeetime(httpRequestLog)); string linkid = channel.GetLinkID(httpRequestLog); bool statusOk = true; if (requestType == RequestType.DataStatusReport) { statusOk = channel.GetStatus(httpRequestLog); } if (statusOk == false) { requestOK = true; return(requestError); } for (int i = 0; i < feetime; i++) { IDataAdapter request = new HttpGetPostAdapter(httpRequestLog); string linkidKey = channel.ChannelParams[DictionaryConst.Dictionary_SPField_LinkID_Key]; if (request.RequestParams.ContainsKey(linkidKey)) { request.RequestParams[linkidKey] = linkid + "-" + i.ToString(); } else { request.RequestParams.Add(linkidKey, linkid + "-" + i.ToString()); } string feeTimeKey = channel.ChannelParams[DictionaryConst.Dictionary_SPField_FeeTime_Key]; if (request.RequestParams.ContainsKey(feeTimeKey)) { request.RequestParams[feeTimeKey] = feetime.ToString(); } else { request.RequestParams.Add(feeTimeKey, feetime.ToString()); } requestOK = channel.ProcessRequest(request, statusOk, out requestError, out errorMessage); } return(requestError); }
public void OnRequestError(Host host, RequestErrorType errorType, RetryDecision.RetryDecisionType decision) { }
public RequestErrorModel(RequestErrorType reqErrorType, RequestErrorMessage reqErrorMessage) { this.RequestErrorTypeEnum = reqErrorType; this.RequestErrorMessageEnum = reqErrorMessage; }
public bool ProcessRequest(IDataAdapter httpRequestLog, bool statusOk, out RequestErrorType requestError, out string errorMessage) { requestError = RequestErrorType.NoError; errorMessage = ""; string linkid = GetLinkID(httpRequestLog); if (string.IsNullOrEmpty(linkid)) { requestError = RequestErrorType.NoLinkID; errorMessage = " 通道 ‘" + Name + "’ 请求失败:没有LinkID ."; return(false); } if (this.CheckLinkIDIsExisted(linkid)) { requestError = RequestErrorType.RepeatLinkID; errorMessage = " 通道 ‘" + Name + "’ 请求失败:重复的LinkID (缓存检查) ."; return(false); } string mo = this.ChannelParams.MoFromRequset(httpRequestLog); if (this.ChannelType == DictionaryConst.Dictionary_ChannelType_IVRChannel_Key) { mo = "ivr"; } string spcode = this.ChannelParams.SPCodeFromRequset(httpRequestLog); string mobile = this.ChannelParams.MobileFromRequset(httpRequestLog); string province = ""; string city = ""; string mobileOperator = ""; PhoneArea phoneArea = this.GetProvinceAndCity(mobile); if (phoneArea != null) { if (!string.IsNullOrEmpty(phoneArea.Province)) { province = phoneArea.Province; } else { province = ""; } if (!string.IsNullOrEmpty(phoneArea.City)) { city = phoneArea.City; } else { city = ""; } if (!string.IsNullOrEmpty(phoneArea.OperatorType)) { mobileOperator = phoneArea.OperatorType; } else { mobileOperator = ""; } } SPCodeWrapper matchCode = null; if (this.ChannelType == DictionaryConst.Dictionary_ChannelType_IVRChannel_Key) { matchCode = this.GetMatchCodeFromIVRRequest(httpRequestLog, spcode, province, city); } else { matchCode = this.GetMatchCodeFromRequest(httpRequestLog, mo, spcode, province, city); } if (matchCode == null) { requestError = RequestErrorType.NoChannelClientSetting; errorMessage = "请求失败:通道‘" + Name + "’请求未能找到匹配的代码设置。"; return(false); } SPClientCodeRelationWrapper clientCodeRelation = matchCode.GetRelateClientCodeRelation(); //如果存在指令,但是不存在对应的分配关系,转到默认匹配 if (clientCodeRelation == null) { clientCodeRelation = this.GetDefaultClientCodeRelation(); //如果是指令没有分配下家如何处理。 //matchCode = clientCodeRelation.CodeID; } SPRecordWrapper record = new SPRecordWrapper(); record.ChannelID = this; record.CodeID = matchCode; record.ClientID = clientCodeRelation.ClientID; record.ClientCodeRelationID = clientCodeRelation; record.Mo = mo; record.Mobile = mobile; record.LinkID = linkid; record.SpNumber = spcode; record.Province = province; record.City = city; record.OperatorType = mobileOperator; record.CreateDate = GetRecordTime(httpRequestLog); record.IsReport = false; record.IsStatOK = statusOk; record.IsIntercept = this.CaculteIsIntercept(matchCode, clientCodeRelation); if (record.IsIntercept) { record.IsSycnToClient = false; record.IsSycnSuccessed = false; record.SycnRetryTimes = 0; } else { if (!clientCodeRelation.SyncData) { record.IsSycnToClient = false; record.IsSycnSuccessed = false; record.SycnRetryTimes = 0; } else { record.IsSycnToClient = true; record.IsSycnSuccessed = false; record.SycnRetryTimes = 0; } } record.Price = clientCodeRelation.Price; record.Count = GetRecordCount(httpRequestLog); SPRecordExtendInfoWrapper spRecordExtendInfo = new SPRecordExtendInfoWrapper(); spRecordExtendInfo.StartTime = this.ChannelParams.StartTimeFromRequset(httpRequestLog); spRecordExtendInfo.EndTime = this.ChannelParams.EndTimeFromRequset(httpRequestLog); spRecordExtendInfo.FeeTime = this.ChannelParams.FeeTimeFromRequset(httpRequestLog); spRecordExtendInfo.State = this.ChannelParams.StateFromRequset(httpRequestLog); spRecordExtendInfo.Ip = httpRequestLog.RequestIp; spRecordExtendInfo.RequestContent = httpRequestLog.RequestData; spRecordExtendInfo.ExtendField1 = this.ChannelParams.ExtendField1FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField2 = this.ChannelParams.ExtendField2FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField3 = this.ChannelParams.ExtendField3FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField4 = this.ChannelParams.ExtendField4FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField5 = this.ChannelParams.ExtendField5FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField6 = this.ChannelParams.ExtendField6FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField7 = this.ChannelParams.ExtendField7FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField8 = this.ChannelParams.ExtendField8FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField9 = this.ChannelParams.ExtendField9FromRequset(httpRequestLog); spRecordExtendInfo.ExtendField10 = this.ChannelParams.ExtendField10FromRequset(httpRequestLog); try { bool result = SPRecordWrapper.InsertPayment(record, spRecordExtendInfo, out requestError, out errorMessage); if (!result && requestError == RequestErrorType.RepeatLinkID) { requestError = RequestErrorType.RepeatLinkID; errorMessage = " 通道 ‘" + Name + "’ 请求失败:重复的LinkID(查询排重 异常排重) ."; return(false); } requestError = RequestErrorType.NoError; errorMessage = ""; try { CacheProviderFactory.GetLinkIDCache().AddLinkIDs(linkid, this.Id); } catch (Exception ex) { Logger.Error(ex.Message); } record.SycnToClient(); return(true); } catch (Exception ex) { requestError = RequestErrorType.DataSaveError; errorMessage = "请求失败:插入数据失败,错误信息:" + ex.Message; return(false); } }
public bool InsertPayment(SPRecordEntity record, SPRecordExtendInfoEntity spRecordExtendInfo, out RequestErrorType requestError, out string errorMessage) { requestError = RequestErrorType.NoError; if (this.CheckHasLinkIDAndChannelID(record.ChannelID, record.LinkID)) { requestError = RequestErrorType.RepeatLinkID; errorMessage = ""; return(false); } try { this.DataObjectsContainerIocID.SPRecordDataObjectInstance.Save(record); spRecordExtendInfo.RecordID = record; this.DataObjectsContainerIocID.SPRecordExtendInfoDataObjectInstance.Save(spRecordExtendInfo); errorMessage = ""; return(true); } catch (Exception ex) { Exception innerEx = ex; while (innerEx.InnerException != null) { innerEx = innerEx.InnerException; } if (innerEx is SqlException && ((SqlException)innerEx).Number == 2601) { requestError = RequestErrorType.RepeatLinkID; errorMessage = ""; return(false); } throw ex; } }
public RequestDetailError( RequestErrorType errorType) { _errorType = errorType; }
public RetryDecisionWithReason(RetryDecision decision, RequestErrorType reason) { Decision = decision; Reason = reason; }
public RequestErrorModel(RequestErrorType reqErrorType, RequestErrorMessage reqErrorMessage, int crimeIndex) { this.RequestErrorTypeEnum = reqErrorType; this.RequestErrorMessageEnum = reqErrorMessage; this.CrimeRequestIndex = crimeIndex; }
public RequestDetailError(RequestErrorType errorType) { _errorType = errorType; }
public static bool InsertPayment(SPRecordWrapper record, SPRecordExtendInfoWrapper spRecordExtendInfo, out RequestErrorType requestError, out string errorMessage) { return(businessProxy.InsertPayment(record.Entity, spRecordExtendInfo.Entity, out requestError, out errorMessage)); }
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); } } }