本文整理汇总了C#中CommandLineArguments类的典型用法代码示例。如果您正苦于以下问题:C# CommandLineArguments类的具体用法?C# CommandLineArguments怎么用?C# CommandLineArguments使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandLineArguments类属于命名空间,在下文中一共展示了CommandLineArguments类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommandLineArgumentsConstructor_NullParameter_EmptyDictionary
public void CommandLineArgumentsConstructor_NullParameter_EmptyDictionary()
{
IEnumerable<string> args = null;
CommandLineArguments target = new CommandLineArguments(args);
Assert.AreEqual(0, target.Count);
}
示例2: CommandLineArgumentsConstructor_AllValuesWithNoArgumentName_ValuesIncludedInOneKey
public void CommandLineArgumentsConstructor_AllValuesWithNoArgumentName_ValuesIncludedInOneKey()
{
IEnumerable<string> args = @"0 1 2 3".Split(' ');
CommandLineArguments target = new CommandLineArguments(args);
Assert.AreEqual(1, target.Count);
}
示例3: Empty
public void Empty()
{
CommandLineArguments args = new CommandLineArguments();
string[] cmdLine = new string[]
{
//@"/path:c:\windows"
};
if (!CommandLineParser.ParseArgumentsWithUsage(cmdLine, args))
{
Assert.Fail();
}
Assert.AreEqual(false, args.AddHost);
Assert.AreEqual(null, args.ApplicationPath);
Assert.AreEqual(null, args.HostName);
Assert.AreEqual(null, args.IPAddress);
Assert.AreEqual(IPMode.Loopback, args.IPMode);
Assert.AreEqual(false, args.IPv6);
Assert.AreEqual(false, args.Nodirlist);
Assert.AreEqual(false, args.Ntlm);
Assert.AreEqual(0, args.Port);
Assert.AreEqual(PortMode.FirstAvailable, args.PortMode);
Assert.AreEqual(65535, args.PortRangeEnd);
Assert.AreEqual(32768, args.PortRangeStart);
Assert.AreEqual(RunMode.Server, args.RunMode);
Assert.AreEqual(false, args.Silent);
Assert.AreEqual(0, args.TimeOut);
Assert.AreEqual("/", args.VirtualPath);
Assert.AreEqual(0, args.WaitForPort);
Assert.AreEqual("/v:\"/\"", args.ToString());
}
示例4: ProcessArguments
private static CommandLineArguments ProcessArguments(string[] arguments)
{
var commandLineArguments = new CommandLineArguments();
int current = 0;
for (; current < arguments.Length; current++)
{
string argument = arguments[current];
if (argument.Length > 0 && (argument[0] == '/' || argument[0] == '-'))
{
string argumentFlag = argument.Substring(1);
if (argumentFlag == "debug")
{
commandLineArguments.Debug = true;
}
else if (argumentFlag == "profile")
{
commandLineArguments.Profile = true;
}
else
{
break;
}
}
else
{
break;
}
}
commandLineArguments.ArgumentsStart = current;
return commandLineArguments;
}
示例5: Main
private static void Main(string[] args)
{
CommandLineArguments commandLineArgs = new CommandLineArguments(args);
string hostFormatString = "http://{0}:{1}";
string owinAddress = String.Format(hostFormatString, commandLineArgs.AllowRemote ? "+" : "localhost", commandLineArgs.Port);
string visibleHost = (commandLineArgs.AllowRemote) ? Environment.MachineName : "localhost";
string visibleAddress = String.Format(hostFormatString, visibleHost, commandLineArgs.Port);
PortManager.OpenPortInFirewall(commandLineArgs.Port);
OwinSelfhostStartup.Startup(owinAddress);
Console.WriteLine("The Bridge is listening at {0} with remote access {1}", visibleAddress, commandLineArgs.AllowRemote ? "enabled" : "disabled");
Test(visibleHost, commandLineArgs.Port);
while (true)
{
Console.WriteLine("Type \"exit\" to stop the Bridge.");
string answer = Console.ReadLine();
if (String.Equals(answer, "exit", StringComparison.OrdinalIgnoreCase))
{
break;
}
}
Environment.Exit(0);
}
示例6: Main
private static void Main(string[] args)
{
CommandLineArguments commandLineArgs = new CommandLineArguments(args);
string hostFormatString = "http://{0}:{1}";
string owinAddress = String.Format(hostFormatString, commandLineArgs.AllowRemote ? "+" : "localhost", commandLineArgs.Port);
string visibleHost = (commandLineArgs.AllowRemote) ? Environment.MachineName : "localhost";
string visibleAddress = String.Format(hostFormatString, visibleHost, commandLineArgs.Port);
// Configure the remote addresses the firewall rules will accept.
// If remote access is not allowed, specifically disallow remote addresses
PortManager.RemoteAddresses = commandLineArgs.AllowRemote ? commandLineArgs.RemoteAddresses : String.Empty;
// Initialize the BridgeConfiguration from command line.
// The first POST to the ConfigController will supply the rest.
ConfigController.BridgeConfiguration.BridgeHost = visibleHost;
ConfigController.BridgeConfiguration.BridgePort = commandLineArgs.Port;
// Remove any pre-existing firewall rules the Bridge may have added
// in past runs. We normally cleanup on exit but could have been
// aborted.
PortManager.RemoveAllBridgeFirewallRules();
// Open the port used to communicate with the Bridge itself
PortManager.OpenPortInFirewall(commandLineArgs.Port);
Console.WriteLine("Starting the Bridge at {0}", visibleAddress);
OwinSelfhostStartup.Startup(owinAddress);
Test(visibleHost, commandLineArgs.Port);
while (true)
{
Console.WriteLine("The Bridge is listening at {0}", visibleAddress);
if (commandLineArgs.AllowRemote)
{
Console.WriteLine("Remote access is allowed from '{0}'", commandLineArgs.RemoteAddresses);
}
else
{
Console.WriteLine("Remote access is disabled.");
}
Console.WriteLine("Current configuration is:{0}{1}", Environment.NewLine, ConfigController.BridgeConfiguration.ToString());
Console.WriteLine("Type \"exit\" to stop the Bridge.");
string answer = Console.ReadLine();
if (String.Equals(answer, "exit", StringComparison.OrdinalIgnoreCase))
{
break;
}
}
Environment.Exit(0);
}
示例7: Process
/// <summary>
/// Parses the command line arguments for valid options and returns them.
/// </summary>
/// <param name="CommandLineArgs">Array of strings containing the command line arguments</param>
/// <returns>CommandLineArguments structure holding the options from the command line</returns>
/// <history>
/// [Curtis_Beard] 07/26/2006 Created
/// [Curtis_Beard] 05/08/2007 ADD: 1590157, support project file
/// </history>
public static CommandLineArguments Process(string[] CommandLineArgs)
{
// create the args structure and initialize it
CommandLineArguments args = new CommandLineArguments();
InitializeArgs(ref args);
// process the command line
Arguments myArgs = new Arguments(CommandLineArgs);
// check for just a single directory / project file
if (CommandLineArgs.Length == 2)
{
args.AnyArguments = true;
// Check command line for a path to start at
string arg1 = CommandLineArgs[1];
// remove an extra quote if (a drive letter
if (arg1.EndsWith("\""))
arg1 = arg1.Substring(0, arg1.Length - 1);
// check for a project file
if (arg1.EndsWith(".agproj"))
{
args.ProjectFile = arg1;
args.IsProjectFile = true;
}
// check for a directory
if (!args.IsProjectFile && System.IO.Directory.Exists(arg1))
{
args.StartPath = arg1;
args.IsValidStartPath = true;
}
// do this before setting defaults to prevent loading wrong config file.
if (!args.IsValidStartPath && !args.IsProjectFile)
{
// check for some other single setting, such as /local
ProcessFlags(myArgs, ref args);
}
}
else if (CommandLineArgs.Length > 1)
{
args.AnyArguments = true;
ProcessFlags(myArgs, ref args);
}
return args;
}
示例8: App
public App()
{
// Add Ctrl+Shift+Z as a redo command. Don't know why it isn't enabled by default.
ApplicationCommands.Redo.InputGestures.Add(new KeyGesture(Key.Z, ModifierKeys.Control | ModifierKeys.Shift));
var cmdArgs = Environment.GetCommandLineArgs().Skip(1);
App.CommandLineArguments = new CommandLineArguments(cmdArgs);
if (App.CommandLineArguments.SingleInstance ?? true) {
cmdArgs = cmdArgs.Select(FullyQualifyPath);
string message = string.Join(Environment.NewLine, cmdArgs);
if (SendToPreviousInstance("dnSpy:\r\n" + message, !App.CommandLineArguments.NoActivate)) {
Environment.Exit(0);
}
}
InitializeComponent();
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
// Don't use DirectoryCatalog, that causes problems if the plugins are from the Internet zone
// see http://stackoverflow.com/questions/8063841/mef-loading-plugins-from-a-network-shared-folder
string appPath = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName);
foreach (string plugin in Directory.GetFiles(appPath, "*.Plugin.dll")) {
string shortName = Path.GetFileNameWithoutExtension(plugin);
try {
var asm = Assembly.Load(shortName);
asm.GetTypes();
catalog.Catalogs.Add(new AssemblyCatalog(asm));
} catch (Exception ex) {
// Cannot show MessageBox here, because WPF would crash with a XamlParseException
// Remember and show exceptions in text output, once MainWindow is properly initialized
StartupExceptions.Add(new ExceptionData { Exception = ex, PluginName = shortName });
}
}
compositionContainer = new CompositionContainer(catalog);
Languages.Initialize(compositionContainer);
if (!System.Diagnostics.Debugger.IsAttached) {
AppDomain.CurrentDomain.UnhandledException += ShowErrorBox;
Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
}
TaskScheduler.UnobservedTaskException += DotNet40_UnobservedTaskException;
EventManager.RegisterClassHandler(typeof(Window),
Hyperlink.RequestNavigateEvent,
new RequestNavigateEventHandler(Window_RequestNavigate));
FixEditorContextMenuStyle();
}
示例9: Main
private static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(BridgeUnhandledExceptionHandler);
CommandLineArguments commandLineArgs = new CommandLineArguments(args);
Console.WriteLine("Bridge.exe was launched with:{0}{1}",
Environment.NewLine, commandLineArgs.ToString());
// If asked to ping (not the default), just ping and return an exit code indicating its state
if (commandLineArgs.Ping)
{
string errorMessage = null;
if (PingBridge(commandLineArgs.BridgeConfiguration.BridgeHost,
commandLineArgs.BridgeConfiguration.BridgePort,
out errorMessage))
{
Console.WriteLine("The Bridge is running.");
Environment.Exit(0);
}
else
{
Console.WriteLine("The Bridge is not running: {0}", errorMessage);
Environment.Exit(1);
}
}
if (commandLineArgs.StopIfLocal)
{
StopBridgeIfLocal(commandLineArgs);
Environment.Exit(0);
}
if (commandLineArgs.Stop)
{
StopBridge(commandLineArgs);
Environment.Exit(0);
}
if (commandLineArgs.Reset)
{
ResetBridge(commandLineArgs);
Environment.Exit(0);
}
if (commandLineArgs.RequireBridgeTimeoutSeconds.HasValue)
{
RequireBridge(commandLineArgs);
}
// Default action is starting the Bridge
StartBridge(commandLineArgs);
}
示例10: QuotedValuesInToString
public void QuotedValuesInToString()
{
CommandLineArguments args = new CommandLineArguments();
string[] cmdLine = new string[]
{
@"/port:32768",
@"/path:c:\temp foo",
@"/vpath:/myapp with spaces",
@"/ntlm",
@"/silent",
@"/nodirlist"
};
if (!CommandLineParser.ParseArgumentsWithUsage(cmdLine, args))
{
Assert.Fail();
}
Assert.AreEqual(false, args.AddHost);
Assert.AreEqual(@"c:\temp foo", args.ApplicationPath);
Assert.AreEqual(null, args.HostName);
Assert.AreEqual(null, args.IPAddress);
Assert.AreEqual(IPMode.Loopback, args.IPMode);
Assert.AreEqual(false, args.IPv6);
Assert.AreEqual(true, args.Nodirlist);
Assert.AreEqual(true, args.Ntlm);
Assert.AreEqual(32768, args.Port);
Assert.AreEqual(PortMode.FirstAvailable, args.PortMode);
Assert.AreEqual(65535, args.PortRangeEnd);
Assert.AreEqual(32768, args.PortRangeStart);
Assert.AreEqual(RunMode.Server, args.RunMode);
Assert.AreEqual(true, args.Silent);
Assert.AreEqual(0, args.TimeOut);
Assert.AreEqual("/myapp with spaces", args.VirtualPath);
Assert.AreEqual(0, args.WaitForPort);
Assert.AreEqual("/a:\"c:\\temp foo\" /v:\"/myapp with spaces\" /p:32768 /ntlm /silent /nodirlist", args.ToString());
}
示例11: Main
private static void Main(string[] args)
{
CommandLineArguments commandLineArgs = new CommandLineArguments(args);
Console.WriteLine("Specified BridgeConfiguration is:{0}{1}",
Environment.NewLine, commandLineArgs.BridgeConfiguration.ToString());
// If asked to ping (not the default), just ping and return an exit code indicating its state
if (commandLineArgs.Ping)
{
string errorMessage = null;
if (PingBridge(commandLineArgs.BridgeConfiguration.BridgeHost,
commandLineArgs.BridgeConfiguration.BridgePort,
out errorMessage))
{
Console.WriteLine("The Bridge is running.");
Environment.Exit(0);
}
else
{
Console.WriteLine("The Bridge is not running: {0}", errorMessage);
Environment.Exit(1);
}
}
else if (commandLineArgs.StopIfLocal)
{
StopBridgeIfLocal(commandLineArgs);
}
else if (commandLineArgs.Stop)
{
StopBridge(commandLineArgs);
}
else
{
// Default action is starting the Bridge
StartBridge(commandLineArgs);
}
}
示例12: GetImports
// TODO (https://github.com/dotnet/roslyn/issues/5854): remove
public static ImmutableArray<string> GetImports(CommandLineArguments args)
{
return args.CompilationOptions.GetImports();
}
示例13: GetScriptOptions
private static ScriptOptions GetScriptOptions(CommandLineArguments arguments, string scriptPathOpt, CommonMessageProvider messageProvider, List<DiagnosticInfo> diagnostics)
{
var touchedFilesLoggerOpt = (arguments.TouchedFilesPath != null) ? new TouchedFileLogger() : null;
var metadataResolver = GetMetadataReferenceResolver(arguments, touchedFilesLoggerOpt);
var sourceResolver = GetSourceReferenceResolver(arguments, touchedFilesLoggerOpt);
var resolvedReferences = new List<MetadataReference>();
if (!arguments.ResolveMetadataReferences(metadataResolver, diagnostics, messageProvider, resolvedReferences))
{
// can't resolve some references
return null;
}
return new ScriptOptions(
filePath: scriptPathOpt ?? "",
references: ImmutableArray.CreateRange(resolvedReferences),
namespaces: CommandLineHelpers.GetImports(arguments),
metadataResolver: metadataResolver,
sourceResolver: sourceResolver);
}
示例14: ResetBridge
// Asks the Bridge to release all its resources but continue running
private static void ResetBridge(CommandLineArguments commandLineArgs)
{
string errorMessage = null;
if (!PingBridge(commandLineArgs.BridgeConfiguration.BridgeHost,
commandLineArgs.BridgeConfiguration.BridgePort,
out errorMessage))
{
Console.WriteLine("The Bridge is not running: {0}", errorMessage);
Environment.Exit(0);
}
string bridgeUrl = String.Format("http://{0}:{1}/Resource", commandLineArgs.BridgeConfiguration.BridgeHost, commandLineArgs.BridgeConfiguration.BridgePort);
string problem = null;
Console.WriteLine("Resetting the Bridge by sending DELETE request to {0}", bridgeUrl);
// We reset the Bridge using a DELETE request to the /resource endpoint.
using (HttpClient httpClient = new HttpClient())
{
try
{
var response = httpClient.DeleteAsync(bridgeUrl).GetAwaiter().GetResult();
if (!response.IsSuccessStatusCode)
{
problem = String.Format("{0}Bridge returned unexpected status code='{1}', reason='{2}'",
Environment.NewLine, response.StatusCode, response.ReasonPhrase);
if (response.Content != null)
{
string contentAsString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
if (contentAsString.Length > 1000)
{
contentAsString = contentAsString.Substring(0, 999) + "...";
}
problem = String.Format("{0}, content:{1}{2}",
problem, Environment.NewLine, contentAsString);
}
}
}
catch (Exception ex)
{
problem = ex.ToString();
}
}
if (problem != null)
{
Console.WriteLine("A problem was encountered resetting the Bridge:{0}{1}",
Environment.NewLine, problem);
Console.WriteLine("Forcing local resource cleanup...");
}
// A successfull DELETE will have cleaned up all firewall rules,
// certificates, etc. So when using localhost, this cleanup will
// be redundant and harmless. When the Bridge is running remotely,
// this cleanup will remove all firewall rules and certificates we
// installed on the current machine to talk with that Bridge.
BridgeController.ReleaseAllResources(force: false);
}
示例15: StartBridge
// Starts the Bridge locally if it is not already running.
private static void StartBridge(CommandLineArguments commandLineArgs)
{
string errorMessage = null;
if (PingBridge(commandLineArgs.BridgeConfiguration.BridgeHost,
commandLineArgs.BridgeConfiguration.BridgePort,
out errorMessage))
{
Console.WriteLine("The Bridge is already running.");
Environment.Exit(0);
}
// The host is not local so we cannot start the Bridge
if (!IsBridgeHostLocal(commandLineArgs.BridgeConfiguration))
{
Console.WriteLine("The Bridge cannot be started from this machine on {0}",
commandLineArgs.BridgeConfiguration.BridgeHost);
Environment.Exit(1);
}
string resourceFolder = commandLineArgs.BridgeConfiguration.BridgeResourceFolder;
if (String.IsNullOrWhiteSpace(resourceFolder))
{
Console.WriteLine("Starting the Bridge requires the BridgeResourceFolder to be specified.");
Console.WriteLine("Use either -BridgeResourceFolder:folderName or set it as an environment variable.");
Environment.Exit(1);
}
resourceFolder = Path.GetFullPath(resourceFolder);
if (!Directory.Exists(resourceFolder))
{
Console.WriteLine("The specified BridgeResourceFolder '{0}' does not exist.");
Environment.Exit(1);
}
commandLineArgs.BridgeConfiguration.BridgeResourceFolder = resourceFolder;
int port = commandLineArgs.BridgeConfiguration.BridgePort;
string hostFormatString = "http://{0}:{1}";
string owinAddress = String.Format(hostFormatString, commandLineArgs.AllowRemote ? "+" : "localhost", port);
string visibleHost = (commandLineArgs.AllowRemote) ? Environment.MachineName : "localhost";
string visibleAddress = String.Format(hostFormatString, visibleHost, port);
// Configure the remote addresses the firewall rules will accept.
// If remote access is not allowed, specifically disallow remote addresses
PortManager.RemoteAddresses = commandLineArgs.AllowRemote ? commandLineArgs.RemoteAddresses : String.Empty;
// Initialize the BridgeConfiguration from command line.
ConfigController.BridgeConfiguration = commandLineArgs.BridgeConfiguration;
ConfigController.BridgeConfiguration.BridgeHost = visibleHost;
// Remove any pre-existing firewall rules or certificates the Bridge
// may have added in past runs. We normally clean them up on exit but
// it is possible a prior Bridge process was terminated prematurely.
BridgeController.ReleaseAllResources(force: false);
Console.WriteLine("Starting the Bridge at {0}", visibleAddress);
OwinSelfhostStartup.Startup(owinAddress);
// Now test whether the Bridge is running. Failure cleans up
// all resources and terminates the process.
if (!PingBridge(visibleHost, port, out errorMessage))
{
Console.WriteLine("The Bridge failed to start or is not responding: {0}", errorMessage);
BridgeController.StopBridgeProcess(1);
}
while (true)
{
Console.WriteLine();
Console.WriteLine("The Bridge is running");
Console.WriteLine(" Listening at {0}/{1}",
visibleAddress, BridgeControllerEndpoint);
if (commandLineArgs.AllowRemote)
{
Console.WriteLine(" Remote access is allowed from '{0}'", commandLineArgs.RemoteAddresses);
}
else
{
Console.WriteLine(" Remote access is disabled.");
}
Console.WriteLine(" Commands:");
Console.WriteLine(" \"cls\" to clear the screen");
Console.WriteLine(" \"exit\" to stop the Bridge");
Console.WriteLine();
Console.Write("Bridge> ");
string answer = Console.ReadLine();
if (string.Equals(answer, "exit", StringComparison.OrdinalIgnoreCase))
{
break;
}
else if (string.Equals(answer, "cls", StringComparison.OrdinalIgnoreCase))
{
Console.Clear();
}
}
//.........这里部分代码省略.........