/// <summary>
        /// 构造函数
        /// </summary>
        public BaseWcfService()
        {
            var httpContext = HttpContext.Current;

            if (httpContext != null)
            {
                var args = httpContext.Request.Url.Segments;
                for (var i = 0; i < args.Length; i++)
                {
                    args[i] = ValidateUtility.CheckNull(args[i].Trim(new char[] { '/', '\\', ' ' })).ToString();
                }
                if (args.Length >= 8)
                {
                    SystemType = MCvHelper.To <SystemType>(args[3]);
                    Token      = MCvHelper.To <string>(args[4]);
                    Guid       = MCvHelper.To <string>(args[5]);
                    UserId     = MCvHelper.To <int>(args[6]);
                    Uid        = MCvHelper.To <string>(args[7]);
                }
                else
                {
                    MLogManager.Error(MLogGroup.WcfService.构造函数, "", "wcf 服务基类 构造函数初始化 ,uri参数错误");
                }
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        public object Invoke(IMethodInvocation invocation)
        {
            var    shopWatch       = new Stopwatch();
            object result          = null;
            var    enableMethodLog = MConfigManager.GetAppSettingsValue <bool>("EnableMethodLog", false);

            try
            {
                shopWatch.Start();

                var resultType = invocation.Method.ReturnType;

                //{sid}/{token}/{guid}/{user_id}/{uid}
                var args = invocation.Arguments;
                for (var i = 0; i < args.Length; i++)
                {
                    args[i] = ValidateUtility.CheckNull(args[i]);
                }
                if (args.Length >= 5)
                {
                    var sid    = MCvHelper.To <string>(args[0]);
                    var token  = MCvHelper.To <string>(args[1]);
                    var guid   = MCvHelper.To <string>(args[2]);
                    var userID = MCvHelper.To <int>(args[3]);
                    var uid    = MCvHelper.To <string>(args[4]);

                    var methodName      = invocation.Method.Name;
                    var methodCacheList = MCacheManager.GetCacheObj().GetValByKey <List <ItemMethodVerify> >("SystemPermission", MCaching.CacheGroup.Pemissions);

                    if (methodCacheList != null && methodCacheList.Any())
                    {
                        var methodCacheInfo = methodCacheList.Find(item => item.MethodName.Equals(methodName, StringComparison.InvariantCultureIgnoreCase));

                        if (methodCacheInfo != null)
                        {
                            var isVerifySystemId    = methodCacheInfo.IsVerifySystemId;
                            var isVerifyToKen       = methodCacheInfo.IsVerifyToken;
                            var isVerifyPermissions = methodCacheInfo.IsVerfiyPemissions;

                            var secureAuth = new SecureAuth
                            {
                                IsVerifySystemId    = isVerifySystemId,
                                IsVerifyToKen       = isVerifyToKen,
                                IsVerifyPermissions = isVerifyPermissions,
                                Sid    = sid,
                                Token  = token,
                                Uid    = uid,
                                UserId = userID
                            };

                            if (secureAuth.Verify().status == MResultStatus.Success)
                            {
                                if (methodCacheInfo.IsEnableCache)
                                {
                                    var cacheKey = string.Format("{0}_{1}", methodName,
                                                                 string.Join("_", invocation.Arguments));



                                    result = MCacheManager.UseCached <dynamic>(cacheKey, MCaching.CacheGroup.Pemissions,
                                                                               () => invocation.Method.Invoke(invocation.This, args));
                                }
                                else
                                {
                                    result = invocation.Method.Invoke(invocation.This, args);
                                }
                            }
                            //result = invocation.Proceed();
                        }
                        else
                        {
                            result = invocation.Method.Invoke(invocation.This, args);
                        }
                    }
                    else
                    {
                        result = invocation.Method.Invoke(invocation.This, args);
                    }
                }
                if (result == null)
                {
                    result = Activator.CreateInstance(resultType);
                }
                return(result);
            }
            catch (Exception ex)
            {
                MLogManager.Error(MLogGroup.AopAdvice.方法拦截, "", "", ex);
            }
            finally
            {
                if (result == null)
                {
                    var resultType = invocation.Method.ReturnType;
                    result = Activator.CreateInstance(resultType);
                }
                if (enableMethodLog)
                {
                    shopWatch.Stop();
                    MLogManager.Info(MLogGroup.AopAdvice.方法拦截, "", "执行用时:{0}毫秒;请求信息:{1};返回信息:{2};",
                                     shopWatch.ElapsedMilliseconds,
                                     invocation.ToString(),
                                     JsonConvert.SerializeObject(result));
                }
            }
            return(result);
        }