Beispiel #1
0
        public ActionResult RelationDelete(int id)
        {
            var model  = this.PermissionServer.GetPermissionRelation(id);
            var result = !this.PermissionAllow(model.PermissionNo, "Admin.PermissionRelationDeleteAll", false) ? AOPResult.Failed("Access Denied") : this.PermissionServer.DeletePermissionRelation(id);

            return(this.Json(new { result.ResultNo, result.ResultDescription }));
        }
Beispiel #2
0
        public ActionResult RelationEdit(int id, PermissionRelation model)
        {
            var model0 = this.PermissionServer.GetPermissionRelation(id, true);

            model.ID = id;
            model.PermissionResource = model0.PermissionResource;

            var result = this.PermissionAllow(model0.PermissionNo, "Admin.PermissionRelationEditAll", false) ? this.PermissionServer.UpdatePermissionRelation(model) : AOPResult.Failed("Access Denied");

            this.ViewBag.Result = result;
            return(this.RelationEditInternal(id, model));
        }
Beispiel #3
0
 public ActionResult UserRoleCreate(UserGroupRole model)
 {
     model.TargetCategory = 2;
     this.ViewBag.Result  = this.RoleAllow("Admin.PermissionUserRoleCreateAll", model.TargetValue) ? this.PermissionServer.AddUserRole(model) : AOPResult.Failed("Access Denied");
     return(this.UserRoleCreateInternal(model));
 }
Beispiel #4
0
        public ActionResult RelationCreate(PermissionRelation model)
        {
            var allowed    = true;
            var permission = PermissionClientService.GetUserPermissions(model.PermissionNo).FirstOrDefault();

            if (permission == null || !permission.Grantable)              //当前用户没有此权限或不可转授,需要进一步判断
            {
                allowed = PermissionClientService.Authorize("Admin.PermissionRelationCreateAll", includeStack: false);
            }
            if (allowed)
            {
                //判断用户是否可对用户授权或对角色授权
                allowed = PermissionClientService.Authorize(model.TargetObject == 1 ? "Admin.PermissionRelationCreateForUser" : "Admin.PermissionRelationCreateForRole", includeStack: false);
            }

            this.ViewBag.Result = allowed ? this.PermissionServer.AddPermissionRelation(model) : AOPResult.Failed("Access Denied");
            return(this.RelationCreateInternal(model));
        }
Beispiel #5
0
 public IAOPResult <int> Test(int a)
 {
     return(AOPResult.Success(a + 1));
 }
Beispiel #6
0
 public IAOPResult <Entity> GetEntity()
 {
     return(AOPResult.Success(new Entity {
         Name = "Abc", Age = 100
     }));
 }
Beispiel #7
0
 public IAOPResult Welcome(string hello)
 {
     return(AOPResult.Success("中文:" + hello));
 }
Beispiel #8
0
 protected override void OnException(ExceptionContext filterContext)
 {
     filterContext.Result           = this.ResultHandle(AOPResult.Failed(filterContext.Exception.Message));
     filterContext.ExceptionHandled = true;
     base.OnException(filterContext);
 }
Beispiel #9
0
        public void ProcessRequest(ServiceContext ctx)
        {
            var httpContext = ctx.HttpContext;
            var methodName  = ctx.MethodName;           //优先获取Url里的方法名

            if (string.IsNullOrEmpty(methodName))       //尝试从请求header里获取方法名
            {
                methodName = httpContext.Request.Headers["$action"];
            }
            var valueProvider = ctx.ValueProvider;

            if (string.IsNullOrEmpty(methodName))             //尝试从请求体里获取方法名
            {
                var vpResult = valueProvider.GetValue("$action");
                methodName = vpResult?.ConvertTo <string>();
            }
            //保存到字典里供外部使用
            ctx.MethodName = methodName;

            this.ServiceFactory.OnRequest(ctx);
            if (ctx.ResultInitialized)
            {
                this.ResultHandle(ctx);
                return;
            }

            methodName = ctx.MethodName;
            var method = ctx.CallMethod;

            if (method == null)
            {
                if (string.IsNullOrEmpty(methodName))
                {
                    this.ResultHandle(ctx, AOPResult.Failed(-500, "method missing"));
                    return;
                }
                if (!this.Methods.ContainsKey(methodName))
                {
                    var vpResult       = valueProvider.GetValue("$method");
                    var methodFullName = vpResult?.ConvertTo <string>();
                    if (!string.IsNullOrEmpty(methodFullName) && this.FullNameMethods.ContainsKey(methodFullName))
                    {
                        method = this.FullNameMethods[methodFullName];
                    }
                }
                else
                {
                    method = this.Methods[methodName];
                }
                ctx.CallMethod = method;
            }
            if (method == null)
            {
                this.ResultHandle(ctx, AOPResult.Failed(-500, "method not found:" + methodName));
                return;
            }

            var setting         = ctx.Setting;
            var serviceInstance = ctx.ObjectInstance;

            if (serviceInstance == null)
            {
                var serviceTypeName = setting.ServiceTypeName;
                ctx.ObjectInstance = serviceInstance = !string.IsNullOrEmpty(serviceTypeName) ? ObjectService.Current.GetOrCreateObject(serviceTypeName) : ObjectService.GetObject(setting.ContractType);
            }
            if (serviceInstance == null || !setting.ContractType.IsInstanceOfType(serviceInstance))
            {
                this.ResultHandle(ctx, AOPResult.Failed(-500, "serviceInstance error"));
                return;
            }
            var parameterValues = ctx.CallArguments;

            if (parameterValues == null)
            {
                var parameters = method.GetParameters();
                ctx.CallArguments = parameterValues = parameters.Select(parameter => this.ConvertTo(valueProvider.GetValue(parameter.Name), parameter.ParameterType)).ToArray();
            }
            this.ServiceFactory.OnCalling(ctx);
            if (!ctx.ResultInitialized)
            {
                TypeHelper.TryInvoke(serviceInstance, method, out var returnValue, true, parameterValues);
                ctx.ResultInitialized = true;
                ctx.ResultValue       = returnValue;
            }
            this.ServiceFactory.OnCalled(ctx);
            this.ResultHandle(ctx);
        }
Beispiel #10
0
 public IAOPResult PushToSubscribeQueue(string queueName, EventMessageHeader header)
 {
     this.Redis.LeftPush(this.RedisDb, this.SubscriberQueuePrefix + queueName, header.GetMessageKey());
     this.Redis.Increment(this.RedisDb, this.MessageRefPrefix + header.MessageGuid);
     return(AOPResult.Success());
 }
Beispiel #11
0
 /// <summary>
 /// 进行异常处理(由异常管理器调用)
 /// </summary>
 /// <param name="e">异常</param>
 /// <param name="level">异常等级(传递给日志记录器处理)</param>
 /// <returns>处理结果,将影响下面的处理器</returns>
 /// <remarks>
 /// 异常管理器将根据返回的结果进行下一步的处理,约定:<br />
 ///		返回的结果中,ResultNo值:
 ///		<list type="bullet">
 ///			<item><description>
 ///				小于0:表示处理异常,管理器将立即退出异常处理
 ///			</description></item>
 ///			<item><description>
 ///				0:处理正常
 ///			</description></item>
 ///			<item><description>
 ///				1:已处理,需要下一个异常处理器进一步处理,<br />
 ///				此时ResultAttachObject为返回的异常(可能与传入的异常是不一致的)
 ///			</description></item>
 ///			<item><description>
 ///				2:已处理,需要重新轮询异常处理器进行处理<br />
 ///					此时ResultAttachObject为返回的异常(可能与传入的异常是不一致的)<br />
 ///					此时异常管理器将重新进行异常处理
 ///			</description></item>
 ///		</list>
 /// </remarks>
 public virtual IAOPResult Handle(Exception e, int level)
 {
     this.LogService.WriteLog(this, level, this.GetFormattedString(e, level, null));
     return(AOPResult.Success());
 }