Esempio n. 1
0
        /// <summary>
        ///     Gets the single user.
        ///     动态获取获取所有的活动
        /// </summary>
        /// <returns>dynamic.</returns>
        public static IEnumerable <Type> GetAllAutoConfig()
        {
            var service = DynamicService.Resolve("AutoConfig");
            var target  = new Interpreter().SetVariable("service", service);
            var result  = target.Eval("service.GetAllTypes()");

            return((IEnumerable <Type>)result);
        }
Esempio n. 2
0
        /// <summary>
        ///     动态获取店铺
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static dynamic GetStore(long userId)
        {
            var orderService = DynamicService.Resolve("Store");
            var target       = new Interpreter().SetVariable("storeService", orderService);
            var parameters   = new[]
            {
                new Parameter("userId", userId)
            };
            var user = (dynamic)target.Eval("storeService.GetUserStore(userId)", parameters);

            return(user);
        }
Esempio n. 3
0
        /// <summary>
        ///     Gets the single user.
        ///     动态获取订单
        /// </summary>
        /// <param name="orderId">Name of the user.</param>
        /// <returns>dynamic.</returns>
        public static dynamic GetSingleOrder(long orderId)
        {
            var orderService = DynamicService.Resolve("Order");
            var target       = new Interpreter().SetVariable("orderService", orderService);
            var parameters   = new[]
            {
                new Parameter("orderId", orderId)
            };
            var user = (dynamic)target.Eval("orderService.GetSingle(orderId)", parameters);

            return(user);
        }
Esempio n. 4
0
        /// <summary>
        ///     Gets the single user.
        ///     动态增加用户的库存
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns>dynamic.</returns>
        public static dynamic UpdateUserStock(long orderId)
        {
            var service    = DynamicService.Resolve("UserStock");
            var target     = new Interpreter().SetVariable("userStockService", service);
            var parameters = new[]
            {
                new Parameter("orderId", orderId)
            };
            var user = (dynamic)target.Eval("userStockService.UpdateUserStock(orderId)", parameters);

            return(user);
        }
Esempio n. 5
0
        /// <summary>
        ///     Gets the single trade.
        ///     动态获取trade
        /// </summary>
        /// <param name="tradeId">Name of the trade.</param>
        /// <returns>dynamic.</returns>
        public static dynamic GetSingleTrade(long tradeId)
        {
            var tradeService = DynamicService.Resolve("Trade");
            var target       = new Interpreter().SetVariable("tradeService", tradeService);
            var parameters   = new[]
            {
                new Parameter("tradeId", tradeId)
            };
            var trade = (dynamic)target.Eval("tradeService.GetSingle(tradeId)", parameters);

            return(trade);
        }
Esempio n. 6
0
        /// <summary>
        ///     Gets the users by identifier.
        ///     动态获取用户列表
        /// </summary>
        /// <param name="userIds">The user ids.</param>
        /// <returns>IEnumerable&lt;System.Object&gt;.</returns>
        public static IEnumerable <object> GetUserListByIds(IEnumerable <long> userIds)
        {
            var userService = DynamicService.Resolve("User");

            var target     = new Interpreter().SetVariable("userService", userService);
            var parameters = new[]
            {
                new Parameter("userIds", userIds)
            };
            var users = (IEnumerable <object>)target.Eval("userService.GetList(userIds)", parameters);

            return(users);
        }
Esempio n. 7
0
        /// <summary>
        ///     动态调用无参数方法
        /// </summary>
        /// <param name="service">服务名称,区分大小写:比如UserService,TypeService</param>
        /// <param name="method">无参数方法名称:</param>
        /// <returns></returns>
        public static void Eval(string service, string method)
        {
            var serviceResolve = DynamicService.Resolve(service);

            if (serviceResolve == null)
            {
                throw new ValidException("服务类型输入错误,未找到");
            }
            var target     = new Interpreter().SetVariable("entityService", serviceResolve);
            var evalString = $"entityService.{method}()";

            target.Eval(evalString);
        }
Esempio n. 8
0
        /// <summary>
        ///     Determines whether the specified 会员 identifier is admin.
        ///     是否是员工
        /// </summary>
        /// <param name="userId">会员Id</param>
        public static dynamic IsAdmin(long userId)
        {
            var userService = DynamicService.Resolve("User");

            ;
            var target     = new Interpreter().SetVariable("userService", userService);
            var parameters = new[]
            {
                new Parameter("userId", userId)
            };
            var user = (dynamic)target.Eval("userService.IsAdmin(userId)", parameters);

            return(user);
        }
Esempio n. 9
0
        /// <summary>
        ///     Gets the single user.
        ///     动态获取用户
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <returns>dynamic.</returns>
        public static dynamic GetSingleUser(string userName)
        {
            var objectCache = Ioc.Resolve <IObjectCache>();

            return(objectCache.GetOrSet(() => {
                var userService = DynamicService.Resolve("User");

                var target = new Interpreter().SetVariable("userService", userService);
                var parameters = new[]
                {
                    new Parameter("userName", userName)
                };
                var user = (dynamic)target.Eval("userService.GetSingle(userName)", parameters);
                return user;
            }, "dynamic_GetSingleUser" + userName, TimeSpan.FromHours(1)).Value);
        }
Esempio n. 10
0
        /// <summary>
        /// 动态调用一个参数的方法
        /// </summary>
        /// <param name="service">服务名称,区分大小写:比如UserService,TypeService</param>
        /// <param name="method">方法名称:</param>
        /// <param name="parameter">参数</param>
        /// <returns></returns>
        public static void Eval(string service, string method, object parameter)
        {
            var serviceResolve = DynamicService.Resolve(service);

            if (serviceResolve == null)
            {
                throw new ValidException("服务类型输入错误,未找到");
            }
            var parameters = new[]
            {
                new Parameter("parameter", parameter)
            };
            var target     = new Interpreter().SetVariable("entityService", serviceResolve);
            var evalString = $"entityService.{method}(parameter)";

            target.Eval(evalString, parameters);
        }
Esempio n. 11
0
        /// <summary>
        ///     Gets the user grade.
        ///     动态获取用户等级
        /// </summary>
        /// <param name="gradeId">The grade identifier.</param>
        /// <returns>dynamic.</returns>
        public static dynamic GetUserGrade(Guid gradeId)
        {
            if (gradeId.IsGuidNullOrEmpty())
            {
                return(null);
            }
            // 获取等级
            var gardeService = DynamicService.Resolve("GradeService");
            var gradeTarget  = new Interpreter().SetVariable("gardeService", gardeService);
            // 获取等级
            var parameters = new[]
            {
                new Parameter("gradeId", gradeId)
            };
            var gradeConfig = (dynamic)gradeTarget.Eval("gardeService.GetGrade(gradeId)", parameters);

            return(gradeConfig);
        }