本文整理汇总了C#中ICommand.Run方法的典型用法代码示例。如果您正苦于以下问题:C# ICommand.Run方法的具体用法?C# ICommand.Run怎么用?C# ICommand.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommand
的用法示例。
在下文中一共展示了ICommand.Run方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryToProceedCommand
private bool TryToProceedCommand(ICommand command, IEnumerable<string> args)
{
if (command != null)
{
if (command.Verbose)
Console.WriteLine("Proceeding Command: " + command.Name);
try
{
_commandPropertyWalker.FillCommandProperties(args, command);
command.Console = Console;
command.Run();
return true;
}
catch (Exception exception)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Unexpected error happended while proceeding the command: " + command.Name);
var exceptionWalker = new ExceptionWalker(exception);
foreach (var message in exceptionWalker.GetExceptionMessages())
{
Console.WriteLine(message);
}
Console.ResetColor();
return false;
}
}
return false;
}
示例2: Cycle
protected void Cycle(ICommand command)
{
try
{
command.Run();
Thread.Sleep(this.interval);
}
catch (TimeoutException)
{
}
}
示例3: RunCommand
private static CommandResult RunCommand(HttpApplication application, ICommand command)
{
try
{
return command.Run(new HttpRequestWrapper(application.Request));
}
catch (AuthServicesException)
{
return new CommandResult()
{
HttpStatusCode = HttpStatusCode.InternalServerError
};
}
}
示例4: RunCommand
private static CommandResult RunCommand(HttpContext application, ICommand command, IOptions options)
{
try
{
return command.Run(new HttpRequestWrapper(application.Request).ToHttpRequestData(), options, application.Session);
}
catch (OIDCException)
{
return new CommandResult
{
HttpStatusCode = HttpStatusCode.InternalServerError
};
}
}
示例5: RunCommand
void RunCommand(ICommand command)
{
command.Owner = treeView;
command.Run();
}
示例6: TryToProceedCommand
private bool TryToProceedCommand(ICommand command, IEnumerable<string> args)
{
if (command != null)
{
AbstractTraceConsole traceConsole = null;
try
{
command.InjectProperties(args);
traceConsole = new TraceConsole(Console, command);
if (!command.AllowParallel && !_lockingService.AcquireLock(command.Name))
return false;
command.Console = traceConsole;
command.Run();
return true;
}
catch (Exception exception)
{
LogException(traceConsole, exception, command);
return false;
}
finally
{
if (!command.AllowParallel)
_lockingService.ReleaseLock(command.Name);
var disposable = traceConsole as IDisposable;
if (disposable != null)
disposable.Dispose();
}
}
return false;
}
示例7: ExecuteCommand
/// <summary>
/// Executes a command
/// </summary>
/// <param name="cmd">The command to execute</param>
/// <param name="args">Arguments to apply to the command</param>
/// <param name="directive">Directives to execute with</param>
/// <returns>The outcome of the execution</returns>
private CommandResult ExecuteCommand(ICommand cmd, string[] args, ExecutionDirective directive)
{
cmd.Initialise(_context, _formatter);
CommandResult result = null;
var manualParseInterface = CommandInspector.GetManualParseCommand(cmd);
if (manualParseInterface != null)
{
var subArgs = from arg in args
select Parser.PerformSubstitution(_context, arg);
result = manualParseInterface.Run(subArgs.ToArray());
}
else
{
var properties = cmd.GetType().GetProperties();
object propValue = null;
var processingArgs = args;
// Process multi-word named parameters first
foreach (var prop in properties)
{
propValue = null;
var namedParameterAttribute = CommandInspector.GetNamedParameter(prop);
if (namedParameterAttribute != null && namedParameterAttribute.WordCount > 1)
{
var words = new List<string>();
for (var i = 0; i < namedParameterAttribute.WordCount; i++)
{
var value = string.Empty;
ParameterUtil.GetParameter(args, "-" + namedParameterAttribute.Name, i, ref value);
if (!string.IsNullOrEmpty(value))
words.Add(value);
}
if (words.Count > 0)
{
propValue = words.ToArray();
processingArgs = ParameterUtil.RemoveParameter(processingArgs, "-" + namedParameterAttribute.Name, namedParameterAttribute.WordCount);
}
}
ConvertAndAssignParameter(prop, cmd, propValue);
}
// Find flags
var flags = from prop in properties
let attr = CommandInspector.GetFlagParameter(prop)
where attr != null
select attr.Name;
// Parse remaining arguments
StringDictionary named = null;
string[] numbered = null;
ParameterUtil.ExtractParameters(out named, out numbered, processingArgs, flags.ToArray());
// Map the parameters to properties
foreach (var prop in properties)
{
propValue = null;
var namedParameterAttribute = CommandInspector.GetNamedParameter(prop);
if (namedParameterAttribute != null)
{
if (named.ContainsKey(namedParameterAttribute.Name))
propValue = named[namedParameterAttribute.Name];
}
var numberedParameterAttribute = CommandInspector.GetNumberedParameter(prop);
if (numberedParameterAttribute != null)
{
if (numberedParameterAttribute.Number < numbered.Length)
propValue = numbered[numberedParameterAttribute.Number];
}
var flagParameterAttribute = CommandInspector.GetFlagParameter(prop);
if (flagParameterAttribute != null)
{
if (named.ContainsKey(flagParameterAttribute.Name))
{
#if NET45
var origVal = (bool)prop.GetValue(cmd);
#else
var origVal = (bool)prop.GetValue(cmd, null);
#endif
propValue = !origVal;
}
}
ConvertAndAssignParameter(prop, cmd, propValue);
//.........这里部分代码省略.........
示例8: RunCommand
private static CommandResult RunCommand(HttpApplication application, ICommand command, IOptions options)
{
return command.Run(
new HttpRequestWrapper(application.Request).ToHttpRequestData(),
options);
}