You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Config/Implementation/IniFileWriter.cs

76 lines
2.4 KiB

6 years ago
using System.IO;
namespace ZeroLevel.Services.Config.Implementation
{
/// <summary>
/// Write config to ini-file
6 years ago
/// </summary>
public class IniFileWriter
6 years ago
: IConfigurationWriter
{
/// <summary>
/// Config file path
6 years ago
/// </summary>
private readonly string _iniPath;
6 years ago
public IniFileWriter(string iniPath)
{
_iniPath = iniPath;
}
6 years ago
/// <summary>
/// Write config to file
6 years ago
/// </summary>
public void WriteConfiguration(IConfiguration configuration)
{
using (TextWriter writer = new StreamWriter(_iniPath, false))
{
foreach (string key in configuration.Keys)
{
if (configuration.Count(key) > 0)
{
foreach (string value in configuration[key])
{
writer.WriteLine(key.Trim() + "=" + value.Trim());
}
}
else
{
writer.WriteLine(key.Trim());
}
}
writer.Flush();
}
}
6 years ago
/// <summary>
/// Write configuration set to file
6 years ago
/// </summary>
public void WriteConfigurationSet(IConfigurationSet configuration)
{
using (TextWriter writer = new StreamWriter(_iniPath, false))
{
foreach (string section in configuration.SectionNames)
{
if (false == section.Equals(Configuration.DEFAULT_SECTION_NAME, System.StringComparison.Ordinal))
writer.WriteLine("[" + section + "]");
foreach (string key in configuration[section].Keys)
{
if (configuration[section].Count(key) > 0)
{
foreach (string value in configuration[section][key])
{
writer.WriteLine(key + "=" + value);
}
}
else
{
writer.WriteLine(key);
}
}
}
writer.Flush();
}
}
}
}

Powered by TurnKey Linux.