コード例 #1
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(this.Queue.Count < 1)
			{
				context.Terminal.WriteLine(TerminalColor.DarkRed, ResourceUtility.GetString("QueueIsEmpty"));
				return;
			}

			int length;

			if(context.Options.TryGetValue<int>("length", out length))
				context.Result = this.Queue.Peek(length);
			else
			{
				if(context.Arguments.Length > 0 && int.TryParse(context.Arguments[0], out length))
					context.Result = this.Queue.Peek(length);
				else
					context.Result = this.Queue.Peek();
			}

			if(context.Result != null)
			{
				TerminalHelper.WriteObject(context.Terminal, context.Result, 3);
				//Zongsoft.Runtime.Serialization.Serializer.Text.Serialize(context.Terminal.OutputStream, context.Result);
			}
		}
コード例 #2
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(this.Queue.Count < 1)
			{
				context.Terminal.WriteLine(TerminalColor.DarkRed, ResourceUtility.GetString("QueueIsEmpty"));
				return;
			}

			int length;
			int round = (int)context.Options["round"];
			context.Options.TryGetValue<int>("length", out length);

			if(round > 0)
			{
				for(int i = 0; i < round; i++)
				{
					context.Result = this.Dequeue(length);

					if(context.Result != null)
						TerminalHelper.WriteObject(context.Terminal, context.Result, 3);
				}
			}
			else
			{
				while(this.Queue.Count > 0)
				{
					context.Result = this.Dequeue(length);

					if(context.Result != null)
						TerminalHelper.WriteObject(context.Terminal, context.Result, 3);
				}
			}
		}
コード例 #3
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			var serviceProvider = this.GetServiceProvider(context.CommandNode);

			if(serviceProvider == null)
				throw new CommandException(ResourceUtility.GetString("CannotObtainObject", "ServiceProvider"));

			var contractText = context.Options["contract"] as string;
			Type contract = null;

			if(!string.IsNullOrWhiteSpace(contractText))
			{
				contract = Type.GetType(contractText, false);

				if(contract == null)
					throw new CommandOptionValueException("contract", contractText);
			}

			if(contract == null)
			{
				if(context.Arguments.Length < 1)
					context.Terminal.WriteLine(TerminalColor.Red, ResourceUtility.GetString("Text.Command.MissingArguments"));

				context.Result = serviceProvider.Resolve(context.Arguments[0]);
			}
			else
			{
				context.Result = serviceProvider.Resolve(contract, context.Arguments.Length > 0 ? context.Arguments[0] : null);
			}

			if(context.Result != null)
				context.Terminal.WriteLine(Zongsoft.Runtime.Serialization.Serializer.Text.Serialize(context.Result));
			else
				context.Terminal.WriteLine(TerminalColor.DarkRed, ResourceUtility.GetString("Text.ServicesGetCommand.NotFoundService"));
		}
コード例 #4
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(this.Listener is TcpServer)
				this.DisplayTcpServerInfo((TcpServer)this.Listener, context.Terminal);
			else if(this.Listener is FtpServer)
				this.DisplayFtpServerInfo((FtpServer)this.Listener, context.Terminal);
			else
				this.DisplayListenerInfo(this.Listener, context.Terminal);
		}
コード例 #5
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(this.Listener.IsListening)
				this.Listener.Stop();

			if(this.Listener.IsListening)
				context.Terminal.WriteLine(ResourceUtility.GetString("${CommandExecuteFailed}"));
			else
				context.Terminal.WriteLine(ResourceUtility.GetString("${CommandExecuteSucceed}"));
		}
コード例 #6
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			var queue = this.Queue;

			if(queue != null)
				queue.Clear();

			//显示执行成功的信息
			context.Terminal.Write(ResourceUtility.GetString("${CommandExecuteSucceed}"));
		}
コード例 #7
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			var queue = this.Queue;

			if(queue != null)
			{
				var count = queue.Count;

				if(count > 0)
					context.Terminal.WriteLine(TerminalColor.DarkGreen, "The queue length is: {0}", count);
				else
					context.Terminal.WriteLine(TerminalColor.DarkRed, ResourceUtility.GetString("QueueIsEmpty"));
			}
		}
コード例 #8
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			var queue = this.Queue as Queue;

			if(queue == null)
			{
				context.Terminal.WriteLine(TerminalColor.DarkRed, ResourceUtility.GetString("NotSupportedOperation"));
				return;
			}

			queue.TrimToSize();

			//显示执行成功的信息
			context.Terminal.Write(ResourceUtility.GetString("CommandExecuteSucceed"));
		}
コード例 #9
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			var round = Math.Max(1, (int)context.Options["round"]);

			for(int i = 0; i < round; i++)
			{
				var count = this.ResolveValue(context, (value) =>
				{
					if(value != null)
						this.Queue.Enqueue(value);
				});

				context.Terminal.WriteLine(TerminalColor.DarkGreen, "第 {0} 轮入队 {1} 条记录。", i + 1, count);
			}
		}
コード例 #10
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(context.Options.Contains("async"))
			{
				this.Client.Connected += Client_Connected;
				this.Client.Failed += Client_Failed;

				this.Client.ConnectAsync(context);
			}
			else
			{
				if(this.Client.Connect())
					context.Terminal.WriteLine(TerminalColor.DarkGreen, ResourceUtility.GetString("${CommandExecuteSucceed}"));
				else
					context.Terminal.WriteLine(TerminalColor.DarkRed, ResourceUtility.GetString("${CommandExecuteFailed}"));
			}
		}
コード例 #11
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			//输出侦听地址。
			context.Terminal.Write(TerminalColor.DarkYellow, string.Format("{0}: {1}", ResourceUtility.GetString("${Text.ListenAddress}"), this.Server.Address));

			//输出服务器状态。
			context.Terminal.Write(TerminalColor.DarkGray, " [");
			this.DisplayServerState(context.Terminal, this.Server.ServerState);
			context.Terminal.Write(TerminalColor.DarkGray, "]");

			if(this.Server.ServerState != ServerState.Running)
				return;

			//输出运行信息。
			context.Terminal.WriteLine();
			context.Terminal.WriteLine(TerminalColor.DarkMagenta, this.Server.Scheduler.GetMetaData().GetSummary());
			context.Terminal.WriteLine();
		}
コード例 #12
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(this.Server.ServerState != ServerState.Stopped)
			{
				//输出日志。
				this.Logger.Debug(ResourceUtility.GetString("${Log.Server.Stopping}"));

				if(context.Options.Contains("wait"))
					this.Server.Stop(new []{ "wait" });
				else
					this.Server.Stop();
			}

			//输出日志。
			this.Logger.Debug(ResourceUtility.GetString("${Log.Server.Stopped}"));

			context.Terminal.WriteLine(ResourceUtility.GetString("${Text.CommandExecuteSucceed}"));
		}
コード例 #13
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(this.Server.ServerState != ServerState.Stopped)
			{
				context.Terminal.WriteLine(ResourceUtility.GetString("${Text.ServerHasBeenStarted}"));
				return;
			}

			//输出日志。
			this.Logger.Debug(ResourceUtility.GetString("${Log.Server.Starting}"));

			this.Server.Start();

			//输出日志。
			this.Logger.Debug(ResourceUtility.GetString("${Log.Server.Started}"));

			//输出控制台。
			context.Terminal.WriteLine(ResourceUtility.GetString("${Text.CommandExecuteSucceed}"));
		}
コード例 #14
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			context.Terminal.Write(TerminalColor.DarkYellow, ResourceUtility.GetString("${Text.IsConnected}") + ": ");
			context.Terminal.WriteLine(this.Client.IsConnected(1000) ? ResourceUtility.GetString("${Text.Yes}") : ResourceUtility.GetString("${Text.No}"));

			context.Terminal.Write(TerminalColor.DarkYellow, ResourceUtility.GetString("${RemoteEndPoint}") + ": ");
			context.Terminal.WriteLine(this.Client.RemoteAddress);

			context.Terminal.Write(TerminalColor.DarkYellow, ResourceUtility.GetString("${LocalEndPoint}") + ": ");
			context.Terminal.WriteLine(this.Client.LocalAddress);

			context.Terminal.Write(TerminalColor.DarkYellow, ResourceUtility.GetString("${LastConnectTime}") + ": ");
			context.Terminal.WriteLine(this.Client.Channel.LastConnectTime);

			context.Terminal.Write(TerminalColor.DarkYellow, ResourceUtility.GetString("${LastSendTime}") + ": ");
			context.Terminal.WriteLine(this.Client.Channel.LastSendTime);

			context.Terminal.Write(TerminalColor.DarkYellow, ResourceUtility.GetString("${LastReceivedTime}") + ": ");
			context.Terminal.WriteLine(this.Client.Channel.LastReceivedTime);
		}
コード例 #15
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			if(this.Server.ServerState == ServerState.Running)
			{
				//输出日志。
				this.Logger.Debug(ResourceUtility.GetString("${Log.Server.Pausing}"));

				this.Server.Pause();
			}

			if(this.Server.ServerState == ServerState.Paused)
			{
				//输出日志。
				this.Logger.Debug(ResourceUtility.GetString("${Log.Server.Paused}"));

				context.Terminal.WriteLine(ResourceUtility.GetString("${Text.CommandExecuteSucceed}"));
			}
			else
			{
				context.Terminal.WriteLine(ResourceUtility.GetString("${Text.CommandExecuteFailed}"));
			}
		}
コード例 #16
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			int channelId;

			if(!context.Options.TryGetValue("channel", out channelId))
				return;

			if(channelId < 0)
				throw new CommandOptionValueException("channel", channelId.ToString());

			var server = this.Listener as TcpServer;

			if(server == null)
			{
				context.Terminal.Error.Write(ResourceUtility.GetString("${Communication.ServerCommand.NotSupportChannel}"));
				return;
			}

			//获取指定编号的通道对象
			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.Terminal.WriteLine(ResourceUtility.GetString("${CommandExecuteSucceed}"));
		}
コード例 #17
0
		protected override void OnExecute(TerminalCommandContext context)
		{
			this.Client.Disconnect();
		}
コード例 #18
0
		private int ResolveValue(TerminalCommandContext context, Action<object> fallback)
		{
			int result = 0;

			switch((ContentType)context.Options["type"])
			{
				case ContentType.BinaryFile:
					foreach(var arg in context.Arguments)
					{
						if(!File.Exists(arg))
						{
							context.Terminal.WriteLine(ResourceUtility.GetString("FileOrDirectoryNotExists", arg));
							continue;
						}

						fallback(File.ReadAllBytes(arg.ToString()));
						result++;
					}
					break;
				case ContentType.TextFile:
					var encoding = (Encoding)context.Options["encoding"];

					foreach(var arg in context.Arguments)
					{
						string[] filePaths = null;

						if(arg.Contains("*") || arg.Contains("?"))
						{
							var directory = Path.GetDirectoryName(arg);

							if(!Directory.Exists(directory))
							{
								context.Terminal.WriteLine(ResourceUtility.GetString("FileOrDirectoryNotExists", arg));
								continue;
							}

							filePaths = Directory.GetFiles(directory, Path.GetFileName(arg));

							foreach(var filePath in filePaths)
							{
								fallback(File.ReadAllText(filePath, encoding));
							}

							result += filePaths.Length;
						}
						else
						{
							if(!File.Exists(arg))
							{
								context.Terminal.WriteLine(ResourceUtility.GetString("FileOrDirectoryNotExists", arg));
								continue;
							}

							fallback(File.ReadAllText(arg.ToString(), encoding));
							result++;
						}
					}
					break;
				case ContentType.String:
					foreach(var arg in context.Arguments)
					{
						fallback(arg);
					}
					break;
				case ContentType.Byte:
					foreach(var arg in context.Arguments)
					{
						fallback(Zongsoft.Common.Convert.ConvertValue<byte>(arg));
					}
					break;
				case ContentType.Short:
					foreach(var arg in context.Arguments)
					{
						fallback(Zongsoft.Common.Convert.ConvertValue<short>(arg));
					}
					break;
				case ContentType.Integer:
					foreach(var arg in context.Arguments)
					{
						fallback(Zongsoft.Common.Convert.ConvertValue<int>(arg));
					}
					break;
				case ContentType.Long:
					foreach(var arg in context.Arguments)
					{
						fallback(Zongsoft.Common.Convert.ConvertValue<long>(arg));
					}
					break;
				case ContentType.Date:
				case ContentType.DateTime:
					if(context.Arguments.Length < 1)
						fallback(DateTime.Now);
					else
					{
						foreach(var arg in context.Arguments)
						{
							fallback(Zongsoft.Common.Convert.ConvertValue<DateTime>(arg));
						}
					}
					break;
				case ContentType.Guid:
					if(context.Arguments.Length < 1)
						fallback(Guid.NewGuid());
					else
					{
						foreach(var arg in context.Arguments)
						{
							fallback(Zongsoft.Common.Convert.ConvertValue<Guid>(arg));
						}
					}
					break;
				default:
					return 0;
			}

			return Math.Max(1, result);
		}