Ejemplo n.º 1
0
        protected override object OnExecute(CommandContext context)
        {
            var round  = (int)context.Expression.Options.GetValue <int>("round");
            var queues = QueueCommandHelper.GetQueues(context.CommandNode, context.Expression.Options.GetValue <string>("queues"));

            foreach (var queue in queues)
            {
                for (int i = 0; i < round; i++)
                {
                    var count = context.Parameter == null ? 0 : 1;

                    if (count > 0)
                    {
                        queue.Enqueue(context.Parameter);
                    }

                    count += this.ResolveValue(context, (value) =>
                    {
                        if (value != null)
                        {
                            queue.Enqueue(value);
                        }
                    });

                    context.Output.WriteLine(CommandOutletColor.DarkGreen, string.Format(ResourceUtility.GetString("Text.QueueInCommand.Message", i + 1, count, queue.Name)));
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        protected override object OnExecute(CommandContext context)
        {
            int count = context.Expression.Options.GetValue <int>("count");

            if (count < 1)
            {
                throw new CommandOptionValueException("count", count);
            }

            var queues = QueueCommandHelper.GetQueues(context.CommandNode, context.Expression.Options.GetValue <string>("queues"));
            var result = new List <object>(count * queues.Count);

            foreach (var queue in queues)
            {
                for (int i = 0; i < count; i++)
                {
                    var item = queue.Dequeue();

                    if (item == null)
                    {
                        continue;
                    }

                    result.Add(item);

                    context.Output.WriteLine(Serializer.Json.Serialize(item));
                    context.Output.WriteLine(CommandOutletColor.DarkGreen, string.Format(Properties.Resources.Text_QueueOutCommand_Message, i + 1, count, queue.Name));
                }
            }

            return(result.ToArray());
        }
Ejemplo n.º 3
0
        protected override object OnExecute(CommandContext context)
        {
            var queues = QueueCommandHelper.GetQueues(context.CommandNode, context.Expression.Options.GetValue <string>("queues"));

            foreach (var queue in queues)
            {
                queue.Clear();
            }

            //显示执行成功的信息
            context.Output.WriteLine(Properties.Resources.Text_CommandExecuteSucceed);

            return(null);
        }
Ejemplo n.º 4
0
        protected override object OnExecute(CommandContext context)
        {
            var count  = context.Expression.Options.GetValue <int>("count");
            int round  = context.Expression.Options.GetValue <int>("round");
            var result = new List <object>(count);

            if (count < 1)
            {
                throw new CommandOptionValueException("count", count);
            }

            if (round < 1)
            {
                throw new CommandOptionValueException("round", round);
            }

            var queues = QueueCommandHelper.GetQueues(context.CommandNode, context.Expression.Options.GetValue <string>("queues"));

            foreach (var queue in queues)
            {
                if (queue.Count == 0)
                {
                    context.Output.WriteLine(CommandOutletColor.DarkRed, ResourceUtility.GetString("Text.QueueIsEmpty", queue.Name));
                    continue;
                }

                for (int i = 0; i < round; i++)
                {
                    var items = queue.Dequeue(count);

                    if (items == null)
                    {
                        break;
                    }

                    foreach (var item in items)
                    {
                        result.Add(item);
                    }

                    context.Output.WriteLine(Serializer.Text.Serialize(items));
                    context.Output.WriteLine(CommandOutletColor.DarkGreen, string.Format(ResourceUtility.GetString("Text.QueueOutCommand.Message", i + 1, count, queue.Name)));
                }
            }

            return(result.ToArray());
        }
Ejemplo n.º 5
0
        protected override object OnExecute(CommandContext context)
        {
            var result = 0;
            var queues = QueueCommandHelper.GetQueues(context.CommandNode, context.Expression.Options.GetValue <string>("queues"));

            foreach (var queue in queues)
            {
                var count = queue.Count;

                if (count > 0)
                {
                    context.Output.WriteLine(CommandOutletColor.DarkGreen, ResourceUtility.GetString("Text.QueueCountCommand.Message", queue.Name, count));
                }
                else
                {
                    context.Output.WriteLine(CommandOutletColor.DarkRed, ResourceUtility.GetString("Text.QueueIsEmpty", queue.Name));
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        protected override object OnExecute(CommandContext context)
        {
            var queues = QueueCommandHelper.GetQueues(context.CommandNode, context.Expression.Options.GetValue <string>("queues"));
            var result = new List <object>(queues.Count);

            foreach (var queue in queues)
            {
                var item = queue.Peek();

                if (item == null)
                {
                    context.Output.WriteLine(CommandOutletColor.DarkRed, string.Format(Properties.Resources.Text_QueueIsEmpty, queue.Name));
                    continue;
                }

                result.Add(item);
                context.Output.WriteLine(Serializer.Json.Serialize(item));
            }

            return(result.ToArray());
        }