本文整理汇总了C#中CommandResult.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# CommandResult.WriteLine方法的具体用法?C# CommandResult.WriteLine怎么用?C# CommandResult.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandResult
的用法示例。
在下文中一共展示了CommandResult.WriteLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteHelpInformation
public static void WriteHelpInformation(
CommandResult commandResult,
string name,
string parameters,
string description,
OptionSet options
)
{
var displayMode = DisplayMode.DontWrap | DisplayMode.DontType;
commandResult.WriteLine(displayMode, description);
commandResult.WriteLine();
commandResult.WriteLine(displayMode, "Usage: {0} {1}", name, parameters);
commandResult.WriteLine();
commandResult.WriteLine(displayMode, "Options:");
commandResult.WriteLine();
var stringWriter = new StringWriter();
options.WriteOptionDescriptions(stringWriter);
commandResult.WriteLine(displayMode, stringWriter.ToString());
}
示例2: DisplayHelp
//public TopicUpdate GrabTopicUpdate
#endregion
#region Private Methods
/// <summary>
/// Display help information for all available commands, or invoke the help argument for a specifically supplied command.
/// </summary>
/// <param name="commands">The list of available commands.</param>
/// <param name="args">Any arguments passed in.</param>
/// <returns>A CommandResult option containing properties relevant to how data should be processed by the UI.</returns>
private CommandResult DisplayHelp(IEnumerable<ICommand> commands, string[] args, CommandResult commandResult)
{
var options = new OptionSet();
options.Add(
"?|help",
"Show help information.",
x =>
{
HelpUtility.WriteHelpInformation(
commandResult,
"HELP",
"[Option]",
"Displays help information.",
options
);
}
);
try
{
if (args != null)
{
var parsedArgs = options.Parse(args);
if (parsedArgs.Count == args.Length)
{
var commandName = parsedArgs.First();
var command = commands.SingleOrDefault(x => x.Name.Is(commandName));
if (command != null)
command.Invoke(new string[] { "-help" });
else
commandResult.WriteLine("'{0}' is not a recognized command.", commandName);
}
}
else
{
commandResult.WriteLine("The following commands are available:");
commandResult.WriteLine();
foreach (ICommand command in commands.OrderBy(x => x.Name))
if (command.ShowHelp)
commandResult.WriteLine(DisplayMode.DontType, "{0}{1}", command.Name.PadRight(15), command.Description);
commandResult.WriteLine();
commandResult.WriteLine("Type \"COMMAND -?\" for details on individual commands.");
if (_currentUser != null)
{
commandResult.WriteLine();
commandResult.WriteLine(DisplayMode.Dim | DisplayMode.DontType, new string('-', AppSettings.DividerLength));
commandResult.WriteLine();
var aliases = _aliasRepository.GetAliases(_currentUser.Username);
if (aliases.Count() > 0)
{
commandResult.WriteLine("You have the following aliases defined:");
commandResult.WriteLine();
foreach (var alias in aliases)
commandResult.WriteLine(DisplayMode.DontType, "{0}'{1}'", alias.Shortcut.ToUpper().PadRight(15, ' '), alias.Command);
}
else
commandResult.WriteLine("You have no aliases defined.");
}
}
}
catch (OptionException ex)
{
commandResult.WriteLine(ex.Message);
}
return commandResult;
}
示例3: BanMessage
private CommandResult BanMessage(CommandResult commandResult)
{
commandResult.Display.Clear();
commandResult.WriteLine("You were banned by {0}.", _currentUser.BanInfo.Creator);
commandResult.WriteLine();
commandResult.WriteLine("Reason: {0}", _currentUser.BanInfo.Reason);
commandResult.WriteLine();
commandResult.WriteLine("Expires {0}.", _currentUser.BanInfo.EndDate.TimeUntil());
FinalParsing(commandResult);
return commandResult;
}
示例4: ExecuteCommand
//.........这里部分代码省略.........
// Perform normal command execution.
// If command does not exist, attempt to use command context instead.
case ContextStatus.Passive:
if (command != null)
{
command.CommandResult.Command = command.Name;
command.Invoke(args);
}
else if (!commandName.Is("HELP"))
{
command = commands.SingleOrDefault(x => x.Name.Is(this._commandContext.Command));
if (command != null)
{
args = commandString.Contains(' ') ? commandString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries) : new string[] { commandString };
var newArgs = new List<string>();
if (this._commandContext.Args != null) newArgs.AddRange(this._commandContext.Args);
newArgs.AddRange(args);
command.CommandResult.Command = command.Name;
command.Invoke(newArgs.ToArray());
}
}
break;
// Perform command execution using command context.
// Reset command context if "CANCEL" is supplied.
case ContextStatus.Forced:
if (!commandName.Is("CANCEL"))
{
command = commands.SingleOrDefault(x => x.Name.Is(this._commandContext.Command));
if (command != null)
{
command.CommandResult.Command = command.Name;
if (this._commandContext.Prompt)
{
var newStrings = new List<string>();
if (this._commandContext.PromptData != null)
newStrings.AddRange(this._commandContext.PromptData);
newStrings.Add(commandString);
this._commandContext.PromptData = newStrings.ToArray();
command.Invoke(this._commandContext.Args);
}
else
{
args = commandString.Contains(' ') ? commandString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries) : new string[] { commandString };
var newArgs = new List<string>();
if (this._commandContext.Args != null) newArgs.AddRange(this._commandContext.Args);
newArgs.AddRange(args);
args = newArgs.ToArray();
command.Invoke(args);
}
}
}
else
{
commandResult.CommandContext.Restore();
commandResult.WriteLine("Action canceled.");
}
break;
}
// If command does not exist, check if the command was "HELP".
// If so, call the ShowHelp method to show help information for all available commands.
if (command == null)
{
if (commandName.Is("HELP"))
commandResult = DisplayHelp(commands, args, commandResult);
else if (!commandName.Is("CANCEL"))
if (commandName.IsNullOrWhiteSpace())
commandResult.WriteLine("You must supply a command.");
else
commandResult.WriteLine("'{0}' is not a recognized command or is not available in the current context.", commandName);
}
_currentUser = commandResult.CurrentUser;
if (_currentUser != null && _currentUser.BanInfo != null)
if (DateTime.UtcNow < _currentUser.BanInfo.EndDate)
return BanMessage(commandResult);
else
{
_userRepository.UnbanUser(_currentUser.Username);
_userRepository.UpdateUser(_currentUser);
}
// Temporarily notify of messages on each command execution.
if (_currentUser != null)
{
var unreadMessageCount = _messageRepository.UnreadMessages(_currentUser.Username);
if (unreadMessageCount > 0)
{
commandResult.WriteLine();
commandResult.WriteLine("You have {0} unread message(s).", unreadMessageCount);
}
}
commandResult.TerminalTitle = string.Format("Terminal - {0}", _currentUser != null ? _currentUser.Username : "Visitor");
FinalParsing(commandResult);
return commandResult;
}