/// <summary> /// //发送报警邮件(公共请求失败的情况下) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="param"></param> /// <param name="requestDesc"></param> /// <param name="exception"></param> /// <param name="sysCode"></param> /// <param name="host"></param> /// <param name="url"></param> /// <param name="retryCount"></param> private static void SendMailForCommonDoRequestFailure <T>(T param, string requestDesc, ExceptionInfoEntity exception, string sysCode, string host, string url, int retryCount, BusinessExceptionMgrParam businessExceptionParam) { var mailTitle = "请求[" + requestDesc + "]" + exception.exceptionMsg; var describe = new StringBuilder(); describe.Append(mailTitle + "!!!<br/>"); describe.Append(" 请求系统:" + sysCode + "<br/>"); describe.Append(" 请求地址:" + host + url + "<br/>"); describe.Append(" 请求参数:" + JsonConvert.SerializeObject(param) + "<br/>"); //邮箱标题 var mailSubject = requestDesc + "请求" + retryCount.ToString() + "次失败"; mailSubject += "[ "; if (businessExceptionParam != null) { mailSubject += "任务号:" + (businessExceptionParam.taskNo == null ? "" : businessExceptionParam.taskNo) + " , "; mailSubject += "流转卡号:" + (businessExceptionParam.processCardNumber == null ? "" : businessExceptionParam.processCardNumber); } mailSubject += " ]"; IMail mail = new Mail(WIPCommon.GetMailCategoryBySysIntegr(sysCode)); mail.MailSending(mailSubject, describe.ToString(), ""); }
/// <summary> /// 替换打印的占位符 /// </summary> /// <typeparam name="T">要取值的实体对象</typeparam> /// <param name="obj">要取值的实体对象值</param> /// <param name="json_dataList"></param> /// <returns></returns> public string Replace <T>(T obj, string json_dataList) { PropertyInfo[] properArray = typeof(T).GetProperties(); Object value = null; string str = ""; foreach (var proper in properArray) { if (proper.GetCustomAttribute(typeof(PrintAttribute), false) != null) { value = proper.GetValue(obj, null); if (value == null) { value = ""; } if (proper.PropertyType == typeof(string)) { str = StringHelper.NullToEmpty(value.ToString()); } else if (proper.PropertyType == typeof(int?) || proper.PropertyType == typeof(int)) { str = StringHelper.NullToEmpty(value == null ? "" : value.ToString()); } else if (proper.PropertyType == typeof(DateTime) || proper.PropertyType == typeof(DateTime?)) { str = WIPCommon.FormatDateTime((DateTime?)value); } //替换 json_dataList = json_dataList.Replace("[" + proper.Name + "]", str); } } return(json_dataList); }
private void PostMail(MailBaseData _MailBaseData, string recipientsAddressRange, string MailSubject, string Describe, string File_Path) { MailSubject = MailSubject + " (" + WIPCommon.ForamtCurDateTime() + ")";//任务名称 Describe += "<br/><br/>"; Describe += "消息来自主机:" + WIPCommon.GetHostName() + "<br/>"; Describe += "主机发生时间:" + WIPCommon.ForamtCurDateTime() + "<br/>"; IDictionary <string, object> logDict = new Dictionary <string, object>(); logDict.Add("recipientsAddressRange", recipientsAddressRange); logDict.Add("MailSubject", MailSubject); logDict.Add("Describe", Describe); logDict.Add("File_Path", File_Path); ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <IDictionary <string, object> >(namespaceName, "MailSending", logDict, "", ""); try { if (File_Path == null) { File_Path = ""; } SMTPHelper.MailSending(_MailBaseData, _recipientsAddressRange, MailSubject, Describe.ToString(), ""); } catch (Exception ex) { WipLogHelper.GetExceptionInfoForError(ex, ref exception); WipLogHelper.WriteExceptionInfo(exception); } }
public override void PreExcute(string MethodName, IDictionary <string, object> InParams) { #region 异步处理 Task.Run(() => { RequestRecordEntity requestRecord = new RequestRecordEntity() { direction = 1, // 1 WIP接收 2 WIP 推送 happenHost = WIPCommon.GetHostName(msgSource), fullFun = namespaceName + "." + MethodName, //方法名 param = JsonConvert.SerializeObject(InParams), //入参 }; Log4netHelper.WriteInfoLogByLog4Net(typeof(Log4netHelper), JsonConvert.SerializeObject(requestRecord)); requestRecordDAL.Add(requestRecord); }); //*/ #endregion }
/// <summary> /// 初始化异常信息类(仅仅是获取异常信息对象) /// </summary> /// <typeparam name="T">入参类</typeparam> /// <param name="namespaceName">当前命名空间名</param> /// <param name="exceptionFun">方法名</param> /// <param name="param">入参类</param> /// <param name="exceptionSource">异常方向,默认是WIP接收</param> /// <param name="msgSource">消息来源,默认是WIPREST服务</param> /// <returns></returns> public static ExceptionInfoEntity GetExceptionInfo <T>(string namespaceName, string exceptionFun, T param, string key1 = "", string key2 = "", ExceptionSource exceptionSource = ExceptionSource.WIPReceive, ExceptionLevel exceptionLevel = ExceptionLevel.BusinessError , string msgSource = WipSource.WIPREST) { ExceptionInfoEntity exception = new ExceptionInfoEntity() { host = WIPCommon.GetHostName(msgSource), key1 = key1, key2 = key2, exceptionLevel = Convert.ToInt32(exceptionLevel).ToString(), //异常级别:默认是业务错误 exceptionFun = namespaceName + "." + exceptionFun, //异常方法名 exceptionSource = Convert.ToInt32(exceptionSource).ToString(), //异常方向 sourceData = JsonConvert.SerializeObject(param), //入参 creator = JwtHelp.GetCurUserName() }; return(exception); }
/// <summary> /// 记录请求日志 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="namespaceName"></param> /// <param name="exceptionFun"></param> /// <param name="param"></param> public static void WriteRequestRecord <T>(string host, string url, T param, Guid guid, string retResult = "") { RequestRecordEntity requestRecord = null; try { requestRecord = new RequestRecordEntity() { direction = 2,// 1 WIP接收 2 WIP 推送 happenHost = WIPCommon.GetHostName(), remark = guid.ToString(), host = host, url = url, retResult = retResult, param = JsonConvert.SerializeObject(param), //入参 }; requestRecordDAL.Add(requestRecord); } catch (Exception ex) { Log4netHelper.WriteErrorLogByLog4Net(typeof(Log4netHelper), "WriteRequestRecord记录异常表出现异常,exception:" + JsonConvert.SerializeObject(requestRecord), ex); } }
/// <summary> /// 验证是否为空 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="columnsList"></param> /// <param name="model"></param> /// <returns></returns> public static ValidateResModel ValidateNullOrEmpty <T>(List <ColumnsModel> columnsList, T model) { ValidateResModel res = new ValidateResModel() { IsValidate = true }; //默认验证通过 ColumnsModel columnsModel = null; PropertyInfo property = null; //属性对象 Object property_value = null; //属性值 string str = ""; for (int j = 0; j < columnsList.Count; j++) { columnsModel = columnsList[j]; property = typeof(T).GetProperty(columnsModel.PropertyName.Trim()); if (property == null) { throw new Exception("列名'" + columnsModel.PropertyName + "'不存在类中"); } property_value = property.GetValue(model, null); if (property.PropertyType == typeof(DateTime) || property.PropertyType == typeof(DateTime?)) { try { Convert.ToDateTime(property_value); } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "时间格式不正确"; break; } } else if (property.PropertyType == typeof(string)) { str = property_value == null ? "" : Convert.ToString(property_value); if (!columnsModel.IsNullable) {//必输 if (string.IsNullOrEmpty(str.Trim())) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "不能为空"; break; } } #region 验证日期类型的字符串格式(因为json这边接收的日期类型都是字符串) if (columnsModel.DataType == typeof(DateTime) && !string.IsNullOrEmpty(str)) {//如果是日期类型,并且传入的值不为空,则需要验证日期格式是否正确 try { Convert.ToDateTime(property_value); } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "时间格式不正确"; break; } } #endregion #region 验证格林威治日期类型的字符串格式(因为json这边接收的日期类型都是字符串) if (columnsModel.DataType == typeof(GreenwichTimeStamp) && !string.IsNullOrEmpty(str)) {//如果是日期类型,并且传入的值不为空,则需要验证日期格式是否正确 try { DateTime?dt = WIPCommon.ForamtGreenwichTimeStampToDateTime(str); if (dt == null) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "格林威治时间格式不正确"; } } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "格林威治时间格式不正确"; break; } } #endregion } else if (property.PropertyType == typeof(int)) { try { int timestamp = Convert.ToInt32(property_value); if (timestamp == 0) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "不能为0"; break; } } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "int格式不正确"; break; } } else if (property.PropertyType == typeof(long)) { if (columnsModel.DataType == typeof(UnixTimeStamp)) {//验证long类型的unix时间戳 try { long timestamp = Convert.ToInt64(property_value); if (timestamp == 0) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "unix时间戳不能为0"; break; } } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "unix时间戳格式不正确"; break; } } } else if (property.PropertyType == typeof(decimal) || property.PropertyType == typeof(decimal?)) { } } return(res); }
/// <summary> /// 验证是否为空 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="columnsList"></param> /// <param name="model"></param> /// <returns></returns> public static ValidateResModel ValidateNullOrEmpty(List <ValidateModel> columnsList) { ValidateResModel res = new ValidateResModel() { IsValidate = true }; //默认验证通过 ValidateModel columnsModel = null; Object property_value = null; //属性值 string str = ""; for (int j = 0; j < columnsList.Count; j++) { columnsModel = columnsList[j]; property_value = columnsModel.DataValue; #region 验证日期类型的字符串格式(因为json这边接收的日期类型都是字符串) if (columnsModel.DataType == typeof(DateTime)) {//如果是日期类型,并且传入的值不为空,则需要验证日期格式是否正确 str = property_value == null ? "" : Convert.ToString(property_value); try { if (!columnsModel.IsNullable) {//必输 if (string.IsNullOrEmpty(str.Trim())) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "不能为空"; break; } } if (!string.IsNullOrEmpty(str.Trim())) { Convert.ToDateTime(property_value); } } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "时间格式不正确"; break; } } #endregion #region 验证格林威治日期类型的字符串格式(因为json这边接收的日期类型都是字符串) else if (columnsModel.DataType == typeof(GreenwichTimeStamp)) {//如果是日期类型,并且传入的值不为空,则需要验证日期格式是否正确 str = property_value == null ? "" : Convert.ToString(property_value); try { if (!columnsModel.IsNullable) {//必输 if (string.IsNullOrEmpty(str.Trim())) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "不能为空"; break; } } if (!string.IsNullOrEmpty(str.Trim())) { DateTime?dt = WIPCommon.ForamtGreenwichTimeStampToDateTime(str); if (dt == null) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "格林威治时间格式不正确"; } } } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "格林威治时间格式不正确"; break; } } #endregion else if (columnsModel.DataType == typeof(string)) { str = property_value == null ? "" : Convert.ToString(property_value); if (!columnsModel.IsNullable) {//必输 if (string.IsNullOrEmpty(str.Trim())) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "不能为空"; break; } } } else if (columnsModel.DataType == typeof(int)) { try { int timestamp = Convert.ToInt32(property_value); if (timestamp == 0) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "不能为0"; break; } } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "int格式不正确"; break; } } else if (columnsModel.DataType == typeof(UnixTimeStamp)) {//验证long类型的unix时间戳 try { long timestamp = Convert.ToInt64(property_value); if (timestamp == 0) { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "unix时间戳不能为0"; break; } } catch { res.IsValidate = false; res.ValidateMsg = columnsModel.ChinaName + "unix时间戳格式不正确"; break; } } else if (columnsModel.DataType == typeof(decimal) || columnsModel.DataType == typeof(decimal?)) { } } return(res); }