protected override object OnExecute(CommandContext context)
        {
            var client = TcpClientCommand.GetClient(context.CommandNode);

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

            if (context.Expression.Options.Contains("async"))
            {
                client.Connected += Client_Connected;
                client.Failed    += Client_Failed;

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

            return(null);
        }
Exemple #2
0
        protected override object OnExecute(CommandContext context)
        {
            var client = TcpClientCommand.GetClient(context.CommandNode);

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

            client.Disconnect();

            context.Output.WriteLine(ResourceUtility.GetString("Text.CommandExecuteSucceed"));

            return(null);
        }
        protected override object OnExecute(CommandContext context)
        {
            var client = TcpClientCommand.GetClient(context.CommandNode);

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

            bool isConnected = client.IsConnected(1000);

            context.Output.Write(CommandOutletColor.DarkYellow, ResourceUtility.GetString("${Text.IsConnected}") + ": ");
            context.Output.WriteLine(isConnected ? ResourceUtility.GetString("${Text.Yes}") : ResourceUtility.GetString("${Text.No}"));

            context.Output.Write(CommandOutletColor.DarkYellow, ResourceUtility.GetString("${Text.RemoteEndPoint}") + ": ");
            context.Output.WriteLine(client.RemoteAddress);

            context.Output.Write(CommandOutletColor.DarkYellow, ResourceUtility.GetString("${Text.LocalEndPoint}") + ": ");
            context.Output.WriteLine(client.LocalAddress);

            context.Output.Write(CommandOutletColor.DarkYellow, ResourceUtility.GetString("${Text.LastConnectTime}") + ": ");
            context.Output.WriteLine(client.Channel.LastConnectTime);

            context.Output.Write(CommandOutletColor.DarkYellow, ResourceUtility.GetString("${Text.LastSendTime}") + ": ");
            context.Output.WriteLine(client.Channel.LastSendTime);

            context.Output.Write(CommandOutletColor.DarkYellow, ResourceUtility.GetString("${Text.LastReceivedTime}") + ": ");
            context.Output.WriteLine(client.Channel.LastReceivedTime);

            return(new
            {
                IsConnected = isConnected,
                RemoteAddress = client.RemoteAddress,
                LocalAddress = client.LocalAddress,
                LastConnectTime = client.Channel.LastConnectTime,
                LastSendTime = client.Channel.LastSendTime,
                LastReceivedTime = client.Channel.LastReceivedTime,
            });
        }