本文整理汇总了C#中Nini.Config.XmlConfigSource类的典型用法代码示例。如果您正苦于以下问题:C# XmlConfigSource类的具体用法?C# XmlConfigSource怎么用?C# XmlConfigSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlConfigSource类属于Nini.Config命名空间,在下文中一共展示了XmlConfigSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmptyConstructor
public void EmptyConstructor()
{
string filePath = "EmptyConstructor.xml";
XmlConfigSource source = new XmlConfigSource ();
IConfig config = source.AddConfig ("Pets");
config.Set ("cat", "Muffy");
config.Set ("dog", "Rover");
config.Set ("bird", "Tweety");
source.Save (filePath);
Assert.AreEqual (3, config.GetKeys ().Length);
Assert.AreEqual ("Muffy", config.Get ("cat"));
Assert.AreEqual ("Rover", config.Get ("dog"));
Assert.AreEqual ("Tweety", config.Get ("bird"));
source = new XmlConfigSource (filePath);
config = source.Configs["Pets"];
Assert.AreEqual (3, config.GetKeys ().Length);
Assert.AreEqual ("Muffy", config.Get ("cat"));
Assert.AreEqual ("Rover", config.Get ("dog"));
Assert.AreEqual ("Tweety", config.Get ("bird"));
File.Delete (filePath);
}
示例2: AutoUpdateHepler
static AutoUpdateHepler()
{
string str = FileUtility.ApplicationRootPath + @"\update";
if (LoggingService.IsInfoEnabled)
{
LoggingService.Info("读取升级配置:" + str);
}
XmlConfigSource source = null;
if (System.IO.File.Exists(str + ".cxml"))
{
XmlTextReader decryptXmlReader = new CryptoHelper(CryptoTypes.encTypeDES).GetDecryptXmlReader(str + ".cxml");
IXPathNavigable document = new XPathDocument(decryptXmlReader);
source = new XmlConfigSource(document);
decryptXmlReader.Close();
}
else if (System.IO.File.Exists(str + ".xml"))
{
source = new XmlConfigSource(str + ".xml");
}
if (source != null)
{
softName = source.Configs["FtpSetting"].GetString("SoftName", string.Empty);
version = source.Configs["FtpSetting"].GetString("Version", string.Empty);
server = source.Configs["FtpSetting"].GetString("Server", string.Empty);
user = source.Configs["FtpSetting"].GetString("User", string.Empty);
password = source.Configs["FtpSetting"].GetString("Password", string.Empty);
path = source.Configs["FtpSetting"].GetString("Path", string.Empty);
liveup = source.Configs["FtpSetting"].GetString("LiveUp", string.Empty);
autoupdate = source.Configs["FtpSetting"].GetString("autoupdate", string.Empty);
}
}
示例3: HasNewVesion
public static bool HasNewVesion()
{
try
{
if (!string.IsNullOrEmpty(server))
{
WebRequest request = WebRequest.Create(string.Format("ftp://{0}/{1}/update.xml", server, softName));
request.Credentials = new NetworkCredential(user, password);
WebResponse response = request.GetResponse();
XmlDocument document = new XmlDocument();
document.Load(response.GetResponseStream());
XmlConfigSource source = new XmlConfigSource(document);
if (source.Configs["FtpSetting"].GetString("Version").CompareTo(version) > 0)
{
LoggingService.InfoFormatted("系统有新版本:{0}", new object[] { source.Configs["FtpSetting"].GetString("Version") });
return true;
}
}
}
catch (Exception exception)
{
LoggingService.Error("查询是否有新版本时出错", exception);
}
return false;
}
示例4: GetConfig
private static XmlConfigSource GetConfig(string cfgFileName)
{
XmlConfigSource source = null;
if (configs.ContainsKey(cfgFileName))
{
return configs[cfgFileName];
}
string filename = cfgFileName;
int num = filename.LastIndexOf('.');
if (filename.EndsWith(".config") && File.Exists(filename.Insert(num + 1, "c")))
{
filename = filename.Insert(num + 1, "c");
LoggingService.DebugFormatted("读取的是加密的配置文件:{0}", new object[] { filename });
CryptoHelper helper = new CryptoHelper(CryptoTypes.encTypeDES);
using (XmlTextReader reader = helper.GetDecryptXmlReader(filename))
{
XPathDocument document = new XPathDocument(reader);
source = new XmlConfigSource(document);
goto Label_00B8;
}
}
if (!File.Exists(filename))
{
throw new ArgumentOutOfRangeException(cfgFileName + "不存在");
}
source = new XmlConfigSource(filename);
Label_00B8:
configs.Add(cfgFileName, source);
return source;
}
示例5: CheckForUpdates
public string CheckForUpdates(string clientVersion)
{
var response = string.Empty;
try
{
if (!Directory.Exists(_dir + @"\Ester"))
{
throw new Exception("Cannot find Ester folder on server");
}
_clientConfigSource = new XmlConfigSource(Path.Combine(HttpRuntime.AppDomainAppPath, @"Resources\Ester\Config.xml")) { AutoSave = true };
int clientVersionNumber;
if (int.TryParse(clientVersion, out clientVersionNumber))
{
if (clientVersionNumber < GetLastVersionNumber())
{
response = _configSource.Configs["Update"].Get("UpdateFileUrl");
}
}
}
catch (Exception exception)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError;
WebOperationContext.Current.OutgoingResponse.StatusDescription = exception.Message;
}
return response;
}
示例6: Merge
public void Merge ()
{
StringWriter textWriter = new StringWriter ();
XmlTextWriter xmlWriter = NiniWriter (textWriter);
WriteSection (xmlWriter, "Pets");
WriteKey (xmlWriter, "cat", "muffy");
WriteKey (xmlWriter, "dog", "rover");
WriteKey (xmlWriter, "bird", "tweety");
xmlWriter.WriteEndDocument ();
StringReader reader = new StringReader (textWriter.ToString ());
XmlTextReader xmlReader = new XmlTextReader (reader);
XmlConfigSource xmlSource = new XmlConfigSource (xmlReader);
StringWriter writer = new StringWriter ();
writer.WriteLine ("[People]");
writer.WriteLine (" woman = Jane");
writer.WriteLine (" man = John");
IniConfigSource iniSource =
new IniConfigSource (new StringReader (writer.ToString ()));
xmlSource.Merge (iniSource);
IConfig config = xmlSource.Configs["Pets"];
Assert.AreEqual (3, config.GetKeys ().Length);
Assert.AreEqual ("muffy", config.Get ("cat"));
Assert.AreEqual ("rover", config.Get ("dog"));
config = xmlSource.Configs["People"];
Assert.AreEqual (2, config.GetKeys ().Length);
Assert.AreEqual ("Jane", config.Get ("woman"));
Assert.AreEqual ("John", config.Get ("man"));
}
示例7: PluginSettingsBase
/// <summary>
/// Initializes a new instance of the <see cref="PluginSettingsBase"/> class.
/// </summary>
/// <param name="pluginName">Name of the plugin.</param>
public PluginSettingsBase(string pluginName)
{
var fileName = string.Format("{0}\\Probel\\nDoctor\\{1}.plugin.config"
, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
, pluginName);
if (!File.Exists(fileName)) { this.BuildDefaultFileStream(fileName); }
Source = new XmlConfigSource(fileName);
}
示例8: GeneralSettings
/// <summary>
/// Initializes a new instance of the <see cref="GeneralSettings"/> class.
/// </summary>
/// <remarks>
/// Internal to prevent construction of this class by any other
/// assembly. This class is intended to be constructed by the
/// <see cref="Configuration"/> class only.
/// </remarks>
/// <param name="configurationSource">Reference to the
/// configuration source that contains the configuration file.</param>
internal GeneralSettings(XmlConfigSource configurationSource)
{
_config = configurationSource.Configs["General"];
if (_config == null)
{
_config = configurationSource.AddConfig("General");
SetDefaults();
}
}
示例9: DatabaseSettings
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseSettings"/> class.
/// </summary>
/// <remarks>
/// Internal to prevent construction of this class by any other
/// assembly. This class is intended to be constructed by the
/// <see cref="Configuration"/> class only.
/// </remarks>
/// <param name="configurationSource">Reference to the
/// configuration source that contains the configuration file.</param>
internal DatabaseSettings(XmlConfigSource configurationSource)
{
_config = configurationSource.Configs["Database"];
if (_config == null)
{
_config = configurationSource.AddConfig("Database");
SetDefaults();
}
}
示例10: GetConfig
public void GetConfig()
{
StringWriter textWriter = new StringWriter ();
XmlTextWriter writer = NiniWriter (textWriter);
WriteSection (writer, "Pets");
WriteKey (writer, "cat", "muffy");
WriteKey (writer, "dog", "rover");
WriteKey (writer, "bird", "tweety");
writer.WriteEndDocument ();
StringReader reader = new StringReader (textWriter.ToString ());
XmlTextReader xmlReader = new XmlTextReader (reader);
XmlConfigSource source = new XmlConfigSource (xmlReader);
IConfig config = source.Configs["Pets"];
Assert.AreEqual ("Pets", config.Name);
Assert.AreEqual (3, config.GetKeys ().Length);
Assert.AreEqual (source, config.ConfigSource);
}
示例11: SupportClass
static SupportClass()
{
string path = Path.Combine(DAOConfigsPath, "DAO.config");
LoggingService.DebugFormatted("查找DAO配置文件:{0}", new object[] { path });
if (File.Exists(path))
{
config = new XmlConfigSource(path);
}
else
{
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
LoggingService.DebugFormatted("查找DAO配置文件:{0}", new object[] { path });
if (File.Exists(path))
{
config = new XmlConfigSource(path);
}
}
if (config == null)
{
LoggingService.Warn("没有找到DAO配置文件...");
}
}
示例12: GetString
public void GetString ()
{
StringWriter textWriter = new StringWriter ();
XmlTextWriter writer = NiniWriter (textWriter);
WriteSection (writer, "Pets");
WriteKey (writer, "cat", "muffy");
WriteKey (writer, "dog", "rover");
WriteKey (writer, "bird", "tweety");
writer.WriteEndDocument ();
StringReader reader = new StringReader (textWriter.ToString ());
XmlTextReader xmlReader = new XmlTextReader (reader);
XmlConfigSource source = new XmlConfigSource (xmlReader);
IConfig config = source.Configs["Pets"];
Assert.AreEqual ("muffy", config.Get ("cat"));
Assert.AreEqual ("rover", config.Get ("dog"));
Assert.AreEqual ("muffy", config.GetString ("cat"));
Assert.AreEqual ("rover", config.GetString ("dog"));
Assert.AreEqual ("my default", config.Get ("Not Here", "my default"));
Assert.IsNull (config.Get ("Not Here 2"));
}
示例13: SupportClass
static SupportClass()
{
string path = Path.Combine(DataFormsConfigPath, source);
if (File.Exists(path))
{
config = new XmlConfigSource(path);
}
else
{
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, source);
if (File.Exists(path))
{
config = new XmlConfigSource(path);
}
}
if (config == null)
{
throw new NullReferenceException("找不到表单配置文件:" + path);
}
string[] keys = config.Configs["DataBindProperty"].GetKeys();
DBPKeys = new StringCollection();
DBPKeys.AddRange(keys);
}
示例14: 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)
{
bool success = false;
if (!IsUri(iniPath))
{
m_log.InfoFormat("[CONFIG] Reading configuration file {0}",
Path.GetFullPath(iniPath));
m_config.Merge(new IniConfigSource(iniPath));
success = true;
}
else
{
m_log.InfoFormat("[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);
m_config.Merge(cs);
success = true;
}
catch (Exception e)
{
m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath);
Environment.Exit(1);
}
}
return success;
}
示例15: 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)
{
bool success = false;
if (!IsUri(iniPath))
{
if(showIniLoading)
m_log.InfoFormat("[CONFIG]: Reading configuration file {0}", Path.GetFullPath(iniPath));
m_config.Merge(new IniConfigSource(iniPath, Nini.Ini.IniFileType.AuroraStyle));
if (inidbg)
{
WriteConfigFile(i, m_config);
}
success = true;
}
else
{
m_log.InfoFormat("[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);
m_config.Merge(cs);
success = true;
}
catch (Exception e)
{
m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), iniPath);
Environment.Exit(1);
}
}
return success;
}