Beispiel #1
0
        protected override object OnExecute(CommandContext context)
        {
            var name = string.Empty;

            if (context.Expression.Options.TryGetValue("name", out name))
            {
                var parts = name.Split('@');

                if (parts.Length == 2)
                {
                    _queueProvider = _serviceProvider.ResolveRequired <IQueueProvider>(parts[1]);
                }
                else
                {
                    _queueProvider = _serviceProvider.ResolveRequired <IQueueProvider>();
                }

                if (_queueProvider == null)
                {
                    throw new CommandException(ResourceUtility.GetString("Text.QueueCommand.MissingQueueProvider"));
                }

                _queue = _queueProvider.GetQueue(parts[0]);

                if (_queue == null)
                {
                    throw new CommandException(ResourceUtility.GetString("Text.QueueCommand.NotFoundQueue", name));
                }
            }

            if (_queue == null)
            {
                throw new CommandException(ResourceUtility.GetString("Text.CannotObtainCommandTarget", "Queue"));
            }

            //打印队列信息
            context.Output.WriteLine(ResourceUtility.GetString("Text.QueueCommand.Message", _queue.Name, _queue.Count, _queue.GetType().FullName, _queue.ToString()));

            return(_queue);
        }