Exemplo n.º 1
0
        protected override object OnExecute(CommandContext context)
        {
            var server = ServerCommandBase.GetServer(context.CommandNode);

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

            if (server.IsListening)
            {
                context.Output.WriteLine(ResourceUtility.GetString("Text.ServerHasBeenStarted"));
                return(false);
            }

            server.Start();

            if (server.IsListening)
            {
                context.Output.WriteLine(CommandOutletColor.Green, ResourceUtility.GetString("Text.CommandExecuteSucceed"));
            }
            else
            {
                context.Output.WriteLine(CommandOutletColor.Red, ResourceUtility.GetString("Text.CommandExecuteFailed"));
            }

            return(server.IsListening);
        }
Exemplo n.º 2
0
        protected override object OnExecute(CommandContext context)
        {
            var server = ServerCommandBase.GetServer(context.CommandNode);

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

            if (server is TcpServer)
            {
                this.DisplayTcpServerInfo((TcpServer)server, context.Output, this.GetActiveChannel(context.CommandNode));
            }
            else if (server is Net.FtpServer)
            {
                this.DisplayFtpServerInfo((FtpServer)server, context.Output);
            }
            else
            {
                this.DisplayListenerInfo(server, context.Output);
            }

            return(server.IsListening);
        }
Exemplo n.º 3
0
        protected override object OnExecute(CommandContext context)
        {
            var server = ServerCommandBase.GetServer(context.CommandNode) as TcpServer;

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

            int channelId = -1;

            if (context.Expression.Options.TryGetValue("channel", out channelId))
            {
                if (channelId < 0)
                {
                    throw new CommandOptionValueException("channel", channelId.ToString());
                }

                //获取指定编号的通道对象
                var channel = server.ChannelManager.GetActivedChannel(channelId);

                //如果获取指定的通道失败或者获取到的通道为空闲状态,则抛出命令选项值异常
                if (channel == null || channel.IsIdled)
                {
                    throw new CommandException(string.Format("Can not obtain the actived channel by '#{0}' channel-id.", channelId));
                }

                //设置服务器的活动通道
                _channel = channel;

                //显示命令执行成功信息
                context.Output.WriteLine(ResourceUtility.GetString("${Text.CommandExecuteSucceed}"));
            }

            return(channelId);
        }