コード例 #1
0
        /// <summary>
        /// 当动作执行中
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            CurUser = GetCurrentUser(this.HttpContext);

            // 判断是否检查登陆
            bool allowAnonymous = false;

            if (filterContext.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
            {
                allowAnonymous = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
                                 .Any(a => a.GetType().Equals(typeof(AllowAnonymousAttribute)));
            }
            if (!allowAnonymous)
            {
                string area       = filterContext.RouteData.Values["area"].ToString();
                string controller = filterContext.RouteData.Values["controller"].ToString();
                string action     = filterContext.RouteData.Values["action"].ToString();

                if (CurUser == null)
                {
                    Robj <bool> robj = new Robj <bool>();
                    robj.Code            = RCode.NeedLogin;
                    robj.Message         = "尚未登录或登录已超时,请重新登录.";
                    filterContext.Result = new ContentResult()
                    {
                        Content = JsonHelper.ObjToJson(robj)
                    };
                }
                else
                {
                    base.OnActionExecuting(filterContext);
                }
            }
            else
            {
                base.OnActionExecuting(filterContext);
            }
        }
コード例 #2
0
        /// <summary>
        /// Action执行完成,返回结果处理
        /// </summary>
        /// <param name="actionExecutedContext"></param>
        public override void OnActionExecuted(ActionExecutedContext actionExecutedContext)
        {
            ControllerActionDescriptor actionDescriptor = actionExecutedContext.ActionDescriptor as ControllerActionDescriptor;

            object[] noPackageList = actionDescriptor.MethodInfo.GetCustomAttributes(typeof(NoPackageResultAttribute), false);
            if (noPackageList.Any())
            {
                base.OnActionExecuted(actionExecutedContext);
                return;
            }
            if (actionExecutedContext.Exception == null)
            {   //执行成功 取得由 API 返回的资料
                ObjectResult result = actionExecutedContext.Result as ObjectResult;
                if (result != null)
                {   // 重新封装回传格式
                    Robj <object> robj = new Robj <object>();
                    robj.Success(result.Value);
                    ObjectResult objectResult = new ObjectResult(robj);
                    actionExecutedContext.Result = objectResult;
                }
            }
            base.OnActionExecuted(actionExecutedContext);
        }
コード例 #3
0
        public IActionResult GetTsModel([FromForm] string itemId, [FromForm] string itemType)
        {
            Robj <TsResultModel> robj = new Robj <TsResultModel>();

            try
            {
                if (string.IsNullOrEmpty(itemId))
                {
                    throw new Exception("参数typeId不能为空");
                }
                if (string.IsNullOrEmpty(itemType))
                {
                    throw new Exception("参数itemType不能为空");
                }
                TsCreator     creator  = new TsCreator();
                TsResultModel tsResult = creator.GetTsResultModel(itemId, itemType);
                robj.Result = tsResult;
            }
            catch (Exception ex)
            {
                robj.Error(ex.Message);
            }
            return(new JsonResult(robj));
        }
コード例 #4
0
        /// <summary>
        /// 当动作执行中
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // 判断是否检查登陆
            bool allowAnonymous = false;

            if (filterContext.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
            {
                allowAnonymous = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
                                 .Any(a => a.GetType().Equals(typeof(AllowAnonymousAttribute)));
            }
            if (!allowAnonymous)
            {
                Robj <bool> robj        = new Robj <bool>();
                HttpContext httpContext = filterContext.HttpContext;
                string      token       = "";
                if (httpContext.Request.Headers.Keys.Select(k => k.ToLower()).Contains(Consts.Sys_TokenKey))
                {
                    token = httpContext.Request.Headers[Consts.Sys_TokenKey];
                }
                if (string.IsNullOrEmpty(token))
                {   //尝试自链接中获取token 以便get请求
                    if (filterContext.HttpContext.Request.Query.Keys.Contains(Consts.Sys_TokenKey))
                    {
                        token = filterContext.HttpContext.Request.Query[Consts.Sys_TokenKey];
                    }
                }
                if (string.IsNullOrEmpty(token))
                {   //尝试自表单数据中获取token
                    if (!string.IsNullOrEmpty(filterContext.HttpContext.Request.ContentType) &&
                        filterContext.HttpContext.Request.ContentType.ToLower() == "application/x-www-form-urlencoded" &&
                        filterContext.HttpContext.Request.Form.Keys.Contains(Consts.Sys_TokenKey))
                    {
                        token = filterContext.HttpContext.Request.Form[Consts.Sys_TokenKey];
                    }
                }

                RCode  rcode      = RCode.Exception;
                string controller = filterContext.RouteData.Values["controller"].ToString();
                string action     = filterContext.RouteData.Values["action"].ToString();
                try
                {
                    if (string.IsNullOrEmpty(token))
                    {                                         //开发使用
                        rcode = RCode.NeedLogin;
                        throw new Exception("你尚未登录系统,请先登录."); //未登录系统抛出异常
                    }
                    else
                    {
                        //UserDto user = CacheHelper.Get<UserDto>(token);
                        //if (user == null)
                        //{
                        //    rcode = RCode.NeedLogin;
                        //    throw new Exception("登录无效或登录已超时,请重新登录.");
                        //}
                    }
                    base.OnActionExecuting(filterContext);
                }
                catch (Exception ex)
                {
                    robj.Code            = rcode;
                    robj.Message         = ex.Message;
                    filterContext.Result = new ContentResult()
                    {
                        Content = JsonHelper.ObjToJson(robj)
                    };
                }
            }
            else
            {
                base.OnActionExecuting(filterContext);
            }
        }
コード例 #5
0
    private void Update()
    {
        PassengerSection  = GameObject.FindGameObjectsWithTag("Passenger");
        DriverSection     = GameObject.FindGameObjectsWithTag("Driver");
        MoneySection      = GameObject.FindGameObjectsWithTag("Money");
        ReputationSection = GameObject.FindGameObjectsWithTag("Reputation");

        switch (btn)
        {
        case 1:
        {
            foreach (GameObject Dobj in DriverSection)
            {
                if (Dobj.GetComponent <Text>() != null)
                {
                    Dobj.GetComponent <Text>().enabled = true;
                }
                if (Dobj.GetComponent <InputField>() != null)
                {
                    Dobj.GetComponent <InputField>().enabled = true;
                }
                if (Dobj.GetComponent <Image>() != null)
                {
                    Dobj.GetComponent <Image>().enabled = true;
                }
            }

            foreach (GameObject Pobj in PassengerSection)
            {
                if (Pobj.GetComponent <Text>() != null)
                {
                    Pobj.GetComponent <Text>().enabled = false;
                }
                if (Pobj.GetComponent <InputField>() != null)
                {
                    Pobj.GetComponent <InputField>().enabled = false;
                }
                if (Pobj.GetComponent <Image>() != null)
                {
                    Pobj.GetComponent <Image>().enabled = false;
                }
            }

            foreach (GameObject Robj in ReputationSection)
            {
                if (Robj.GetComponent <Text>() != null)
                {
                    Robj.GetComponent <Text>().enabled = false;
                }
                if (Robj.GetComponent <InputField>() != null)
                {
                    Robj.GetComponent <InputField>().enabled = false;
                }
                if (Robj.GetComponent <Image>() != null)
                {
                    Robj.GetComponent <Image>().enabled = false;
                }
            }

            foreach (GameObject Mobj in MoneySection)
            {
                if (Mobj.GetComponent <Text>() != null)
                {
                    Mobj.GetComponent <Text>().enabled = false;
                }
                if (Mobj.GetComponent <InputField>() != null)
                {
                    Mobj.GetComponent <InputField>().enabled = false;
                }
                if (Mobj.GetComponent <Image>() != null)
                {
                    Mobj.GetComponent <Image>().enabled = false;
                }
            }
            break;
        }

        case 2:
        {
            foreach (GameObject Robj in ReputationSection)
            {
                if (Robj.GetComponent <Text>() != null)
                {
                    Robj.GetComponent <Text>().enabled = false;
                }
                if (Robj.GetComponent <InputField>() != null)
                {
                    Robj.GetComponent <InputField>().enabled = false;
                }
                if (Robj.GetComponent <Image>() != null)
                {
                    Robj.GetComponent <Image>().enabled = false;
                }
            }
            foreach (GameObject _Dobj in DriverSection)
            {
                if (_Dobj.GetComponent <Text>() != null)
                {
                    _Dobj.GetComponent <Text>().enabled = false;
                }
                if (_Dobj.GetComponent <InputField>() != null)
                {
                    _Dobj.GetComponent <InputField>().enabled = false;
                }
                if (_Dobj.GetComponent <Image>() != null)
                {
                    _Dobj.GetComponent <Image>().enabled = false;
                }
            }

            foreach (GameObject _Pobj in PassengerSection)
            {
                if (_Pobj.GetComponent <Text>() != null)
                {
                    _Pobj.GetComponent <Text>().enabled = true;
                }
                if (_Pobj.GetComponent <InputField>() != null)
                {
                    _Pobj.GetComponent <InputField>().enabled = true;
                }
                if (_Pobj.GetComponent <Image>() != null)
                {
                    _Pobj.GetComponent <Image>().enabled = true;
                }
            }

            foreach (GameObject Mobj in MoneySection)
            {
                if (Mobj.GetComponent <Text>() != null)
                {
                    Mobj.GetComponent <Text>().enabled = false;
                }
                if (Mobj.GetComponent <InputField>() != null)
                {
                    Mobj.GetComponent <InputField>().enabled = false;
                }
                if (Mobj.GetComponent <Image>() != null)
                {
                    Mobj.GetComponent <Image>().enabled = false;
                }
            }
            break;
        }

        case 3:
        {
            foreach (GameObject Robj in ReputationSection)
            {
                if (Robj.GetComponent <Text>() != null)
                {
                    Robj.GetComponent <Text>().enabled = false;
                }
                if (Robj.GetComponent <InputField>() != null)
                {
                    Robj.GetComponent <InputField>().enabled = false;
                }
                if (Robj.GetComponent <Image>() != null)
                {
                    Robj.GetComponent <Image>().enabled = false;
                }
            }

            foreach (GameObject _Dobj in DriverSection)
            {
                if (_Dobj.GetComponent <Text>() != null)
                {
                    _Dobj.GetComponent <Text>().enabled = false;
                }
                if (_Dobj.GetComponent <InputField>() != null)
                {
                    _Dobj.GetComponent <InputField>().enabled = false;
                }
                if (_Dobj.GetComponent <Image>() != null)
                {
                    _Dobj.GetComponent <Image>().enabled = false;
                }
            }

            foreach (GameObject _Pobj in PassengerSection)
            {
                if (_Pobj.GetComponent <Text>() != null)
                {
                    _Pobj.GetComponent <Text>().enabled = false;
                }
                if (_Pobj.GetComponent <InputField>() != null)
                {
                    _Pobj.GetComponent <InputField>().enabled = false;
                }
                if (_Pobj.GetComponent <Image>() != null)
                {
                    _Pobj.GetComponent <Image>().enabled = false;
                }
            }
            foreach (GameObject Mobj in MoneySection)
            {
                if (Mobj.GetComponent <Text>() != null)
                {
                    Mobj.GetComponent <Text>().enabled = true;
                }
                if (Mobj.GetComponent <InputField>() != null)
                {
                    Mobj.GetComponent <InputField>().enabled = true;
                }
                if (Mobj.GetComponent <Image>() != null)
                {
                    Mobj.GetComponent <Image>().enabled = true;
                }
            }
            break;
        }

        case 4:
        {
            foreach (GameObject Robj in ReputationSection)
            {
                if (Robj.GetComponent <Text>() != null)
                {
                    Robj.GetComponent <Text>().enabled = true;
                }
                if (Robj.GetComponent <InputField>() != null)
                {
                    Robj.GetComponent <InputField>().enabled = true;
                }
                if (Robj.GetComponent <Image>() != null)
                {
                    Robj.GetComponent <Image>().enabled = true;
                }
            }

            foreach (GameObject _Dobj in DriverSection)
            {
                if (_Dobj.GetComponent <Text>() != null)
                {
                    _Dobj.GetComponent <Text>().enabled = false;
                }
                if (_Dobj.GetComponent <InputField>() != null)
                {
                    _Dobj.GetComponent <InputField>().enabled = false;
                }
                if (_Dobj.GetComponent <Image>() != null)
                {
                    _Dobj.GetComponent <Image>().enabled = false;
                }
            }

            foreach (GameObject _Pobj in PassengerSection)
            {
                if (_Pobj.GetComponent <Text>() != null)
                {
                    _Pobj.GetComponent <Text>().enabled = false;
                }
                if (_Pobj.GetComponent <InputField>() != null)
                {
                    _Pobj.GetComponent <InputField>().enabled = false;
                }
                if (_Pobj.GetComponent <Image>() != null)
                {
                    _Pobj.GetComponent <Image>().enabled = false;
                }
            }
            foreach (GameObject Mobj in MoneySection)
            {
                if (Mobj.GetComponent <Text>() != null)
                {
                    Mobj.GetComponent <Text>().enabled = false;
                }
                if (Mobj.GetComponent <InputField>() != null)
                {
                    Mobj.GetComponent <InputField>().enabled = false;
                }
                if (Mobj.GetComponent <Image>() != null)
                {
                    Mobj.GetComponent <Image>().enabled = false;
                }
            }
            break;
        }
        }
    }