本文整理汇总了C#中System.CommandLine类的典型用法代码示例。如果您正苦于以下问题:C# CommandLine类的具体用法?C# CommandLine怎么用?C# CommandLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandLine类属于System命名空间,在下文中一共展示了CommandLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CsvViewer
public CsvViewer(CommandLine.CommandLine cmd, FileIO fio, Ui ui, Formatieren format)
{
_cmd = cmd;
_fio = fio;
_ui = ui;
_format = format;
}
示例2: RunApplication
public void RunApplication(string[] args)
{
var commandLine = new CommandLine();
commandLine.Parse(args);
using (var @lock = CreateLock(string.IsNullOrEmpty(commandLine.LockName) ? @"F17BFCF1-0832-4575-9C7D-F30D8C359159" : commandLine.LockName, commandLine.AddGlobalPrefix))
{
Console.WriteLine("Acquiring lock");
@lock.Lock();
Console.WriteLine("Acquired lock");
try
{
Console.WriteLine("Holding lock for {0} seconds", commandLine.HoldTime);
Thread.Sleep(1000*commandLine.HoldTime);
}
finally
{
Console.WriteLine("Released lock");
@lock.Unlock();
}
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey(true);
}
示例3: Main
static void Main(string[] args)
{
System.Windows.Forms.Application.EnableVisualStyles();
if (LoadConfiguration(args))
{
Configuration.Environment = ExecutionEnvironment.WindowsApplication;
ICommandLine commandLine = new CommandLine(args);
string titleArgument = commandLine.GetArgument("title");
string projectPath = commandLine.GetArgument("project");
string viewName = commandLine.GetArgument("view");
string recordId = commandLine.GetArgument("record");
try
{
Epi.Windows.Enter.EnterMainForm mainForm = new Epi.Windows.Enter.EnterMainForm();
if (!mainForm.IsDisposed)
{
mainForm.Show();
if (mainForm.WindowState == FormWindowState.Minimized)
{
mainForm.WindowState = FormWindowState.Normal;
}
mainForm.Activate();
mainForm.Text = string.IsNullOrEmpty(titleArgument) ? mainForm.Text : titleArgument;
if (!string.IsNullOrEmpty(projectPath))
{
Project project = new Project(projectPath);
mainForm.CurrentProject = project;
if (string.IsNullOrEmpty(recordId))
{
mainForm.FireOpenViewEvent(project.Views[viewName]);
}
else
{
mainForm.FireOpenViewEvent(project.Views[viewName], recordId);
}
}
//--2225
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
//--
System.Windows.Forms.Application.Run(mainForm);
}
mainForm = null;
}
catch (Exception baseException)
{
MsgBox.ShowError(string.Format("Error: \n {0}", baseException.ToString()));
}
}
}
示例4: Initialise
protected override void Initialise(CommandLine cl)
{
if (cl.args.Count == 1)
volumeId = cl.args[0].Trim();
else
throw new SyntaxException("The snapshot command requires one parameter");
}
示例5: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
var commandLine = new CommandLine(args);
if (commandLine.RunAsService)
{
ServiceBase[] servicesToRun = new ServiceBase[] {new ShredHostService()};
ServiceBase.Run(servicesToRun);
}
else if (!String.IsNullOrEmpty(commandLine.PreviousExeConfigurationFilename))
{
var groups = SettingsGroupDescriptor.ListInstalledLocalSettingsGroups();
foreach (var group in groups)
SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename);
ShredSettingsMigrator.MigrateAll(commandLine.PreviousExeConfigurationFilename);
}
else
{
Thread.CurrentThread.Name = "Main thread";
if (!ManifestVerification.Valid)
Console.WriteLine("The manifest detected an invalid installation.");
ShredHostService.InternalStart();
Console.WriteLine("Press <Enter> to terminate the ShredHost.");
Console.WriteLine();
Console.ReadLine();
ShredHostService.InternalStop();
}
}
示例6: Execute
public void Execute(CommandLine commandLine, CommandExecutionContext context)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("==================================================");
Console.WriteLine(" Welcome to {0} {1}", ApplicationInfo.Title, ApplicationInfo.Version.ToString(2));
Console.WriteLine(" " + ApplicationInfo.Description);
Console.WriteLine(" " + ApplicationInfo.CopyrightHolder);
Console.WriteLine("==================================================");
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Available commands are:");
foreach (var cmd in CommandFactory.All)
{
Console.Write("-" + cmd.Name);
Console.Write("\t");
if (!String.IsNullOrEmpty(cmd.ShortName))
{
Console.Write("[" + cmd.ShortName + "] ");
}
Console.Write(cmd.Description);
if (!String.IsNullOrEmpty(cmd.Usage))
{
Console.Write(" Usage: " + cmd.Usage);
}
Console.WriteLine();
}
}
示例7: Execute
public void Execute(CommandLine commandLine, CommandExecutionContext context)
{
if (commandLine.Parameters.Count != 2)
{
ConsoleUtil.ErrorLine("Invalid request. Please check syntax: " + Usage);
return;
}
var host = commandLine.Parameters[1];
var ip = commandLine.Parameters[0];
if (context.Hosts.Contains(host))
{
if (commandLine.Options.Count > 0 && commandLine.Options[0].Name == "override")
{
context.Hosts.Set(ip, host);
context.Hosts.Save();
Console.WriteLine("1 entry updated: " + commandLine.Parameters[0] + " " + commandLine.Parameters[1]);
}
else
{
ConsoleUtil.ErrorLine(host + " already exists. Use -override to override the existing entry.");
}
}
else
{
context.Hosts.Set(commandLine.Parameters[0], commandLine.Parameters[1]);
context.Hosts.Save();
Console.WriteLine("1 entry added: " + commandLine.Parameters[0] + " " + commandLine.Parameters[1]);
}
}
示例8: CheckOptions
public override void CheckOptions(CommandLine cmd)
{
// Confidence estimator
double confidence = Allcea.DEFAULT_CONFIDENCE;
double sizeRel = Allcea.DEFAULT_RELATIVE_SIZE;
double sizeAbs = Allcea.DEFAULT_ABSOLUTE_SIZE;
if (cmd.HasOption('c')) {
confidence = AbstractCommand.CheckConfidence(cmd.GetOptionValue('c'));
}
if (cmd.HasOption('s')) {
string[] sizeStrings = cmd.GetOptionValues('s');
if (sizeStrings.Length != 2) {
throw new ArgumentException("Must provide two target effect sizes: relative and absolute.");
}
sizeRel = AbstractCommand.CheckRelativeSize(sizeStrings[0]);
sizeAbs = AbstractCommand.CheckAbsoluteSize(sizeStrings[1]);
}
this._confEstimator = new NormalConfidenceEstimator(confidence, sizeRel, sizeAbs);
// Double format
if (cmd.HasOption('d')) {
this._decimalDigits = AbstractCommand.CheckDigits(cmd.GetOptionValue('d'));
}
// Files
this._inputPath = AbstractCommand.CheckInputFile(cmd.GetOptionValue('i'));
if (cmd.HasOption('j')) {
this._judgedPath = AbstractCommand.CheckJudgedFile(cmd.GetOptionValue('j'));
}
this._estimatedPath = AbstractCommand.CheckEstimatedFile(cmd.GetOptionValue('e'));
}
示例9: GetCommand
/// <summary>
/// 获取用户命令。
/// </summary>
/// <param name="args">命令行参数。</param>
/// <param name="verb">命令代号。</param>
/// <returns></returns>
public static CommandLine GetCommand(string[] args, string verb)
{
CommandLine command = null;
if (args != null && args.Length > 0)
{
if (verb.IndexOf('-') != 0)
verb = "-" + verb;
for (int i = 0; i < args.Length; i++)
{
if (args[i] == verb)
{
command = new CommandLine(verb, String.Empty);
if (args[i + 1].IndexOf(("-")) != 0)
{
command.Parameter = args[i + 1];
}
break;
}
}
}
return command;
}
示例10: Main
public static void Main(string[] args)
{
CommandLine commandLine = new CommandLine(args);
switch(commandLine.Action)
{
case "new":
// Create a new employee
Console.WriteLine("'Creating' a new Employee.");
break;
case "update":
// Update an existing employee's data
Console.WriteLine("'Updating' a new Employee.");
break;
case "delete":
// Remove an existing employee's file
Console.WriteLine("'Removing' a new Employee.");
break;
default:
Console.WriteLine(
"Employee.exe new|update|delete " +
"<id> [firstname] [lastname]");
break;
}
}
示例11: Run
public void Run(string[] args)
{
CommandLine commandLine = new CommandLine();
commandLine.AddOption("Verbose", false, "-verbose");
commandLine.Parse(args);
if ((bool)commandLine.GetOption("-h"))
{
commandLine.Help("Katahdin Interpreter");
return;
}
Runtime runtime = new Runtime(true, false, false, false,
(bool)commandLine.GetOption("-verbose"));
//new ConsoleParseTrace(runtime);
runtime.SetUp(commandLine.Args);
if (!((bool)commandLine.GetOption("-nostd")))
runtime.ImportStandard();
foreach (string file in commandLine.Files)
runtime.Import(file);
}
示例12: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
var commandLine = new CommandLine(args);
if (commandLine.RunAsService)
{
var ServicesToRun = new ServiceBase[] { new ShredHostService() };
ServiceBase.Run(ServicesToRun);
}
else if (!String.IsNullOrEmpty(commandLine.PreviousExeConfigurationFilename))
{
var groups = SettingsGroupDescriptor.ListInstalledLocalSettingsGroups();
groups.Add(new SettingsGroupDescriptor(typeof (ShredSettingsMigrator).Assembly.GetType("ClearCanvas.Server.ShredHost.ShredHostServiceSettings")));
foreach (var group in groups)
SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename);
ShredSettingsMigrator.MigrateAll(commandLine.PreviousExeConfigurationFilename);
}
else
{
ShredHostService.InternalStart();
Console.WriteLine("Press <Enter> to terminate the ShredHost.");
Console.WriteLine();
Console.ReadLine();
ShredHostService.InternalStop();
}
}
示例13: CreateInstance
public static void CreateInstance(string commandName, CommandLine commandLine)
{
commandLine.command = CreateInstance(commandName);
if (commandLine.command == null)
throw new SyntaxException(string.Format("Unknown command: {0}", commandName));
else
commandLine.command.Initialise(commandLine);
}
示例14: RunApplication
public void RunApplication(string[] args)
{
var commandLine = new CommandLine(args);
var groups = SettingsGroupDescriptor.ListInstalledLocalSettingsGroups();
foreach (var group in groups)
SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename);
}
示例15: Initialise
protected override void Initialise(CommandLine cl)
{
if (cl.args.Count > 0)
command = Command.CreateInstance(cl.args[0]);
if (command == null)
command = this;
}