Example #1
0
        public PerformAction CreateAction(string userCommand, Version version, ConstructingContext context)
        {
            if (version == null)
            {
                throw new UnSpecifiedVersionException();
            }
            //命令不带参数的情况
            if (!userCommand.Contains(Constants.CommandParameterSpliter))
            {
                var title  = userCommand.Trim();
                var action = ActionResolver.ResolvePerform(title, version);
                //var action = TypeContainer.Resolve<PerformAction>(title,version);
                action.CommandText = userCommand;
                action.ActionName  = title;
                action.Parameters  = new List <string>();
                return(action);
            }
            else
            {
                var spliterIndex  = userCommand.IndexOf(Constants.CommandParameterSpliter);
                var title         = userCommand.Substring(0, spliterIndex).Trim();
                var parameterText = userCommand.Substring(spliterIndex + 1, userCommand.Length - spliterIndex - 1).Trim();
                var action        = ActionResolver.ResolvePerform(title, version);
                //var action = TypeContainer.Resolve<PerformAction>(title,version);
                action.CommandText = userCommand;
                action.ActionName  = title;
                action.Parameters  = parameterText.SplitAndTrim(Constants.ParameterSpliter).ToList().Translate(context.Bindings).Escape();
                return(action);
            }


            //使用这种方法是不行的。
            //var actionFullName = TypeContainer.Mapping[title].FullName;
            //var action = Assembly.GetExecutingAssembly().CreateInstance(actionFullName) as PerformAction;
        }
        public FunctionAction CreateAction(string userCommand, Version version, ConstructingContext context)
        {
            FunctionAction funcAction      = new FunctionAction();
            var            spliterIndex    = userCommand.IndexOf(Constants.CommandParameterSpliter);
            var            parameterText   = userCommand.Substring(spliterIndex + 1, userCommand.Length - spliterIndex - 1).Trim();
            string         funcName        = parameterText.Substring(0, parameterText.IndexOf("("));
            List <string>  actualParamList = parameterText.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)?.ToList();

            var           orderSetDic = FuncProcessor.Instance.Process(actualParamList, context.FunctionText);
            List <string> paramList   = orderSetDic.ContainsKey(funcName) ? orderSetDic[funcName] : new List <string>();
            var           instance    = PerformActionFactory.Instance;

            funcAction.ActionName  = funcName;
            funcAction.ActionName  = parameterText;
            funcAction.CommandText = parameterText;
            foreach (var param in paramList)
            {
                funcAction.BodyActions.Add(instance.CreateAction(param.Trim(), version, context));
            }

            return(funcAction);
        }
        public AssertAction CreateAction(string userCommand, Version version, ConstructingContext context)
        {
            if (version == null)
            {
                throw new UnSpecifiedVersionException();
            }

            if (!userCommand.StartsWith(Constants.Configs.AssertPrefix))
            {
                throw new Exception("invalid user assert command. Should be started with " + Constants.Configs.AssertPrefix);
            }
            var firstSpliterIndex = userCommand.IndexOf(Constants.CommandParameterSpliter);

            if (firstSpliterIndex < 0)
            {
                throw new InvalidCommandFormatException(userCommand);
            }
            userCommand = userCommand.Remove(0, firstSpliterIndex + 1).Trim();//删掉前缀(验证)和冒号

            var spliterIndex = userCommand.IndexOf(Constants.CommandParameterSpliter);

            if (spliterIndex < 0)
            {
                throw new InvalidCommandFormatException(userCommand);
            }
            var title         = userCommand.Substring(0, spliterIndex).Trim();                                         // 获取命令前缀  “表格列存在”
            var parameterText = userCommand.Substring(spliterIndex + 1, userCommand.Length - spliterIndex - 1).Trim(); // 参数

            var action = ActionResolver.ResolveAssert(title, version);

            //var action = TypeContainer.Resolve<AssertAction>(title, version); //如果实例化有问题,内部会抛出异常。不会返回null
            action.Parameters  = parameterText.SplitAndTrim(Constants.ParameterSpliter).ToList().Translate(context.Bindings).Escape();
            action.ActionName  = title;
            action.CommandText = userCommand;
            return(action);
        }