コード例 #1
0
        protected virtual Expression BuildExecuteCommand(CommandExpression command)
        {
            // parameterize query
            var expression = this.Parameterize(command);

            string commandText = this.linguist.Format(expression);
            ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(expression);
            QueryCommand qc = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType)));

            Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray();

            ProjectionExpression projection = ProjectionFinder.FindProjection(expression);

            if (projection != null)
            {
                return(this.ExecuteProjection(projection, false, qc, values));
            }

            Expression plan = Expression.Call(this.executor,
                                              "ExecuteCommand",
                                              null,
                                              Expression.Constant(qc),
                                              Expression.NewArrayInit(typeof(object), values));

            return(plan);
        }
コード例 #2
0
    public static CommandExpression Simplify(CommandExpression ce, bool removeSelectRowCount, AliasGenerator aliasGenerator)
    {
        if (removeSelectRowCount)
        {
            ce = (CommandExpression) new SelectRowRemover().Visit(ce);
        }

        return((CommandExpression) new CommandSimplifier(aliasGenerator).Visit(ce));
    }
コード例 #3
0
        /// <summary>
        /// Determines whether [is multiple commands] [the specified command].
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns>
        ///   <c>true</c> if [is multiple commands] [the specified command]; otherwise, <c>false</c>.
        /// </returns>
        protected virtual bool IsMultipleCommands(CommandExpression command)
        {
            if (command == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        protected virtual Expression BuildExecuteCommand(CommandExpression command)
        {
            // parameterize query
            var expression = this.Parameterize(command);

            var cdu = (command as CDUCommandExpression);

            string commandText = this.dbContext.BuildSql(expression);
            ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(expression);

            Expression[] values     = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray();
            var          parameters = namedValues.Select(v => new NamedParameter(v.Name, v.Type, v.SqlType)).ToArray();

            ProjectionExpression projection = ProjectionFinder.FindProjection(expression);

            if (projection != null)
            {
                return(this.ExecuteProjection(projection, false, commandText, parameters, values));
            }

            bool supportVersionCheck = false;
            var  delete = cdu as DeleteCommand;

            if (delete != null)
            {
                supportVersionCheck = delete.SupportsVersionCheck;
            }
            var update = cdu as UpdateCommand;

            if (update != null)
            {
                supportVersionCheck = update.SupportsVersionCheck;
            }

            var commandContext = Expression.New(
                MethodRepository.CommandContext.New,
                Expression.Constant(commandText),
                Expression.Constant(parameters),
                Expression.NewArrayInit(typeof(object), values),
                Expression.Constant(cdu.Table.Mapping.EntityType, Types.Type),
                Expression.Constant((OperationType)cdu.DbNodeType),
                Expression.Constant(supportVersionCheck),
                Expression.Constant(cdu.Instance))
            ;

            //Expression plan = Expression.Call(this.executor, "ExecuteNonQuery", new Type[] { (command as CDUCommandExpression).Table.Entity.EntityType },
            //    Expression.Constant(commandText),
            //     Expression.Constant(parameters),
            //    Expression.NewArrayInit(typeof(object), values)
            //    );

            Expression plan = Expression.Call(this.executor, "ExecuteNonQuery", null, commandContext);

            return(plan);
        }
コード例 #5
0
 protected override Expression VisitCommand(CommandExpression command)
 {
     if (this.Dialect.SupportMultipleCommands || !IsMultipleCommands(command))
     {
         return(this.BuildExecuteCommand(command));
     }
     else
     {
         return(base.VisitCommand(command));
     }
 }
コード例 #6
0
            protected override CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter)
            {
                var args = parameter as ReceivedEventArgs;

                if (args == null)
                {
                    throw new InvalidOperationException("Invalid execution parameter.");
                }

                return(new FtpCommandContext(this, expression, node.Command, (FtpServerChannel)args.Channel, (FtpStatement)args.ReceivedObject));
            }
コード例 #7
0
 protected override Expression VisitCommand(CommandExpression command)
 {
     if (this.linguist.Language.AllowsMultipleCommands || !this.IsMultipleCommands(command))
     {
         return(this.BuildExecuteCommand(command));
     }
     else
     {
         return(base.VisitCommand(command));
     }
 }
コード例 #8
0
        /// <summary>
        /// 构造调用 ExecuteScalar 方法的表达式。
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private Expression BuildExecuteScalarCommand(CommandExpression command)
        {
            var expression = Parameterize(command);
            var result     = translator(expression);

            var plan = Expression.Call(executor, MtlExecuteScalar,
                                       Expression.Constant((SqlCommand)result.QueryText),
                                       CreateParameterCollectionExpression(expression)
                                       );

            return(plan);
        }
コード例 #9
0
		public CommandExecutorContext(ICommandExecutor executor, CommandExpression expression, object parameter)
		{
			if(executor == null)
				throw new ArgumentNullException(nameof(executor));

			if(expression == null)
				throw new ArgumentNullException(nameof(expression));

			_executor = executor;
			_expression = expression;
			_parameter = parameter;
		}
コード例 #10
0
 public void TestCommandExpressionParseException()
 {
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("./"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("../"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("help/"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("/help/"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("./help/"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("../help/"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("queue.in/"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("/queue.in/"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("./queue.in/"));
     Assert.Throws <CommandExpressionException>(() => CommandExpression.Parse("../queue.in/"));
 }
コード例 #11
0
		public CommandContext(ICommandExecutor executor, CommandExpression expression, ICommand command, object parameter, IDictionary<string, object> extendedProperties = null)
		{
			if(command == null)
				throw new ArgumentNullException("command");

			_executor = executor;
			_command = command;
			_parameter = parameter;
			_expression = expression;

			if(extendedProperties != null && extendedProperties.Count > 0)
				_extendedProperties = new Dictionary<string, object>(extendedProperties, StringComparer.OrdinalIgnoreCase);
		}
コード例 #12
0
		public CommandContext(ICommandExecutor executor, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary<string, object> extendedProperties = null)
		{
			if(commandNode == null)
				throw new ArgumentNullException("commandNode");

			if(commandNode.Command == null)
				throw new ArgumentException(string.Format("The Command property of '{0}' command-node is null.", commandNode.FullPath));

			_executor = executor;
			_commandNode = commandNode;
			_command = commandNode.Command;
			_parameter = parameter;
			_expression = expression;

			if(extendedProperties != null && extendedProperties.Count > 0)
				_extendedProperties = new Dictionary<string, object>(extendedProperties, StringComparer.OrdinalIgnoreCase);
		}
コード例 #13
0
        protected virtual bool IsMultipleCommands(CommandExpression command)
        {
            if (command == null)
            {
                return(false);
            }
            switch ((DbExpressionType)command.NodeType)
            {
            case DbExpressionType.Insert:
            case DbExpressionType.Delete:
            case DbExpressionType.Update:
                return(false);

            default:
                return(true);
            }
        }
コード例 #14
0
ファイル: ChatController.cs プロジェクト: zamixn/PongRoyale
        public ChatController(RichTextBox output, TextBox input)
        {
            Output = output;
            Input  = input;

            BoldFont   = new Font(Output.Font, FontStyle.Bold);
            NormalFont = new Font(Output.Font, FontStyle.Regular);
            ItalicFont = new Font(Output.Font, FontStyle.Italic);

            NormalColor = Output.SelectionColor;
            ErrorColor  = Color.Red;
            InfoColor   = Color.FromArgb(50, 50, 50);

            RedVisitor    = new RedExpressionVisitor(output);
            BlueVisitor   = new BlueExpressionVisitor(output);
            GreenVisitor  = new GreenExpressionVisitor(output);
            YellowVisitor = new YellowExpressionVisitor(output);
            PurpleVisitor = new PurpleExpressionVisitor(output);

            FixFormatExpression textExpr = new FixFormatExpression(
                new AggregateExpression(new List <IChatExpression>()
            {
                new ReplaceExpression(":smile:", "😃"),
                new ReplaceExpression(":D", "😄"),
                new ReplaceExpression(":grinning:", "😁"),
                new ReplaceExpression(":anime:", "😆"),
                new ReplaceExpression(":embarrased", "😅"),
                new ReplaceExpression(":rofl:", "🤣"),
                new ReplaceExpression(":crying:", "😂"),
                new ReplaceExpression(":)", "🙂"),
                new ReplaceExpression("(:", "🙃"),
                new ReplaceExpression(":upsidesmile:", "🙃"),
                new ReplaceExpression(":wink:", "😉"),
                new ReplaceExpression(":blush:", "😊"),
                new ReplaceExpression(":halo:", "😇"),
            })
                );
            CommandExpression     cmdExpr = new CommandExpression();
            ChangeColorExpression clrExpr = new ChangeColorExpression();

            TextInterpreter = new ParserExpression(clrExpr, cmdExpr, textExpr);

            Originator = new ChatOriginator();
            Caretaker  = new ChatCaretaker();
        }
コード例 #15
0
    internal protected virtual R Insert <R>(IQueryable query, LambdaExpression constructor, ITable table, Func <SqlPreCommandSimple, R> continuation, bool removeSelectRowCount = false)
    {
        AliasGenerator aliasGenerator = new AliasGenerator();

        SqlPreCommandSimple cr;

        using (HeavyProfiler.Log("LINQ"))
            using (var log = HeavyProfiler.LogNoStackTrace("Clean"))
            {
                Expression cleaned = Clean(query.Expression, true, log) !;
                var        binder  = new QueryBinder(aliasGenerator);
                log.Switch("Bind");
                CommandExpression insert           = binder.BindInsert(cleaned, constructor, table);
                CommandExpression insertOprimized  = (CommandExpression)Optimize(insert, binder, aliasGenerator, log);
                CommandExpression insertSimplified = CommandSimplifier.Simplify(insertOprimized, removeSelectRowCount, aliasGenerator);
                log.Switch("TR");
                cr = TranslatorBuilder.BuildCommandResult(insertSimplified);
            }
        return(continuation(cr));
    }
コード例 #16
0
    internal protected virtual R Update <R>(IUpdateable updateable, Func <SqlPreCommandSimple, R> continuation, bool removeSelectRowCount = false)
    {
        AliasGenerator aliasGenerator = new AliasGenerator();

        SqlPreCommandSimple cr;

        using (HeavyProfiler.Log("LINQ"))
            using (var log = HeavyProfiler.LogNoStackTrace("Clean"))
            {
                Expression cleaned = Clean(updateable.Query.Expression, true, log) !;

                var binder = new QueryBinder(aliasGenerator);
                log.Switch("Bind");
                CommandExpression update           = binder.BindUpdate(cleaned, updateable.PartSelector, updateable.SetterExpressions);
                CommandExpression updateOptimized  = (CommandExpression)Optimize(update, binder, aliasGenerator, log);
                CommandExpression updateSimplified = CommandSimplifier.Simplify(updateOptimized, removeSelectRowCount, aliasGenerator);
                log.Switch("TR");
                cr = TranslatorBuilder.BuildCommandResult(updateSimplified);
            }
        return(continuation(cr));
    }
コード例 #17
0
        /// <summary>
        /// 构造调用 ExecuteNoQuery 方法的表达式。
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private Expression BuildExecuteNoQueryCommand(CommandExpression command)
        {
            var expression = Parameterize(command);
            var result     = _translator.Translate(expression);

            if (_isAsync)
            {
                _cancelToken = Expression.Parameter(typeof(CancellationToken), "token");
                return(Expression.Call(_executor, MethodCache.DbExecuteNoQueryAsync,
                                       Expression.Constant((SqlCommand)result.QueryText),
                                       CreateParameterCollectionExpression(expression),
                                       _cancelToken
                                       ));
            }
            else
            {
                return(Expression.Call(_executor, MethodCache.DbExecuteNoQuery,
                                       Expression.Constant((SqlCommand)result.QueryText),
                                       CreateParameterCollectionExpression(expression)
                                       ));
            }
        }
コード例 #18
0
        /// <summary>
        /// 构造调用 ExecuteScalar 方法的表达式。
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private Expression BuildExecuteScalarCommand(CommandExpression command)
        {
            var expression = Parameterize(command);
            var result     = translator(expression);


            if (isAsync)
            {
                cancelToken = Expression.Parameter(typeof(CancellationToken), "token");
                return(Expression.Call(executor, MtlExecuteScalarAsync.MakeGenericMethod(command.Type),
                                       Expression.Constant((SqlCommand)result.QueryText),
                                       CreateParameterCollectionExpression(expression),
                                       cancelToken
                                       ));
            }
            else
            {
                return(Expression.Call(executor, MtlExecuteScalar.MakeGenericMethod(command.Type),
                                       Expression.Constant((SqlCommand)result.QueryText),
                                       CreateParameterCollectionExpression(expression)
                                       ));
            }
        }
コード例 #19
0
        public void TestCommandExpressionParseWithPipeline()
        {
            CommandExpression expression;

            expression = CommandExpression.Parse("plugins.find '/Workbench'");

            Assert.Equal("find", expression.Name);
            Assert.Equal("plugins/", expression.Path);
            Assert.Equal("plugins/find", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);
            Assert.Equal(0, expression.Options.Count);
            Assert.Equal(1, expression.Arguments.Length);
            Assert.Equal("/Workbench", expression.Arguments[0]);

            expression = CommandExpression.Parse("sms.generate -template:'user.register' -authenticode:12345 phonenumber'1 phonenumber:2 phonenumber-3 'phonenumber|4' | queue.in sms");

            Assert.Equal("generate", expression.Name);
            Assert.Equal("sms/", expression.Path);
            Assert.Equal("sms/generate", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);
            Assert.Equal(2, expression.Options.Count);
            Assert.Equal(4, expression.Arguments.Length);
            Assert.Equal("user.register", expression.Options["template"]);
            Assert.Equal("12345", expression.Options["authenticode"]);
            Assert.Equal("phonenumber'1", expression.Arguments[0]);
            Assert.Equal("phonenumber:2", expression.Arguments[1]);
            Assert.Equal("phonenumber-3", expression.Arguments[2]);
            Assert.Equal("phonenumber|4", expression.Arguments[3]);

            Assert.NotNull(expression.Next);
            Assert.Equal("in", expression.Next.Name);
            Assert.Equal("queue/", expression.Next.Path);
            Assert.Equal("queue/in", expression.Next.FullPath);
            Assert.Equal(PathAnchor.None, expression.Next.Anchor);
            Assert.Equal("sms", expression.Next.Arguments[0]);
        }
コード例 #20
0
        /// <summary>
        /// 构造调用 ExecuteScalar 方法的表达式。
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private Expression BuildExecuteScalarCommand(CommandExpression command)
        {
            var expression = Parameterize(command);
            var result     = _translator.Translate(expression);

            if (_isAsync)
            {
                var method = ReflectionCache.GetMember("ExecuteScalarAsync", command.Type, k => MethodCache.DbExecuteScalarAsync.MakeGenericMethod(k));
                _cancelToken = Expression.Parameter(typeof(CancellationToken), "token");
                return(Expression.Call(_executor, method,
                                       Expression.Constant((SqlCommand)result.QueryText),
                                       CreateParameterCollectionExpression(expression),
                                       _cancelToken
                                       ));
            }
            else
            {
                var method = ReflectionCache.GetMember("ExecuteScalar", command.Type, k => MethodCache.DbExecuteScalar.MakeGenericMethod(k));
                return(Expression.Call(_executor, method,
                                       Expression.Constant((SqlCommand)result.QueryText),
                                       CreateParameterCollectionExpression(expression)
                                       ));
            }
        }
コード例 #21
0
 internal FtpCommandContext(ICommandExecutor executor, CommandExpression expression, ICommand command, FtpServerChannel channel, FtpStatement statement) : base(executor, expression, command, null, null)
 {
     _channel   = channel;
     _statement = statement;
 }
コード例 #22
0
ファイル: DbExpressionWriter.cs プロジェクト: nikhel/elinq
 protected virtual Expression VisitCommand(CommandExpression command)
 {
     this.Write(this.FormatQuery(command));
     return command;
 }
コード例 #23
0
			protected override CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter)
			{
				var args = parameter as ReceivedEventArgs;

				if(args == null)
					throw new InvalidOperationException("Invalid execution parameter.");

				return new FtpCommandContext(
						this,
						expression,
						node.Command,
						(FtpServerChannel)args.Channel,
						(FtpStatement)args.ReceivedObject);
			}
コード例 #24
0
 protected override CommandContext CreateCommandContext(CommandExecutorContext session, CommandExpression expression, CommandTreeNode node, object parameter)
 {
     return(new TerminalCommandContext(session, expression, node, parameter));
 }
コード例 #25
0
        public static void Main(string[] args)
        {
            if (args == null || args.Length < 1)
            {
                Console.WriteLine(ResourceUtility.GetString("Text.MissingArguments"));
                return;
            }

            try
            {
                //使用当前命令行参数构造一个命令表达式
                var expression = CommandExpression.Parse("deployer " + string.Join(" ", args));

                //创建一个部署文件路径的列表
                var paths = new List <string>(expression.Arguments.Length);

                //校验所有指定的文件路径是否都存在,并将处理后的路径加入到待处理的列表中
                foreach (var argument in expression.Arguments)
                {
                    var path = Path.IsPathRooted(argument) ? argument : Zongsoft.IO.Path.Combine(Environment.CurrentDirectory, argument);

                    if (File.Exists(path))
                    {
                        paths.Add(path);
                    }
                    else
                    {
                        throw new FileNotFoundException(path);
                    }
                }

                //创建部署器类的实例
                var deployer = new Deployer(Zongsoft.Terminals.ConsoleTerminal.Instance);

                //将命令行选项添加到部署器的环境变量中
                if (expression.Options.Count > 0)
                {
                    foreach (var option in expression.Options)
                    {
                        deployer.EnvironmentVariables[option.Key] = option.Value;
                    }
                }

                //依次部署指定的部署文件
                foreach (var path in paths)
                {
                    //部署指定的文件
                    var counter = deployer.Deploy(path);

                    //打印部署的结果信息
                    deployer.Terminal.WriteLine(CommandOutletColor.DarkGreen, ResourceUtility.GetString("Text.Deploy.CompleteInfo", path, counter.Total, counter.Successes, counter.Failures));
                }
            }
            catch (Exception ex)
            {
                //设置控制台前景色为“红色”
                var foregroundColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;

                //打印异常消息
                Console.Error.WriteLine(ex.Message);

                //重置控制台的前景色
                Console.ForegroundColor = foregroundColor;
            }
        }
コード例 #26
0
 public static CommandExpression Simplify(CommandExpression ce, bool removeSelectRowCount, AliasGenerator aliasGenerator)
 {
     return (CommandExpression)new CommandSimplifier { removeSelectRowCount = removeSelectRowCount, aliasGenerator = aliasGenerator }.Visit(ce);
 }
コード例 #27
0
 protected DynamicCommandExpression(CommandExpression caller, ExpressionFunction function)
     : base(caller, function)
 {
 }
コード例 #28
0
 protected DynamicCommandExpression(CommandExpression caller, string reference)
     : base(caller, reference)
 {
 }
コード例 #29
0
 protected DynamicCommandExpression(CommandExpression left, CommandExpression right, ExpressionOperator expressionOperator)
     : base(left, right, expressionOperator)
 {
 }
コード例 #30
0
 public TerminalCommandContext(CommandExecutorContext session, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary <string, object> extendedProperties = null) : base(session, expression, commandNode, parameter, extendedProperties)
 {
 }
コード例 #31
0
		protected virtual CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter)
		{
			return new CommandContext(this, expression, node, parameter);
		}
コード例 #32
0
 protected override Expression VisitCommand(CommandExpression command)
 {
     this.isTopLevel = true;
     return base.VisitCommand(command);
 }
コード例 #33
0
 protected virtual Expression VisitCommand(CommandExpression command)
 {
     switch ((DbExpressionType)command.NodeType)
     {
         case DbExpressionType.Insert:
             return this.VisitInsert((InsertCommand)command);
         case DbExpressionType.Update:
             return this.VisitUpdate((UpdateCommand)command);
         case DbExpressionType.Delete:
             return this.VisitDelete((DeleteCommand)command);
         case DbExpressionType.If:
             return this.VisitIf((IFCommand)command);
         case DbExpressionType.Block:
             return this.VisitBlock((BlockCommand)command);
         case DbExpressionType.Declaration:
             return this.VisitDeclaration((DeclarationCommand)command);
         default:
             return this.VisitUnknown(command);
     }
 }
コード例 #34
0
        public void TestCommandExpressionParse()
        {
            var expression = CommandExpression.Parse("");

            Assert.Null(expression);

            expression = CommandExpression.Parse("/");
            Assert.Equal("/", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal("/", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse(".");
            Assert.Equal(".", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal(".", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("..");
            Assert.Equal("..", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal("..", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal("send", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("/send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("/", expression.Path);
            Assert.Equal("/send", expression.FullPath);
            Assert.Equal(PathAnchor.Root, expression.Anchor);

            expression = CommandExpression.Parse("./send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("./", expression.Path);
            Assert.Equal("./send", expression.FullPath);
            Assert.Equal(PathAnchor.Current, expression.Anchor);

            expression = CommandExpression.Parse("../send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("../", expression.Path);
            Assert.Equal("../send", expression.FullPath);
            Assert.Equal(PathAnchor.Parent, expression.Anchor);

            expression = CommandExpression.Parse("sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("sms/", expression.Path);
            Assert.Equal("sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("/sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("/sms/", expression.Path);
            Assert.Equal("/sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.Root, expression.Anchor);

            expression = CommandExpression.Parse("./sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("./sms/", expression.Path);
            Assert.Equal("./sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.Current, expression.Anchor);

            expression = CommandExpression.Parse("../sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("../sms/", expression.Path);
            Assert.Equal("../sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.Parent, expression.Anchor);

            expression = CommandExpression.Parse("notification.send -name:Zongsoft.CRM -type:Message -mode:Alias -destination:User.100 -title:'task:create'");
            Assert.Equal("send", expression.Name);
            Assert.Equal(5, expression.Options.Count);
            Assert.Equal("Zongsoft.CRM", expression.Options["name"]);
            Assert.Equal("Message", expression.Options["type"]);
            Assert.Equal("Alias", expression.Options["mode"]);
            Assert.Equal("User.100", expression.Options["destination"]);
            Assert.Equal("task:create", expression.Options["title"]);
        }
コード例 #35
0
		public TerminalCommandContext(TerminalCommandExecutor executor, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary<string, object> extendedProperties = null) : base(executor, expression, commandNode, parameter, extendedProperties)
		{
		}
コード例 #36
0
 protected override Expression VisitCommand(CommandExpression command)
 {
     isTopLevel = true;
     return(base.VisitCommand(command));
 }
コード例 #37
0
		protected virtual object ExecuteCommand(CommandExecutorContext context, CommandExpression expression, CommandTreeNode node, object parameter)
		{
			if(context == null)
				throw new ArgumentNullException(nameof(context));

			if(node == null)
				throw new ArgumentNullException(nameof(node));

			if(node.Command == null)
				return null;

			return node.Command.Execute(this.CreateCommandContext(expression, node, parameter));
		}
コード例 #38
0
        public void TestCommandExpressionParse()
        {
            var expression = CommandExpression.Parse("");

            Assert.Null(expression);

            expression = CommandExpression.Parse("/");
            Assert.Equal("/", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal("/", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse(".");
            Assert.Equal(".", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal(".", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("..");
            Assert.Equal("..", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal("..", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("", expression.Path);
            Assert.Equal("send", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("/send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("/", expression.Path);
            Assert.Equal("/send", expression.FullPath);
            Assert.Equal(PathAnchor.Root, expression.Anchor);

            expression = CommandExpression.Parse("./send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("./", expression.Path);
            Assert.Equal("./send", expression.FullPath);
            Assert.Equal(PathAnchor.Current, expression.Anchor);

            expression = CommandExpression.Parse("../send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("../", expression.Path);
            Assert.Equal("../send", expression.FullPath);
            Assert.Equal(PathAnchor.Parent, expression.Anchor);

            expression = CommandExpression.Parse("sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("sms/", expression.Path);
            Assert.Equal("sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.None, expression.Anchor);

            expression = CommandExpression.Parse("/sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("/sms/", expression.Path);
            Assert.Equal("/sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.Root, expression.Anchor);

            expression = CommandExpression.Parse("./sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("./sms/", expression.Path);
            Assert.Equal("./sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.Current, expression.Anchor);

            expression = CommandExpression.Parse("../sms.send");
            Assert.Equal("send", expression.Name);
            Assert.Equal("../sms/", expression.Path);
            Assert.Equal("../sms/send", expression.FullPath);
            Assert.Equal(PathAnchor.Parent, expression.Anchor);
        }
コード例 #39
0
 public TerminalCommandContext(TerminalCommandExecutor executor, CommandExpression expression, ICommand command, object parameter, IDictionary <string, object> extendedProperties = null) : base(executor, expression, command, parameter, extendedProperties)
 {
 }