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 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); }