本文整理汇总了C#中CommandLine.Parser.ParseArgumentsStrict方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLine.Parser.ParseArgumentsStrict方法的具体用法?C# CommandLine.Parser.ParseArgumentsStrict怎么用?C# CommandLine.Parser.ParseArgumentsStrict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandLine.Parser
的用法示例。
在下文中一共展示了CommandLine.Parser.ParseArgumentsStrict方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>
/// 应用程序入口
/// </summary>
/// <param name="args">命令行参数</param>
static void Main(string[] args)
{
System.DateTime startTime = System.DateTime.Now;
//-- 分析命令行参数
var options = new Options();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-1)))
{
//-- 执行导出操作
try
{
Run(options);
}
catch (Exception exp)
{
Console.WriteLine("Error: " + exp.Message);
}
}
//-- 程序计时
System.DateTime endTime = System.DateTime.Now;
System.TimeSpan dur = endTime - startTime;
Console.WriteLine(
string.Format("[{0}]:\t转换完成[{1}毫秒].",
Path.GetFileName(options.ExcelPath),
dur.Milliseconds)
);
}
示例2: Main
static void Main(string[] args)
{
// Parse command line options
var mpOptions = new CommandLineOptions();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1));
List<string> products = new List<string>
{
"MediaPortal Setup TV", // Legacy folders for TVE3 support
"MediaPortal TV Server", // Legacy folders for TVE3 support
"MP2-Client",
"MP2-Server",
"MP2-ClientLauncher",
"MP2-ServiceMonitor"
};
string dataPath = !string.IsNullOrEmpty(mpOptions.DataDirectory) ?
mpOptions.DataDirectory :
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
string outputPath = !string.IsNullOrEmpty(mpOptions.OutputDirectory) ?
mpOptions.OutputDirectory :
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "MediaPortal2-Logs");
try
{
CollectLogFiles(dataPath, outputPath, products);
}
catch (Exception ex)
{
Console.WriteLine("Exception while collecting log files: {0}", ex);
}
}
示例3: Main
/// <summary>
/// The main entry point for the MP2 server application.
/// </summary>
public static void Main(params string[] args)
{
// Parse command line options
var mpOptions = new CommandLineOptions();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1));
if (mpOptions.RunAsConsoleApp)
new ApplicationLauncher(mpOptions.DataDirectory).RunAsConsole();
else
{
ServiceBase[] servicesToRun = new ServiceBase[] { new WindowsService() };
ServiceBase.Run(servicesToRun);
}
}
示例4: Main
static void Main(string[] args)
{
// direct the output to the console.
OsmSharp.Tools.Output.OutputStreamHost.RegisterOutputStream(
new ConsoleOutputStream());
// check for command line options.
var options = new Options();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
{
// parsing was successfull.
OperationProcessor.Settings["pbf_file"] = options.File;
}
// initializes the processor(s).
var processors = new List<IProcessor>();
processors.Add(OperationProcessor.GetInstance());
// start all the processor(s).
foreach (IProcessor processor in processors)
{
processor.Start();
}
// get the hostname.
string hostname = options.Hostname;
if (string.IsNullOrWhiteSpace(hostname))
{
hostname = ConfigurationManager.AppSettings["hostname"];
}
if (string.IsNullOrWhiteSpace(hostname))
{
throw new ArgumentOutOfRangeException("hostname", "Hostname not configure! use -h or --host");
}
OsmSharp.Tools.Output.OutputStreamHost.WriteLine("Service will listen to: {0}",
hostname);
// start the self-hosting.
var host = new AppHost();
host.Init();
host.Start(hostname);
OsmSharp.Tools.Output.OutputStreamHost.WriteLine("OsmDataService started.");
Console.ReadLine();
}
示例5: Parse_strict_bad_input_fails_and_exits_when_get_usage_is_defined
public void Parse_strict_bad_input_fails_and_exits_when_get_usage_is_defined()
{
var options = new SimpleOptionsForStrict();
var testWriter = new StringWriter();
ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter);
var result = parser.ParseArgumentsStrict(new string[] { "--bad", "--input" }, options,
() => Console.WriteLine("fake fail"));
result.Should().BeFalse();
var helpText = testWriter.ToString();
Console.WriteLine(helpText);
var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Did we really called user help method?
lines.Should().HaveCount(n => n == 1);
// Verify just significant output
lines[0].Trim().Should().Be("SimpleOptionsForStrict (user defined)");
}
示例6: Main
static void Main(string[] args)
{
Thread.CurrentThread.Name = "Main";
// Parse command line options
var mpOptions = new CommandLineOptions();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1));
if (String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("wix")))
{
Console.Write("WiX environment variable could not be found. Please reinstall WiX.");
Environment.Exit(2);
}
if (!CreateTransforms(mpOptions))
Environment.Exit(3);
if (!MergeTransforms(mpOptions))
Environment.Exit(4);
}
示例7: Parse_strict_bad_input_fails_and_exits
public void Parse_strict_bad_input_fails_and_exits()
{
var options = new SimpleOptions();
var testWriter = new StringWriter();
ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter);
var result = parser.ParseArgumentsStrict(new string[] {"--bad", "--input"}, options,
() => Console.WriteLine("fake fail"));
result.Should().BeFalse();
var helpText = testWriter.ToString();
Console.WriteLine(helpText);
var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Did we really produced all help?
lines.Should().HaveCount(n => n == 8);
// Verify just significant output
lines[5].Trim().Should().Be("-s, --string");
lines[6].Trim().Should().Be("-i");
lines[7].Trim().Should().Be("--switch");
}
示例8: Main
static void Main(string[] args)
{
var cmd = new GenArgs();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
if (parser.ParseArgumentsStrict(args, cmd, () =>
{
Console.ReadLine();
Environment.FailFast("Failed");
}))
{
if (File.Exists(cmd.ResxFilePath))
{
Run(cmd);
}
else
{
Console.WriteLine($"RESX file {cmd.ResxFilePath} does not eixst");
}
}
Console.WriteLine("Press <ENTER> to quit");
Console.ReadLine();
}
示例9: OnStartup
/// <summary>
/// Either shows the application's main window or inits the application in the system tray.
/// </summary>
private void OnStartup(object sender, StartupEventArgs args)
{
Thread.CurrentThread.Name = "Main";
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
// Parse command line options
var mpOptions = new CommandLineOptions();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
parser.ParseArgumentsStrict(args.Args, mpOptions, () => Environment.Exit(1));
// Check if another instance is already running
// If new instance was created by UacHelper previous one, assume that previous one is already closed.
if (SingleInstanceHelper.IsAlreadyRunning(MUTEX_ID, out _mutex))
{
_mutex = null;
// Set focus on previously running app
SingleInstanceHelper.SwitchToCurrentInstance(SingleInstanceHelper.SHOW_MP2_SERVICEMONITOR_MESSAGE );
// Stop current instance
Console.Out.WriteLine("Application already running.");
Environment.Exit(2);
}
// Make sure we're properly handling exceptions
DispatcherUnhandledException += OnUnhandledException;
AppDomain.CurrentDomain.UnhandledException += LauncherExceptionHandling.CurrentDomain_UnhandledException;
var systemStateService = new SystemStateService();
ServiceRegistration.Set<ISystemStateService>(systemStateService);
systemStateService.SwitchSystemState(SystemState.Initializing, false);
#if !DEBUG
string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MP2-ServiceMonitor\Log");
#endif
try
{
ILogger logger = null;
try
{
ApplicationCore.RegisterVitalCoreServices();
ApplicationCore.RegisterCoreServices();
logger = ServiceRegistration.Get<ILogger>();
logger.Debug("Starting Localization");
Localization localization = new Localization();
ServiceRegistration.Set<ILocalization>(localization);
localization.Startup();
//ApplicationCore.StartCoreServices();
logger.Debug("UiExtension: Registering ISystemResolver service");
ServiceRegistration.Set<ISystemResolver>(new SystemResolver());
logger.Debug("UiExtension: Registering IServerConnectionManager service");
ServiceRegistration.Set<IServerConnectionManager>(new ServerConnectionManager());
#if !DEBUG
logPath = ServiceRegistration.Get<IPathManager>().GetPath("<LOG>");
#endif
}
catch (Exception e)
{
if (logger != null)
logger.Critical("Error starting application", e);
systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
ServiceRegistration.IsShuttingDown = true;
ApplicationCore.DisposeCoreServices();
throw;
}
var appController = new AppController();
ServiceRegistration.Set<IAppController>(appController);
// Start the application
logger.Debug("Starting application");
try
{
ServiceRegistration.Get<IServerConnectionManager>().Startup();
appController.StartUp(mpOptions);
}
catch (Exception e)
{
logger.Critical("Error executing application", e);
systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
ServiceRegistration.IsShuttingDown = true;
}
}
catch (Exception ex)
{
#if DEBUG
var log = new ConsoleLogger(LogLevel.All, false);
log.Error(ex);
#else
ServerCrashLogger crash = new ServerCrashLogger(logPath);
//.........这里部分代码省略.........
示例10: Main
/// <summary>
/// The main entry point for the MP2-ClientLauncher application.
/// </summary>
private static void Main(params string[] args)
{
Thread.CurrentThread.Name = "Main";
// Parse command line options
var mpOptions = new CommandLineOptions();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1));
// Check if another instance is already running
if (SingleInstanceHelper.IsAlreadyRunning(MUTEX_ID, out _mutex))
{
_mutex = null;
// Stop current instance
Console.Out.WriteLine("Application already running.");
Environment.Exit(2);
}
#if !DEBUG
string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
@"Team MediaPortal", "MP2-Client", "Log");
#endif
//// todo: Make sure we're properly handling exceptions
//DispatcherUnhandledException += OnUnhandledException;
//AppDomain.CurrentDomain.UnhandledException += LauncherExceptionHandling.CurrentDomain_UnhandledException;
// Start core services
ILogger logger = null;
try
{
// Check if user wants to override the default Application Data location.
ApplicationCore.RegisterVitalCoreServices(mpOptions.DataDirectory);
logger = ServiceRegistration.Get<ILogger>();
#if !DEBUG
logPath = ServiceRegistration.Get<IPathManager>().GetPath("<LOG>");
#endif
}
catch (Exception e)
{
if (logger != null)
logger.Critical("Error starting application", e);
ApplicationCore.DisposeCoreServices();
throw;
}
// Start application
logger.Info("Starting application");
try
{
if (TerminateProcess("ehtray"))
logger.Info("Terminating running instance(s) of ehtray.exe");
Remote.Transceivers.AddRange(GetTransceiverList());
Remote.Click += OnClick;
Device.DeviceArrival += OnDeviceArrival;
Device.DeviceRemoval += OnDeviceRemoval;
if (!mpOptions.NoIcon)
InitTrayIcon();
Application.Run();
}
catch (Exception e)
{
logger.Critical("Error executing application", e);
}
logger.Info("Exiting...");
// Release mutex for single instance
if (_mutex != null)
_mutex.ReleaseMutex();
Application.Exit();
}
示例11: Main
/// <summary>
/// The main entry point for the MP2 client application.
/// </summary>
private static void Main(params string[] args)
{
Thread.CurrentThread.Name = "Main";
// Parse command line options
var mpOptions = new CommandLineOptions();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1));
// Check if another instance is already running
if (SingleInstanceHelper.IsAlreadyRunning(MUTEX_ID, out _mutex))
{
_mutex = null;
// Set focus on previously running app
SingleInstanceHelper.SwitchToCurrentInstance(SingleInstanceHelper.SHOW_MP2_CLIENT_MESSAGE);
// Stop current instance
Console.Out.WriteLine("Application already running.");
Environment.Exit(2);
}
#if !DEBUG
string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MP2-Client\Log");
#endif
Application.ThreadException += LauncherExceptionHandling.Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += LauncherExceptionHandling.CurrentDomain_UnhandledException;
SystemStateService systemStateService = new SystemStateService();
ServiceRegistration.Set<ISystemStateService>(systemStateService);
systemStateService.SwitchSystemState(SystemState.Initializing, false);
try
{
#if !DEBUG
SplashScreen splashScreen = null;
#endif
ILogger logger = null;
try
{
// Check if user wants to override the default Application Data location.
ApplicationCore.RegisterVitalCoreServices(mpOptions.DataDirectory);
#if !DEBUG
splashScreen = CreateSplashScreen();
splashScreen.ShowSplashScreen();
#endif
ApplicationCore.RegisterCoreServices();
logger = ServiceRegistration.Get<ILogger>();
#if !DEBUG
IPathManager pathManager = ServiceRegistration.Get<IPathManager>();
logPath = pathManager.GetPath("<LOG>");
#endif
UiExtension.RegisterUiServices();
}
catch (Exception e)
{
if (logger != null)
logger.Critical("Error starting application", e);
systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
ServiceRegistration.IsShuttingDown = true;
UiExtension.DisposeUiServices();
ApplicationCore.DisposeCoreServices();
throw;
}
// Start the core
logger.Debug("ApplicationLauncher: Starting application");
try
{
IPluginManager pluginManager = ServiceRegistration.Get<IPluginManager>();
pluginManager.Initialize();
pluginManager.Startup(false);
ApplicationCore.StartCoreServices();
ISkinEngine skinEngine = ServiceRegistration.Get<ISkinEngine>();
IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
IMediaAccessor mediaAccessor = ServiceRegistration.Get<IMediaAccessor>();
ILocalSharesManagement localSharesManagement = ServiceRegistration.Get<ILocalSharesManagement>();
// We have to handle some dependencies here in the start order:
// 1) After all plugins are loaded, the SkinEngine can initialize (=load all skin resources)
// 2) After the skin resources are loaded, the workflow manager can initialize (=load its states and actions)
// 3) Before the main window is shown, the splash screen should be hidden
// 4) After the workflow states and actions are loaded, the main window can be shown
// 5) After the skinengine triggers the first workflow state/startup screen, the default shortcuts can be registered
mediaAccessor.Initialize(); // Independent from other services
localSharesManagement.Initialize(); // After media accessor was initialized
skinEngine.Initialize(); // 1)
workflowManager.Initialize(); // 2)
//.........这里部分代码省略.........
示例12: Parse_strict_bad_input_fails_and_exits_with_verbs
public void Parse_strict_bad_input_fails_and_exits_with_verbs()
{
string invokedVerb = null;
object invokedVerbInstance = null;
var options = new OptionsWithVerbsNoHelp();
var testWriter = new StringWriter();
ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter);
var result = parser.ParseArgumentsStrict(new string[] { "bad", "input" }, options,
(verb, subOptions) =>
{
invokedVerb = verb;
invokedVerbInstance = subOptions;
},
() => Console.WriteLine("fake fail"));
result.Should().BeFalse();
var helpText = testWriter.ToString();
Console.WriteLine(helpText);
var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Did we really produced all help?
lines.Should().HaveCount(n => n == 8);
// Verify just significant output
lines[5].Trim().Should().Be("add Add file contents to the index.");
lines[6].Trim().Should().Be("commit Record changes to the repository.");
lines[7].Trim().Should().Be("clone Clone a repository into a new directory.");
invokedVerb.Should().Be("bad");
invokedVerbInstance.Should().BeNull();
}
示例13: Parse_strict_bad_input_fails_and_exits_with_verbs_when_get_usage_is_defined
public void Parse_strict_bad_input_fails_and_exits_with_verbs_when_get_usage_is_defined()
{
string invokedVerb = null;
object invokedVerbInstance = null;
var options = new OptionsWithVerbs();
var testWriter = new StringWriter();
ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter);
var result = parser.ParseArgumentsStrict(new string[] { "bad", "input" }, options,
(verb, subOptions) =>
{
invokedVerb = verb;
invokedVerbInstance = subOptions;
},
() => Console.WriteLine("fake fail"));
result.Should().BeFalse();
var helpText = testWriter.ToString();
Console.WriteLine(helpText);
var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Did we really produced all help?
lines.Should().HaveCount(n => n == 1);
// Verify just significant output
lines[0].Trim().Should().Be("verbs help index");
invokedVerb.Should().Be("bad");
invokedVerbInstance.Should().BeNull();
}
示例14: Main
public static void Main(string[] args)
{
options = new Options();
CommandLine.Parser parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2));
if (options.AccessKey == null || options.SecretKey == null)
{
Console.WriteLine(options.GetUsage());
Environment.Exit(-2);
}
try
{
// ListVolumes(); // got for testing connectivity
CheckForScheduledSnapshots();
CheckForExpiredSnapshots();
}
catch (Exception err)
{
Console.WriteLine("Error from " + err.Source + ": " + err.Message);
Environment.Exit(-2);
}
Environment.Exit(0);
}