本文整理汇总了C#中ConfigurationManager.PrintHelp方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationManager.PrintHelp方法的具体用法?C# ConfigurationManager.PrintHelp怎么用?C# ConfigurationManager.PrintHelp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigurationManager
的用法示例。
在下文中一共展示了ConfigurationManager.PrintHelp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static int Main(string [] args)
{
var configurationManager = new ConfigurationManager ();
if (!configurationManager.LoadCommandLineArgs (args))
return 1;
// Show the help and exit.
if (configurationManager.Help) {
configurationManager.PrintHelp ();
#if DEBUG
Console.WriteLine ("Press any key...");
Console.ReadKey ();
#endif
return 0;
}
// Show the version and exit.
if (configurationManager.Version) {
Version.Show ();
return 0;
}
if (!configurationManager.LoadConfigFile ())
return 1;
configurationManager.SetupLogger ();
#if DEBUG
// Log everything while debugging
Logger.Level = LogLevel.All;
#endif
Logger.Write (LogLevel.Debug, Assembly.GetExecutingAssembly ().GetName ().Name);
string configDir = configurationManager.ConfigDir;
if (String.IsNullOrEmpty (configDir)) {
Logger.Write (LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter");
return 1;
}
var configDirInfo = new DirectoryInfo (configDir);
if (!configDirInfo.Exists) {
Logger.Write (LogLevel.Error, "The configuration directory \"{0}\" does not exist!", configDir);
return 1;
}
Logger.Write (LogLevel.Debug, "Configuration directory exists, loading configuration files");
ChildrenManager.StartChildren (configDirInfo.GetFiles("*.xml"), configurationManager);
if (!configurationManager.Stoppable)
return 0;
Console.WriteLine ("Hit Return to stop the server.");
Console.ReadLine ();
ChildrenManager.TermChildren();
ChildrenManager.KillChildren();
return 0;
}
示例2: RealMain
//
// Parameters:
//
// args - original args passed to the program
// root - true means caller is in the root domain
// ext_apphost - used when single app mode is used, in a recursive call to
// RealMain from the single app domain
// quiet - don't show messages. Used to avoid double printing of the banner
//
public int RealMain(string [] args, bool root, IApplicationHost ext_apphost, bool v_quiet)
{
var configurationManager = new ConfigurationManager (v_quiet,
ext_apphost == null ? null : ext_apphost.Path);
if (!configurationManager.LoadCommandLineArgs (args))
return 1;
// Show the help and exit.
if (configurationManager.Help) {
configurationManager.PrintHelp ();
#if DEBUG
Console.WriteLine("Press any key...");
Console.ReadKey ();
#endif
return 0;
}
// Show the version and exit.
if (configurationManager.Version) {
Version.Show ();
return 0;
}
var hash = GetHash (args);
if (hash == -1) {
Logger.Write(LogLevel.Error, "Couldn't calculate hash - should have left earlier - something is really wrong");
return 1;
}
if (hash == -2) {
Logger.Write(LogLevel.Error, "Couldn't calculate hash - unrecognized parameter");
return 1;
}
if (!configurationManager.LoadConfigFile ())
return 1;
configurationManager.SetupLogger ();
ushort port = configurationManager.Port ?? 0;
bool useTCP = port != 0;
string lockfile = useTCP ? Path.Combine (Path.GetTempPath (), "mod_mono_TCP_") : configurationManager.Filename;
lockfile = String.Format ("{0}_{1}", lockfile, hash);
ModMonoWebSource webSource = useTCP
? new ModMonoTCPWebSource (configurationManager.Address, port, lockfile)
: new ModMonoWebSource (configurationManager.Filename, lockfile);
if(configurationManager.Terminate) {
if (configurationManager.Verbose)
Logger.Write (LogLevel.Notice, "Shutting down running mod-mono-server...");
bool res = webSource.GracefulShutdown ();
if (configurationManager.Verbose)
if (res)
Logger.Write (LogLevel.Notice, "Done");
else
Logger.Write (LogLevel.Error, "Failed.");
return res ? 0 : 1;
}
var server = new ApplicationServer (webSource, configurationManager.Root) {
Verbose = configurationManager.Verbose,
SingleApplication = !root
};
#if DEBUG
Console.WriteLine (Assembly.GetExecutingAssembly ().GetName ().Name);
#endif
if (configurationManager.Applications != null)
server.AddApplicationsFromCommandLine (configurationManager.Applications);
if (configurationManager.AppConfigFile != null)
server.AddApplicationsFromConfigFile (configurationManager.AppConfigFile);
if (configurationManager.AppConfigDir != null)
server.AddApplicationsFromConfigDirectory (configurationManager.AppConfigDir);
if (!configurationManager.Master && configurationManager.Applications == null
&& configurationManager.AppConfigDir == null && configurationManager.AppConfigFile == null)
server.AddApplicationsFromCommandLine ("/:."); // TODO: do we really want this?
VPathToHost vh = server.GetSingleApp ();
if (root && vh != null) {
// Redo in new domain
vh.CreateHost (server, webSource);
var svr = (Server)vh.AppHost.Domain.CreateInstanceAndUnwrap (GetType ().Assembly.GetName ().ToString (), GetType ().FullName);
webSource.Dispose ();
return svr.RealMain (args, false, vh.AppHost, configurationManager.Quiet);
}
//.........这里部分代码省略.........
示例3: Main
public static int Main (string [] args)
{
var configurationManager = new ConfigurationManager ("mono-fpm");
if (!configurationManager.LoadCommandLineArgs (args))
return 1;
// Show the help and exit.
if (configurationManager.Help) {
configurationManager.PrintHelp ();
#if DEBUG
Console.WriteLine ("Press any key...");
Console.ReadKey ();
#endif
return 0;
}
// Show the version and exit.
if (configurationManager.Version) {
Version.Show ();
return 0;
}
if (!configurationManager.LoadConfigFile ())
return 1;
configurationManager.SetupLogger ();
#if DEBUG
// Log everything while debugging
Logger.Level = LogLevel.All;
#endif
Logger.Write (LogLevel.Debug, Assembly.GetExecutingAssembly ().GetName ().Name);
string configDir = configurationManager.ConfigDir;
string webDir = configurationManager.WebDir;
if (String.IsNullOrEmpty (configDir) && (!Platform.IsUnix || String.IsNullOrEmpty (webDir))) {
if(Platform.IsUnix)
Logger.Write (LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter or web directories with the --web-dir parameter.");
else
Logger.Write (LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter.");
return 1;
}
if (!String.IsNullOrEmpty (configDir)) {
var configDirInfo = new DirectoryInfo (configDir);
if (!configDirInfo.Exists) {
Logger.Write (LogLevel.Error, "The configuration directory \"{0}\" does not exist!", configDir);
} else {
Logger.Write (LogLevel.Debug, "Configuration directory {0} exists, loading configuration files", configDir);
FileInfo[] configFiles = configDirInfo.GetFiles ("*.xml");
ChildrenManager.StartChildren (configFiles, configurationManager);
}
}
if (Platform.IsUnix && !String.IsNullOrEmpty (webDir)) {
var webDirInfo = new UnixDirectoryInfo (Path.GetFullPath (webDir));
if (!webDirInfo.Exists) {
Logger.Write (LogLevel.Error, "The web directory \"{0}\" does not exist!", webDir);
} else {
Logger.Write (LogLevel.Debug, "Web directory {0} exists, starting children", webDir);
IEnumerable<UnixDirectoryInfo> webDirs =
from entry in webDirInfo.GetFileSystemEntries ()
let dir = entry as UnixDirectoryInfo
where dir != null
select dir;
if (configurationManager.HttpdGroup == null) {
Logger.Write (LogLevel.Error, "Couldn't autodetect the httpd group, you must specify it explicitly with --httpd-group");
return 1;
}
if (!CheckGroupExists (configurationManager.FpmGroup) || !CheckGroupExists (configurationManager.HttpdGroup) || !CheckUserExists (configurationManager.FpmUser))
return 1;
ChildrenManager.StartAutomaticChildren (webDirs, configurationManager);
}
}
Platform.SetIdentity (configurationManager.FpmUser, configurationManager.FpmGroup);
if (!configurationManager.Stoppable) {
var sleep = new ManualResetEvent (false);
sleep.WaitOne (); // Do androids dream of electric sheep?
}
Console.WriteLine ("Hit Return to stop the server.");
Console.ReadLine ();
ChildrenManager.TermChildren();
ChildrenManager.KillChildren();
return 0;
}
示例4: DebugMain
/// <param name="args">Original args passed to the program.</param>
/// <param name="root">If set to <c>true</c> it means the caller is in the root domain.</param>
/// <param name="ext_apphost">Used when single app mode is used, in a recursive call to RealMain from the single app domain.</param>
/// <param name="quiet">If set to <c>true</c> don't show messages. Used to avoid double printing of the banner.</param>
internal CompatTuple<int, string, ApplicationServer> DebugMain (string [] args, bool root, IApplicationHost ext_apphost, bool quiet)
{
var configurationManager = new ConfigurationManager ("xsp", quiet);
var security = new SecurityConfiguration ();
if (!ParseOptions (configurationManager, args, security))
return new CompatTuple<int,string,ApplicationServer> (1, "Error while parsing options", null);
// Show the help and exit.
if (configurationManager.Help) {
configurationManager.PrintHelp ();
#if DEBUG
Console.WriteLine ("Press any key...");
Console.ReadKey ();
#endif
return success;
}
// Show the version and exit.
if (configurationManager.Version) {
Version.Show ();
return success;
}
if (!configurationManager.LoadConfigFile ())
return new CompatTuple<int,string,ApplicationServer> (1, "Error while loading the configuration file", null);
configurationManager.SetupLogger ();
WebSource webSource;
if (security.Enabled) {
try {
key = security.KeyPair;
webSource = new XSPWebSource (configurationManager.Address,
configurationManager.RandomPort ? default(ushort) : configurationManager.Port,
security.Protocol, security.ServerCertificate,
GetPrivateKey, security.AcceptClientCertificates,
security.RequireClientCertificates, !root);
}
catch (CryptographicException ce) {
Logger.Write (ce);
return new CompatTuple<int,string,ApplicationServer> (1, "Error while setting up https", null);
}
} else {
webSource = new XSPWebSource (configurationManager.Address, configurationManager.Port, !root);
}
var server = new ApplicationServer (webSource, configurationManager.Root) {
Verbose = configurationManager.Verbose,
SingleApplication = !root
};
if (configurationManager.Applications != null)
server.AddApplicationsFromCommandLine (configurationManager.Applications);
if (configurationManager.AppConfigFile != null)
server.AddApplicationsFromConfigFile (configurationManager.AppConfigFile);
if (configurationManager.AppConfigDir != null)
server.AddApplicationsFromConfigDirectory (configurationManager.AppConfigDir);
if (configurationManager.Applications == null && configurationManager.AppConfigDir == null && configurationManager.AppConfigFile == null)
server.AddApplicationsFromCommandLine ("/:.");
VPathToHost vh = server.GetSingleApp ();
if (root && vh != null) {
// Redo in new domain
vh.CreateHost (server, webSource);
var svr = (Server) vh.AppHost.Domain.CreateInstanceAndUnwrap (GetType ().Assembly.GetName ().ToString (), GetType ().FullName);
webSource.Dispose ();
return svr.DebugMain (args, false, vh.AppHost, configurationManager.Quiet);
}
server.AppHost = ext_apphost;
if (!configurationManager.Quiet) {
Logger.Write(LogLevel.Notice, Assembly.GetExecutingAssembly().GetName().Name);
Logger.Write(LogLevel.Notice, "Listening on address: {0}", configurationManager.Address);
Logger.Write(LogLevel.Notice, "Root directory: {0}", configurationManager.Root);
}
try {
if (!server.Start (!configurationManager.NonStop, (int)configurationManager.Backlog))
return new CompatTuple<int,string,ApplicationServer> (2, "Error while starting server", server);
if (!configurationManager.Quiet) {
// MonoDevelop depends on this string. If you change it, let them know.
Logger.Write(LogLevel.Notice, "Listening on port: {0} {1}", server.Port, security);
}
if (configurationManager.RandomPort && !configurationManager.Quiet)
Logger.Write (LogLevel.Notice, "Random port: {0}", server.Port);
if (!configurationManager.NonStop) {
if (!configurationManager.Quiet)
Console.WriteLine ("Hit Return to stop the server.");
//.........这里部分代码省略.........
示例5: Main
public static int Main(string[] args)
{
if (Platform.IsUnix) {
uint uid = Syscall.geteuid ();
uint gid = Syscall.getegid ();
Platform.SetIdentity (uid, gid);
}
var configurationManager = new ConfigurationManager ("fastcgi-mono-server");
if (!configurationManager.LoadCommandLineArgs (args))
return 1;
// Show the help and exit.
if (configurationManager.Help) {
configurationManager.PrintHelp ();
#if DEBUG
Console.WriteLine ("Press any key...");
Console.ReadKey ();
#endif
return 0;
}
// Show the version and exit.
if (configurationManager.Version) {
Version.Show ();
return 0;
}
if (!configurationManager.LoadConfigFile ())
return 1;
configurationManager.SetupLogger ();
#if DEBUG
// Log everything while debugging
Logger.Level = LogLevel.All;
#endif
Logger.Write (LogLevel.Debug, Assembly.GetExecutingAssembly ().GetName ().Name);
Platform.LogIdentity ();
string root_dir;
if (!TryGetRootDirectory (configurationManager, out root_dir))
return 1;
CreateAppServer (configurationManager, root_dir);
if (!TryLoadApplicationsConfig (configurationManager))
return 1;
IServer server;
if (configurationManager.OnDemand) {
Socket socket;
Uri uri;
if (!TryCreateOnDemandSocket (configurationManager.OnDemandSock, out socket, out uri))
return 1;
server = CreateOnDemandServer (configurationManager, socket);
CreateWatchdog (configurationManager, server);
} else {
Socket socket;
if (!TryCreateSocket (configurationManager, out socket))
return 1;
server = new ServerProxy (CreateServer (configurationManager, socket));
}
var stoppable = configurationManager.Stoppable;
if (!server.Start (stoppable, (int)configurationManager.Backlog)) {
Logger.Write (LogLevel.Error, "Failed to start server!");
return 1;
}
if (stoppable) {
Console.WriteLine (
"Hit Return to stop the server.");
Console.ReadLine ();
server.Stop ();
}
return 0;
}