本文整理汇总了C#中IConfigSource.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# IConfigSource.Merge方法的具体用法?C# IConfigSource.Merge怎么用?C# IConfigSource.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConfigSource
的用法示例。
在下文中一共展示了IConfigSource.Merge方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadConfig
public static IConfigSource LoadConfig(IConfigSource source)
{
string iniFileName = source.Configs["Startup"].GetString("inifile", CONFIG_FILE);
string iniFilePath = Path.Combine(Util.configDir(), iniFileName);
source.Merge(DefaultConfig());
if (!File.Exists(iniFilePath))
{
m_log.FatalFormat("[CONFIG]: File {0} not found, could not load any configuration.", iniFilePath);
m_log.FatalFormat("[CONFIG]: Did you copy the AssetInventoryServer.ini.example file to AssetInventoryServer.ini?");
Environment.Exit(1);
}
source.Merge(new IniConfigSource(iniFilePath));
return source;
}
示例2: LoadConfigSettings
/// <summary>
/// Loads the region configuration
/// </summary>
/// <param name="argvSource">Parameters passed into the process when started</param>
/// <param name="configSettings"></param>
/// <param name="networkInfo"></param>
/// <returns>A configuration that gets passed to modules</returns>
public IConfigSource LoadConfigSettings()
{
bool iniFileExists = false;
List<string> sources = new List<string>();
string iniFileName = "OpenSim.ini";
string iniFilePath = Path.Combine(".", iniFileName);
if (IsUri(iniFileName))
{
if (!sources.Contains(iniFileName))
sources.Add(iniFileName);
}
else
{
if (File.Exists(iniFilePath))
{
if (!sources.Contains(iniFilePath))
sources.Add(iniFilePath);
}
}
m_config = new IniConfigSource();
m_config.Merge(DefaultConfig());
m_log.Info("[CONFIG] Reading configuration settings");
if (sources.Count == 0)
{
m_log.FatalFormat("[CONFIG] Could not load any configuration");
m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
Environment.Exit(1);
}
for (int i = 0 ; i < sources.Count ; i++)
{
if (ReadConfig(sources[i]))
iniFileExists = true;
AddIncludes(sources);
}
if (!iniFileExists)
{
m_log.FatalFormat("[CONFIG] Could not load any configuration");
m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!");
Environment.Exit(1);
}
return m_config;
}
示例3: ReadConfig
/// <summary>
/// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
/// </summary>
/// <param name="iniPath">Full path to the ini</param>
/// <param name="i"></param>
/// <param name="source"></param>
/// <returns></returns>
private bool ReadConfig(string iniPath, int i, IConfigSource source)
{
bool success = false;
if (!IsUri(iniPath))
{
if (showIniLoading)
Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
Util.BasePathCombine(iniPath)));
source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
if (inidbg)
{
WriteConfigFile(i, source);
}
success = true;
}
else
{
// The ini file path is a http URI
// Try to read it
try
{
string file = Utilities.Utilities.ReadExternalWebsite(iniPath);
string filename = Path.GetTempFileName();
File.WriteAllText(filename, file);
if (showIniLoading)
Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
Util.BasePathCombine(iniPath)));
source.Merge(new IniConfigSource(filename, IniFileType.AuroraStyle));
if (inidbg)
{
WriteConfigFile(i, source);
}
File.Delete(filename);
success = true;
}
catch (Exception e)
{
Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
Environment.Exit(1);
}
}
return success;
}
示例4: LoadConfigSettings
//.........这里部分代码省略.........
string iniFileName =
startupConfig.GetString("inifile", "OpenSim.ini");
//Be mindful of these when modifying...
//1) When file A includes file B, if the same directive is found in both, that the value in file B wins.
//2) That inifile may be used with or without inimaster being used.
//3) That any values for directives pulled in via inifile (Config Set 2) override directives of the same name found in the directive set (Config Set 1) created by reading in bin/Opensim.ini and its subsequently included files or that created by reading in whatever file inimaster points to and its subsequently included files.
if (IsUri(masterFileName))
{
if (!sources.Contains(masterFileName))
sources.Add(masterFileName);
}
else
{
string masterFilePath = Path.GetFullPath(
Path.Combine(Util.configDir(), masterFileName));
if (masterFileName != String.Empty &&
File.Exists(masterFilePath) &&
(!sources.Contains(masterFilePath)))
sources.Add(masterFilePath);
if (iniFileName == "") //Then it doesn't exist and we need to set this
Application.iniFilePath = masterFilePath;
}
if (iniFileName != "")
{
if (IsUri(iniFileName))
{
if (!sources.Contains(iniFileName))
sources.Add(iniFileName);
Application.iniFilePath = iniFileName;
}
else
{
Application.iniFilePath = Path.GetFullPath(
Path.Combine(Util.configDir(), iniFileName));
if (File.Exists(Application.iniFilePath))
{
if (!sources.Contains(Application.iniFilePath))
sources.Add(Application.iniFilePath);
}
}
}
string iniDirName =
startupConfig.GetString("inidirectory", "");
string iniDirPath =
Path.Combine(Util.configDir(), iniDirName);
if (Directory.Exists(iniDirPath) && iniDirName != "")
{
m_log.InfoFormat("Searching folder {0} for config ini files",
iniDirPath);
string[] fileEntries = Directory.GetFiles(iniDirName);
foreach (string filePath in fileEntries)
{
if (Path.GetExtension(filePath).ToLower() == ".ini")
{
if (!sources.Contains(Path.GetFullPath(filePath)))
sources.Add(Path.GetFullPath(filePath));
}
}
}
m_config = new IniConfigSource();
m_log.Info("[CONFIG]: Reading configuration settings");
if (sources.Count == 0)
{
m_log.FatalFormat("[CONFIG]: Could not load any configuration");
m_log.FatalFormat("[CONFIG]: Did you copy the OpenSim.ini.example file to OpenSim.ini?");
throw new NotSupportedException();
}
for (int i = 0 ; i < sources.Count ; i++)
{
if (ReadConfig(sources[i], i))
iniFileExists = true;
AddIncludes(sources, ref i);
}
if (!iniFileExists)
{
m_log.FatalFormat("[CONFIG]: Could not load any configuration");
m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
throw new NotSupportedException();
}
// Make sure command line options take precedence
m_config.Merge(argvSource);
return m_config;
}
示例5: LoadConfigSettings
//.........这里部分代码省略.........
{
bool iniFileExists = false;
IConfig startupConfig = argvSource.Configs["Startup"];
List<string> sources = new List<string>();
string masterFileName =
startupConfig.GetString("inimaster", String.Empty);
if (IsUri(masterFileName))
{
if (!sources.Contains(masterFileName))
sources.Add(masterFileName);
}
else
{
string masterFilePath = Path.GetFullPath(
Path.Combine(Util.configDir(), masterFileName));
if (masterFileName != String.Empty &&
File.Exists(masterFilePath) &&
(!sources.Contains(masterFilePath)))
sources.Add(masterFilePath);
}
string iniFileName =
startupConfig.GetString("inifile", "OpenSim.ini");
if (IsUri(iniFileName))
{
if (!sources.Contains(iniFileName))
sources.Add(iniFileName);
Application.iniFilePath = iniFileName;
}
else
{
Application.iniFilePath = Path.GetFullPath(
Path.Combine(Util.configDir(), iniFileName));
if (File.Exists(Application.iniFilePath))
{
if (!sources.Contains(Application.iniFilePath))
sources.Add(Application.iniFilePath);
}
}
string iniDirName =
startupConfig.GetString("inidirectory", "Configuration/Modules");
string iniDirPath =
Path.Combine(Util.configDir(), iniDirName);
if (Directory.Exists(iniDirPath))
{
m_log.InfoFormat("Searching folder {0} for config ini files",
iniDirPath);
string[] fileEntries = Directory.GetFiles(iniDirName);
foreach (string filePath in fileEntries)
{
if (Path.GetExtension(filePath).ToLower() == ".ini")
{
if (!sources.Contains(Path.GetFullPath(filePath)))
sources.Add(Path.GetFullPath(filePath));
}
}
}
m_config = new IniConfigSource();
m_log.Info("[CONFIG]: Reading configuration settings");
if (sources.Count == 0)
{
m_log.FatalFormat("[CONFIG]: Could not load any configuration");
m_log.FatalFormat("[CONFIG]: Did you copy the OpenSim.ini.example file to OpenSim.ini?");
throw new NotSupportedException();
}
for (int i = 0 ; i < sources.Count ; i++)
{
if (ReadConfig(sources[i]))
iniFileExists = true;
AddIncludes(sources);
}
if (!iniFileExists)
{
m_log.FatalFormat("[CONFIG]: Could not load any configuration");
m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
throw new NotSupportedException();
}
// Make sure command line options take precedence
m_config.Merge(argvSource);
return m_config;
}
示例6: LoadConfigSettings
/// <summary>
/// Loads the region configuration
/// </summary>
/// <param name="argvSource">Parameters passed into the process when started</param>
/// <param name="configSettings"></param>
/// <param name="networkInfo"></param>
/// <returns>A configuration that gets passed to modules</returns>
public IConfigSource LoadConfigSettings(IConfig startupConfig)
{
bool iniFileExists = false;
List<string> sources = new List<string>();
string masterFileName = startupConfig.GetString("inimaster", "OpenSimDefaults.ini");
if (masterFileName == "none")
masterFileName = String.Empty;
if (IsUri(masterFileName))
{
if (!sources.Contains(masterFileName))
sources.Add(masterFileName);
}
else
{
string masterFilePath = Path.GetFullPath(
Path.Combine(Util.configDir(), masterFileName));
if (masterFileName != String.Empty)
{
if (File.Exists(masterFilePath))
{
if (!sources.Contains(masterFilePath))
sources.Add(masterFilePath);
}
else
{
m_log.ErrorFormat("Master ini file {0} not found", Path.GetFullPath(masterFilePath));
Environment.Exit(1);
}
}
}
string iniFileName = startupConfig.GetString("inifile", Path.Combine(".", "OpenSim.ini"));
if (IsUri(iniFileName))
{
if (!sources.Contains(iniFileName))
sources.Add(iniFileName);
}
else
{
if (File.Exists(iniFileName))
{
if (!sources.Contains(iniFileName))
sources.Add(iniFileName);
}
}
m_config = new IniConfigSource();
m_config.Merge(DefaultConfig());
m_log.Info("[CONFIG] Reading configuration settings");
if (sources.Count == 0)
{
m_log.FatalFormat("[CONFIG] Could not load any configuration");
m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
Environment.Exit(1);
}
for (int i = 0 ; i < sources.Count ; i++)
{
if (ReadConfig(sources[i]))
iniFileExists = true;
AddIncludes(sources);
}
if (!iniFileExists)
{
m_log.FatalFormat("[CONFIG] Could not load any configuration");
m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!");
Environment.Exit(1);
}
return m_config;
}
示例7: ReadConfig
/// <summary>
/// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
/// </summary>
/// <param name = "iniPath">Full path to the ini</param>
/// <returns></returns>
private bool ReadConfig(string iniPath, int i, IConfigSource source)
{
bool success = false;
if (!IsUri(iniPath))
{
if (showIniLoading)
Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}", Util.BasePathCombine(iniPath)));
source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
if (inidbg)
{
WriteConfigFile(i, source);
}
success = true;
}
else
{
Console.WriteLine(string.Format("[CONFIG]: {0} is a http:// URI, fetching ...", iniPath));
// The ini file path is a http URI
// Try to read it
try
{
XmlReader r = XmlReader.Create(iniPath);
XmlConfigSource cs = new XmlConfigSource(r);
source.Merge(cs);
success = true;
}
catch (Exception e)
{
Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
Environment.Exit(1);
}
}
return success;
}
示例8: Configure
/// <summary>
/// Configure the plugin. This is the equivilent of our parameterized constructor
/// for regular Robust connectors. But, we just get our configuration and return
/// the port we want to run our connector on back to the application. Then the
/// application will send our server to the Initialize method
/// </summary>
/// <param name='config'>
/// IConfigSource - Main Config.
/// </param>
public uint Configure(IConfigSource config)
{
m_log.Info("[SLIPSTREAM]: Running Configuration");
Config = config;
IConfig startconfig = Config.Configs["Startup"];
string configdirectory = startconfig.GetString("ConfigDirectory", ".");
ConfigFile = Path.Combine(configdirectory, "SlipStream.ini");
m_log.InfoFormat("[SLIPSTREAM]: Configuration {0}", ConfigFile);
// Look in our main config first
IConfig serverConfig = Config.Configs[ConfigName];
if (serverConfig == null)
{
// Look for individual config file
serverConfig = GetConfig ();
if (serverConfig == null)
throw new Exception(String.Format("[SlipStream]: Cannot file configuration for {0}, not loaded!", ConfigName));
Config.Merge(serverConfig.ConfigSource);
}
uint serverPort = (uint) serverConfig.GetInt("ServerPort", 0);
ServiceModuleName = serverConfig.GetString("LocalServiceModule",
String.Empty);
// Just something to test the config
m_log.InfoFormat("[SLIPSTREAM]: CodeWord {0}", serverConfig.GetString ("CodeWord","Blaah!"));
if (ServiceModuleName == String.Empty)
throw new Exception("No LocalServiceModule in config file");
// We want to ship these plugins disabled to allow the user to make
// adjustments to the ini prior to running. The bootstrap ini will be downloaded
// when the plugin is enabled the first time. It should have an Enable and it
// should be set to false. The user can disable the module in the console, make
// edits (including setting Enable to true) then re-enable the plugin. It will
// load and run w/o restarting their Robust.
if (serverConfig.GetBoolean("Enabled", false) == false)
{
m_log.Info("[SLIPSTREAM]: Module Disabled");
Enabled = false;
return 0;
}
else
Enabled = true;
return (uint) serverPort;
}
示例9: LoadConfigSettings
//.........这里部分代码省略.........
if (File.Exists (iniFilePath))
{
if (!sources.Contains (iniFilePath))
sources.Add (iniFilePath);
}
}
}
string iniDirName =
startupConfig.GetString ("inidirectory", "");
if (iniDirName != "" && Directory.Exists (iniDirName))
{
m_log.InfoFormat ("Searching folder {0} for config ini files",
iniDirName);
string[] fileEntries = Directory.GetFiles (iniDirName);
foreach (string filePath in fileEntries)
{
if (Path.GetExtension (filePath).ToLower () == ".ini")
{
if (!sources.Contains (Path.Combine (iniDirName, filePath)))
sources.Add (Path.Combine (iniDirName, filePath));
}
}
}
}
else
{
string mainIniDirectory = startupConfig.GetString ("mainIniDirectory", "");
if(mainIniDirectory != "")
basePath = mainIniDirectory;
string mainIniFileName = startupConfig.GetString ("mainIniFileName", defaultIniFile);
string secondaryIniFileName = startupConfig.GetString ("secondaryIniFileName", "");
if(mainIniFileName == "")
{
}
else if (IsUri (mainIniFileName))
{
if (!sources.Contains (mainIniFileName))
sources.Add (mainIniFileName);
}
else
{
string mainIniFilePath = Path.Combine (mainIniDirectory, mainIniFileName);
if (!sources.Contains (mainIniFilePath))
sources.Add (mainIniFilePath);
}
if (secondaryIniFileName == "")
{
}
else if (IsUri (secondaryIniFileName))
{
if (!sources.Contains (secondaryIniFileName))
sources.Add (secondaryIniFileName);
}
else
{
string secondaryIniFilePath = Path.Combine (mainIniDirectory, secondaryIniFileName);
if (!sources.Contains (secondaryIniFilePath))
sources.Add (secondaryIniFilePath);
}
}
m_config = new IniConfigSource();
m_log.Info("[Config]: Reading configuration settings");
if (sources.Count == 0)
{
m_log.FatalFormat("[CONFIG]: Could not load any configuration");
m_log.FatalFormat("[CONFIG]: Did you copy the " + defaultIniFile + ".example file to " + defaultIniFile + "?");
throw new NotSupportedException();
}
List<string> triedPaths = new List<string> ();
for (int i = 0 ; i < sources.Count ; i++)
{
if (ReadConfig(sources[i], i))
iniFileExists = true;
AddIncludes (sources, basePath, ref i, ref triedPaths);
}
FixDefines (ref m_config);
if (!iniFileExists)
{
m_log.FatalFormat("[CONFIG]: Could not load any configuration");
m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
throw new NotSupportedException();
}
// Make sure command line options take precedence
m_config.Merge(argvSource);
return m_config;
}
示例10: Configure
public uint Configure(IConfigSource config)
{
Config = config;
IConfig startconfig = Config.Configs["Startup"];
string configdirectory = startconfig.GetString("ConfigDirectory", ".");
ConfigFile = Path.Combine(configdirectory, CONFIG_FILE);
IConfig wifiConfig = Config.Configs[ConfigName];
if (wifiConfig == null)
{
// No [WifiService] in the main configuration. We need to read it from its own file
if (!File.Exists(ConfigFile))
{
// We need to copy the one that comes in the package
if (!Directory.Exists(configdirectory))
Directory.CreateDirectory(configdirectory);
string embeddedConfig = Path.Combine(AssemblyDirectory, CONFIG_FILE);
File.Copy(embeddedConfig, ConfigFile);
m_log.ErrorFormat("[Wifi]: PLEASE EDIT {0} BEFORE RUNNING THIS SERVICE", ConfigFile);
throw new Exception("Wifi addin must be configured prior to running");
}
else
{
m_log.DebugFormat("[Wifi]: Configuring from {0}...", ConfigFile);
IConfigSource configsource = new IniConfigSource(ConfigFile);
AdjustStorageProvider(configsource);
wifiConfig = configsource.Configs[ConfigName];
// Merge everything and expand eventual key values used by our config
Config.Merge(configsource);
Config.ExpandKeyValues();
}
if (wifiConfig == null)
throw new Exception(string.Format("[Wifi]: Could not load configuration from {0}. Unable to proceed.", ConfigFile));
}
Enabled = wifiConfig.GetBoolean("Enabled", false);
// Let's look for the port in WifiService first, then look elsewhere
int port = wifiConfig.GetInt("ServerPort", -1);
if (port > 0)
return (uint)port;
IConfig section = Config.Configs["Const"];
if (section != null)
{
port = section.GetInt("PublicPort", -1);
if (port > 0)
return (uint)port;
}
if (port < 0)
throw new Exception("[Wifi]: Could not find port in configuration file");
return 0;
}