protected virtual object ResultHandle(IAOPResult aop, Type returnType, ISerializer serializer) { #if DEBUG Logging.LogService.Debug(aop.ToString(), this); #endif object returnValue = null; if (!typeof(IAOPResult).IsAssignableFrom(returnType)) { //不是返回IAOPResult,需要去掉IAOPResult if (aop.ResultNo == 0) { if (returnType != typeof(void)) //不是无返回值 { if (aop.ResultAttachObject != null) { returnValue = returnType.IsInstanceOfType(aop.ResultAttachObject) ? aop.ResultAttachObject : serializer.Convert(aop.ResultAttachObject, returnType, null); } } } else { throw new ResultException(aop.ResultNo, aop.ResultDescription); } } else { returnValue = aop; } return(returnValue); }
/// <summary> /// 获取附加对象 /// </summary> /// <param name="aop"><see cref="IAOPResult"/> 泛型实例</param> /// <param name="throwErrorOnFailed">失败时是否抛出异常</param> /// <returns>附加对象</returns> public static T GetAttachObject <T>(this IAOPResult <T> aop, bool throwErrorOnFailed) { if (throwErrorOnFailed) { aop.ThrowErrorOnFailed(); } return(aop.ResultAttachObjectEx); }
/// <summary> /// 对失败结果进行处理 /// </summary> /// <typeparam name="T">泛型类型</typeparam> /// <param name="aop"><see cref="IAOPResult{T}"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult{T}"/>实例</returns> public static IAOPResult <T> Failed <T>(this IAOPResult <T> aop, Action <IAOPResult <T> > handler) { if (aop.IsUnSuccess() && handler != null) { handler(aop); } return(aop); }
/// <summary> /// 对失败结果进行处理 /// </summary> /// <param name="aop"><see cref="IAOPResult{T}"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult"/>实例</returns> public static IAOPResult Failed(this IAOPResult aop, Func <IAOPResult, IAOPResult> handler) { if (aop.IsUnSuccess() && handler != null) { aop = handler(aop); } return(aop); }
/// <summary> /// 对成功结果进行处理 /// </summary> /// <param name="aop"><see cref="IAOPResult"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult"/>实例</returns> public static IAOPResult Success(this IAOPResult aop, Action <IAOPResult> handler) { if (aop.IsSuccess() && handler != null) { handler(aop); } return(aop); }
/// <summary> /// 对成功结果进行处理 /// </summary> /// <typeparam name="T">泛型类型</typeparam> /// <param name="aop"><see cref="IAOPResult{T}"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult{T}"/>实例</returns> public static IAOPResult <T> Success <T>(this IAOPResult <T> aop, Func <IAOPResult <T>, IAOPResult <T> > handler) { if (aop.IsSuccess() && handler != null) { aop = handler(aop); } return(aop); }
/// <summary> /// 对返回结果进行处理 /// </summary> /// <param name="aop"><see cref="IAOPResult{T}"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult{T}"/>实例</returns> public static IAOPResult <T> Handle <T>(this IAOPResult <T> aop, Func <IAOPResult <T>, IAOPResult <T> > handler) { if (handler != null) { aop = handler(aop); } return(aop); }
/// <summary> /// 对返回结果进行处理 /// </summary> /// <param name="aop"><see cref="IAOPResult"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult"/>实例</returns> public static IAOPResult Handle(this IAOPResult aop, Func <IAOPResult, IAOPResult> handler) { if (handler != null) { aop = handler(aop); } return(aop); }
/// <summary> /// 把<see cref="IAOPResult"/>接口转换成类实例<see cref="AOPResult"/> /// </summary> /// <param name="aop"><see cref="IAOPResult"/>接口实例</param> /// <param name="initializer">初始器</param> /// <returns><see cref="AOPResult"/>实例</returns> internal static AOPResult ToAOPResult(IAOPResult aop, Action <AOPResult> initializer) { if (aop != null) { var aopResult = aop as AOPResult ?? (AOPResult)Create(aop.ResultNo, aop.ResultDescription, aop.ResultAttachObject, aop.InnerAOPResult, aop.GetResultData()); initializer?.Invoke(aopResult); return(aopResult); } return(null); }
/// <summary> /// 如果处理失败,则抛出异常 <see cref="ExceptionBase"/> /// </summary> /// <returns>返回本身</returns> public static IAOPResult ThrowErrorOnFailed(this IAOPResult aop) { if (aop.IsFailed()) { var e = new ExceptionBase(aop.ResultNo, aop.ResultDescription); e.Data.Add(typeof(IAOPResult), aop); throw e; } return(aop); }
/// <summary> /// 把<see cref="IAOPResult"/>接口转换成类实例<see cref="AOPResult"/> /// </summary> /// <param name="aop"><see cref="IAOPResult"/>接口实例</param> /// <param name="initializer">初始器</param> /// <returns><see cref="AOPResult"/>实例</returns> public static AOPResult ToAOPResult(this IAOPResult aop, Action <AOPResult> initializer) { if (aop != null) { var result = aop is AOPResult ? (AOPResult)aop : (AOPResult)AOPResult.Create(aop.ResultNo, aop.ResultDescription, aop.ResultAttachObject, aop.InnerAOPResult, aop.GetResultData()); if (initializer != null) { initializer(result); } return(result); } return(null); }
/// <summary> /// 把<c>IAOPResult</c>转换成<c>IAOPResult<T></c> /// </summary> /// <typeparam name="T">附加的泛型</typeparam> /// <param name="aop">待转换的<c>IAOPResult</c></param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <T> ToAOPResult <T>(this IAOPResult aop) { if (aop is IAOPResult <T> ) { return((IAOPResult <T>)aop); } var attachObject = default(T); if (aop.ResultAttachObject is T) { attachObject = (T)aop.ResultAttachObject; } return(AOPResult.Create(aop.ResultNo, aop.ResultDescription, attachObject, aop, aop.GetResultData())); }
/// <summary> /// 获取附加对象 /// </summary> /// <param name="aop"><see cref="IAOPResult"/> 泛型实例</param> /// <param name="throwErrorOnFailed">失败时是否抛出异常</param> /// <returns>附加对象</returns> public static T GetAttachObject <T>(this IAOPResult aop, bool throwErrorOnFailed) { if (throwErrorOnFailed) { aop.ThrowErrorOnFailed(); } var result = aop.ResultAttachObject; if (result != null && result is T) { return((T)result); } return(default(T)); }
/// <summary> /// 把<c>IAOPResult</c>转换成<c>IAOPResult<T></c> /// </summary> /// <typeparam name="T">附加的泛型</typeparam> /// <param name="aop">待转换的<c>IAOPResult</c></param> /// <param name="initializer">初始器</param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <T> ToAOPResult <T>(this IAOPResult aop, Action <AOPResult <T> > initializer) { if (aop is IAOPResult <T> ) { return((IAOPResult <T>)aop); } var attachObject = default(T); if (aop.ResultAttachObject is T) { attachObject = (T)aop.ResultAttachObject; } var result = (AOPResult <T>)AOPResult.Create(aop.ResultNo, aop.ResultDescription, attachObject, aop, aop.GetResultData()); if (initializer != null) { initializer(result); } return(result); }
public ActionResult UserRoleDelete(int id) { IAOPResult result = null; if (!PermissionClientService.Authorize("Admin.PermissionUserRoleDeleteAll", includeStack: false)) //没有对所有角色操作的权限,则需要限制为当前用户拥有的角色 { var userRoles = this.PermissionServer.GetUserGroupRoles(); var roleNo = userRoles.Where(x => x.ID == id).Select(x => x.TargetValue).SingleOrDefault(); //判断是否是当前用户可管理的角色 var roles = PermissionClientService.GetUserPermissions("Admin.PermissionUserManageRole"); var exists = roles.Any(x => x.PermissionValue.StringEquals(roleNo)); if (!exists) { result = AOPResult.Failed("Access Denied"); } } if (result == null) { result = this.PermissionServer.DeleteUserRole(id); } return(this.Json(new { result.ResultNo, result.ResultDescription })); }
protected virtual IAOPResult PublishMessage(EventMessage message) { IAOPResult result = null; if (string.IsNullOrEmpty(message.MessageGuid)) { message.MessageGuid = Guid.NewGuid().ToString("N"); } if (this.Setting.PublishToServer) { result = this.PublishToServer(message); } if (this.Setting.PublishToLocal) { result = this.PublishToLocal(message); } if (result == null) { result = AOPResult.Success(); } return(result); }
protected virtual object ResultHandle(IAOPResult aop, Type returnType, ISerializer serializer) { #if DEBUG LogService.WriteLog(this, LogLevel.DEBUG, aop.ToString()); #endif object returnValue = null; if (typeof(IAOPResult).IsAssignableFrom(returnType)) { returnValue = aop; if (returnType.IsGenericType && aop.IsUnSuccess()) //要求返回的是泛型,并且返回失败 { var aopType = aop.GetType(); if (!aopType.IsGenericType) //实际获取到的不是泛型,需要转换 { var rt = typeof(AOPResult <>).MakeGenericType(returnType.GetGenericArguments()); var instance = (AOPResult)TypeHelper.CreateObject(rt, null, false); instance.ResultNo = aop.ResultNo; instance.ResultDescription = aop.ResultDescription; returnValue = instance; } } } else if (aop.IsSuccess()) { if (returnType != typeof(void)) { if (aop.ResultAttachObject != null) { returnValue = returnType.IsInstanceOfType(aop.ResultAttachObject) ? aop.ResultAttachObject : serializer.Convert(aop.ResultAttachObject, returnType, null); } } } else { throw new RemotingException(aop.ResultNo, aop.ResultDescription); } return(returnValue); }
/// <summary> /// 把<see cref="IAOPResult"/>接口转换成类实例<see cref="AOPResult"/> /// </summary> /// <param name="aop"><see cref="IAOPResult"/>接口实例</param> /// <returns><see cref="AOPResult"/>实例</returns> public static AOPResult ToAOPResult(this IAOPResult aop) { return(aop.ToAOPResult(null)); }
/// <summary> /// 处理结果是否失败(ResultNo != 0 ) /// </summary> public static bool IsUnSuccess(this IAOPResult aop) { return(aop.ResultNo != 0); }
/// <summary> /// 构造函数 /// </summary> /// <param name="resultNo">返回代码</param> /// <param name="resultDescription">对应的描述信息</param> /// <param name="resultAttachObject">相应的附加信息</param> /// <param name="innerAOPResult">内部AOPResult</param> public AOPResult(int resultNo, string resultDescription, object resultAttachObject = null, IAOPResult innerAOPResult = null) { this.ResultNo = resultNo; this.ResultDescription = resultDescription; this.ResultAttachObject = resultAttachObject; this.InnerAOPResult = innerAOPResult; }
public static object ToLite <T>(this IAOPResult <T> aop, Func <T, object> resultHandler) { return(new { aop.ResultNo, aop.ResultDescription, ResultAttachObject = resultHandler != null && aop.ResultAttachObject != null?resultHandler(aop.ResultAttachObjectEx) : aop.ResultAttachObjectEx }); }
/// <summary> /// 把<c>IAOPResult<Q></c>转换成<c>IAOPResult<P></c>,其中<typeparamref name="Q"/>从<typeparamref name="P"/>派生 /// </summary> /// <typeparam name="Q">附加的泛型</typeparam> /// <typeparam name="P">附加的泛型</typeparam> /// <param name="result">待转换的<c>IAOPResult<T></c></param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <P> CovertTo <Q, P>(this IAOPResult <Q> result) where Q : P { return(AOPResult.Create <P>(result.ResultNo, result.ResultDescription, result.ResultAttachObjectEx, result, result.GetResultData())); }
/// <summary> /// 把<c>IAOPResult<Q></c>转换成<c>IAOPResult<P></c> /// </summary> /// <typeparam name="Q">附加的泛型</typeparam> /// <typeparam name="P">附加的泛型</typeparam> /// <param name="result">待转换的<c>IAOPResult<T></c></param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <P> ToAOPResult <Q, P>(this IAOPResult <Q> result) { return(AOPResult.Create(result.ResultNo, result.ResultDescription, default(P), result, result.GetResultData())); }
/// <summary> /// 如果处理失败,则抛出异常 <see cref="ExceptionBase"/> /// </summary> /// <returns>返回本身</returns> public static IAOPResult <T> ThrowErrorOnFailed <T>(this IAOPResult <T> aop) { ((IAOPResult)aop).ThrowErrorOnFailed(); return(aop); }
/// <summary> /// 处理结果是否失败(ResultNo < 0 ) /// </summary> public static bool IsFailed(this IAOPResult aop) { return(aop.ResultNo < 0); }
protected override object ResultHandle(IAOPResult aop, Type returnType, ISerializer serializer) { return(ElapseTime("ResponseHandle`3", () => base.ResultHandle(aop, returnType, serializer))); }
/// <summary> /// 创建<see cref="IAOPResult{T}"/>实例 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="resultNo">返回代码</param> /// <param name="resultDescription">描述信息</param> /// <param name="attachObject">附加信息</param> /// <param name="innerAOPResult">内部AOPResult</param> /// <param name="resultData">传递的其他信息集合(上下文)</param> /// <returns><see cref="IAOPResult{T}"/>实例</returns> public static IAOPResult <T> Create <T>(int resultNo, string resultDescription, T attachObject, IAOPResult innerAOPResult = null, IDictionary resultData = null) { return(new AOPResult <T>(resultNo, resultDescription, attachObject, ToAOPResult(innerAOPResult, null)) { ResultData = resultData }); }
/// <summary> /// 已处理,但有不致命的错误(ResultNo > 0) /// </summary> public static bool IsPassedButFailed(this IAOPResult aop) { return(aop.ResultNo > 0); }
public void OnResultHandling(ProxyContext ctx, IAOPResult result) { this.ResultHandling?.Invoke(ctx, result); }
/// <summary> /// 创建<see cref="IAOPResult{T}"/>实例 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="resultNo">返回代码</param> /// <param name="resultDescription">描述信息</param> /// <param name="attachObject">附加信息</param> /// <param name="innerAOPResult">内部AOPResult</param> /// <returns><see cref="IAOPResult{T}"/>实例</returns> public static IAOPResult <T> Create <T>(int resultNo, string resultDescription, T attachObject, IAOPResult innerAOPResult) { return(new AOPResult <T>(resultNo, resultDescription, attachObject, ToAOPResult(innerAOPResult, null))); }