コード例 #1
0
ファイル: HttpRealProxy.cs プロジェクト: lanicon/devfx
        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);
        }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
 /// <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);
 }
コード例 #6
0
 /// <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);
 }
コード例 #7
0
 /// <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);
 }
コード例 #8
0
 /// <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);
 }
コード例 #9
0
 /// <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);
 }
コード例 #10
0
 /// <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);
 }
コード例 #11
0
 /// <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);
 }
コード例 #12
0
        /// <summary>
        /// 把<c>IAOPResult</c>转换成<c>IAOPResult&lt;T&gt;</c>
        /// </summary>
        /// <typeparam name="T">附加的泛型</typeparam>
        /// <param name="aop">待转换的<c>IAOPResult</c></param>
        /// <returns>转换后的<c>IAOPResult&lt;T&gt;</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()));
        }
コード例 #13
0
        /// <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));
        }
コード例 #14
0
        /// <summary>
        /// 把<c>IAOPResult</c>转换成<c>IAOPResult&lt;T&gt;</c>
        /// </summary>
        /// <typeparam name="T">附加的泛型</typeparam>
        /// <param name="aop">待转换的<c>IAOPResult</c></param>
        /// <param name="initializer">初始器</param>
        /// <returns>转换后的<c>IAOPResult&lt;T&gt;</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);
        }
コード例 #15
0
ファイル: PermissionsController.cs プロジェクト: mer2/octopus
        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 }));
        }
コード例 #16
0
ファイル: EventClientService.cs プロジェクト: mer2/octopus
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
 /// <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));
 }
コード例 #19
0
 /// <summary>
 /// 处理结果是否失败(ResultNo != 0 )
 /// </summary>
 public static bool IsUnSuccess(this IAOPResult aop)
 {
     return(aop.ResultNo != 0);
 }
コード例 #20
0
ファイル: AOPResult.cs プロジェクト: lanicon/devfx
 /// <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;
 }
コード例 #21
0
 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 });
 }
コード例 #22
0
 /// <summary>
 /// 把<c>IAOPResult&lt;Q&gt;</c>转换成<c>IAOPResult&lt;P&gt;</c>,其中<typeparamref name="Q"/>从<typeparamref name="P"/>派生
 /// </summary>
 /// <typeparam name="Q">附加的泛型</typeparam>
 /// <typeparam name="P">附加的泛型</typeparam>
 /// <param name="result">待转换的<c>IAOPResult&lt;T&gt;</c></param>
 /// <returns>转换后的<c>IAOPResult&lt;T&gt;</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()));
 }
コード例 #23
0
 /// <summary>
 /// 把<c>IAOPResult&lt;Q&gt;</c>转换成<c>IAOPResult&lt;P&gt;</c>
 /// </summary>
 /// <typeparam name="Q">附加的泛型</typeparam>
 /// <typeparam name="P">附加的泛型</typeparam>
 /// <param name="result">待转换的<c>IAOPResult&lt;T&gt;</c></param>
 /// <returns>转换后的<c>IAOPResult&lt;T&gt;</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()));
 }
コード例 #24
0
 /// <summary>
 /// 如果处理失败,则抛出异常 <see cref="ExceptionBase"/>
 /// </summary>
 /// <returns>返回本身</returns>
 public static IAOPResult <T> ThrowErrorOnFailed <T>(this IAOPResult <T> aop)
 {
     ((IAOPResult)aop).ThrowErrorOnFailed();
     return(aop);
 }
コード例 #25
0
 /// <summary>
 /// 处理结果是否失败(ResultNo &lt; 0 )
 /// </summary>
 public static bool IsFailed(this IAOPResult aop)
 {
     return(aop.ResultNo < 0);
 }
コード例 #26
0
 protected override object ResultHandle(IAOPResult aop, Type returnType, ISerializer serializer)
 {
     return(ElapseTime("ResponseHandle`3", () => base.ResultHandle(aop, returnType, serializer)));
 }
コード例 #27
0
 /// <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
     });
 }
コード例 #28
0
 /// <summary>
 /// 已处理,但有不致命的错误(ResultNo &gt; 0)
 /// </summary>
 public static bool IsPassedButFailed(this IAOPResult aop)
 {
     return(aop.ResultNo > 0);
 }
コード例 #29
0
ファイル: HttpRealProxyFactory.cs プロジェクト: mer2/octopus
 public void OnResultHandling(ProxyContext ctx, IAOPResult result)
 {
     this.ResultHandling?.Invoke(ctx, result);
 }
コード例 #30
0
 /// <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)));
 }