本文整理汇总了C#中ConfigurationManager.LoadCommandLineArgs方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationManager.LoadCommandLineArgs方法的具体用法?C# ConfigurationManager.LoadCommandLineArgs怎么用?C# ConfigurationManager.LoadCommandLineArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigurationManager
的用法示例。
在下文中一共展示了ConfigurationManager.LoadCommandLineArgs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
{
// Load the configuration file stored in the
// executable's resources.
configmanager = new ConfigurationManager (
typeof(MainClass).Assembly,
"ConfigurationManager.xml");
configmanager.LoadCommandLineArgs (args);
// Show the help and exit.
if ((bool)configmanager ["help"] || (bool)configmanager ["?"]) {
ShowHelp ();
return 0;
}
// Show the version and exit.
if ((bool)configmanager ["version"]) {
ShowVersion ();
return 0;
}
string config = (string) configmanager ["config"];
if (config == null) {
Console.WriteLine ("You must pass /config=<filename> option. See 'help' for more info");
return 1;
}
try {
string config_file = (string)configmanager ["configfile"];
if (config_file != null) configmanager.LoadXmlConfig (config_file);
} catch (ApplicationException e) {
Console.WriteLine (e.Message);
return 1;
} catch (System.Xml.XmlException e) {
Console.WriteLine ("Error reading XML configuration: {0}", e.Message);
return 1;
}
try {
string log_level = (string) configmanager ["loglevels"];
if (log_level != null)
Logger.Level = (LogLevel) Enum.Parse (typeof(LogLevel), log_level);
} catch {
Console.WriteLine ("Failed to parse log levels.");
Console.WriteLine ("Using default levels: {0}", Logger.Level);
}
// Enable console logging during Main ().
Logger.WriteToConsole = true;
try {
string log_file = (string) configmanager ["logfile"];
if (log_file != null) Logger.Open (log_file);
} catch (Exception e) {
Logger.Write (LogLevel.Error, "Error opening log file: {0}", e.Message);
Logger.Write (LogLevel.Error,"Events will not be logged.");
}
Logger.Write (LogLevel.Debug,
Assembly.GetExecutingAssembly ().GetName ().Name);
bool auto_map = false; //(bool) configmanager ["automappaths"];
string applications = (string) configmanager ["applications"];
string app_config_file;
string app_config_dir;
try {
app_config_file = (string) configmanager ["appconfigfile"];
app_config_dir = (string) configmanager ["appconfigdir"];
} catch (ApplicationException e) {
Logger.Write (LogLevel.Error, e.Message);
return 1;
}
// server.MaxConnections = (ushort)
// configmanager ["maxconns"];
// server.MaxRequests = (ushort)
// configmanager ["maxreqs"];
// server.MultiplexConnections = (bool)
// configmanager ["multiplex"];
// Logger.Write (LogLevel.Debug, "Max connections: {0}",
// server.MaxConnections);
// Logger.Write (LogLevel.Debug, "Max requests: {0}",
// server.MaxRequests);
// Logger.Write (LogLevel.Debug, "Multiplex connections: {0}",
// server.MultiplexConnections);
bool stopable = (bool)configmanager ["stopable"];
Logger.WriteToConsole = (bool)configmanager ["printlog"];
List<ConfigInfo> serverConfigs = ConfigUtils.GetConfigsFromFile (config, "server", typeof(AppServerConfig));
if (serverConfigs.Count != 1) {
if (serverConfigs.Count == 0) {
//.........这里部分代码省略.........
示例4: 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;
}
示例5: ParseOptions
static bool ParseOptions (ConfigurationManager manager, string[] args, SecurityConfiguration security)
{
if (!manager.LoadCommandLineArgs (args))
return false;
// TODO: add mutual exclusivity rules
if(manager.Https)
security.Enabled = true;
if (manager.HttpsClientAccept) {
security.Enabled = true;
security.AcceptClientCertificates = true;
security.RequireClientCertificates = false;
}
if (manager.HttpsClientRequire) {
security.Enabled = true;
security.AcceptClientCertificates = true;
security.RequireClientCertificates = true;
}
if (manager.P12File != null)
security.Pkcs12File = manager.P12File;
if(manager.Cert != null)
security.CertificateFile = manager.Cert;
if (manager.PkFile != null)
security.PvkFile = manager.PkFile;
if (manager.PkPwd != null)
security.Password = manager.PkPwd;
security.Protocol = manager.Protocols;
int minThreads = manager.MinThreads ?? 0;
if(minThreads > 0)
ThreadPool.SetMinThreads (minThreads, minThreads);
if(!String.IsNullOrEmpty(manager.PidFile))
try {
using (StreamWriter sw = File.CreateText (manager.PidFile)) {
sw.Write (Process.GetCurrentProcess ().Id);
}
} catch (Exception ex) {
Logger.Write (LogLevel.Error, "Failed to write pidfile {0}: {1}", manager.PidFile,
ex.Message);
}
if(manager.NoHidden)
MonoWorkerRequest.CheckFileAccess = false;
return true;
}
示例6: 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;
}