|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections.Specialized;
using System.IO;
namespace DeepCast
{
/// <summary>
/// Class for managing user settings
/// </summary>
public class Settings
{
private static NameValueCollection _settings;
private static string _settingsPath;
static Settings()
{
_settingsPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
_settingsPath += @"\Settings.xml";
XmlDocument xdoc = new XmlDocument();
xdoc.Load(_settingsPath);
XmlElement root = xdoc.DocumentElement;
System.Xml.XmlNodeList nodeList = root.ChildNodes.Item(0).ChildNodes;
_settings = new NameValueCollection();
_settings.Add("FireEagleToken", nodeList.Item(0).Attributes["value"].Value);
_settings.Add("FireEagleSecret", nodeList.Item(1).Attributes["value"].Value);
_settings.Add("TwitterEmail", nodeList.Item(2).Attributes["value"].Value);
_settings.Add("TwitterPassword", nodeList.Item(3).Attributes["value"].Value);
_settings.Add("FireEagleEnabled", nodeList.Item(4).Attributes["value"].Value);
_settings.Add("TwitterEnabled", nodeList.Item(5).Attributes["value"].Value);
_settings.Add("YahooMapsApiKey", nodeList.Item(6).Attributes["value"].Value);
_settings.Add("OpenCellIDApiKey", nodeList.Item(7).Attributes["value"].Value);
}
public static void Update()
{
XmlTextWriter writer = new XmlTextWriter(_settingsPath, System.Text.UTF8Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("configuration");
writer.WriteStartElement("appSettings");
for (int i = 0; i < _settings.Count; ++i)
{
writer.WriteStartElement("add");
writer.WriteStartAttribute("key", string.Empty);
writer.WriteRaw(_settings.GetKey(i));
writer.WriteEndAttribute();
writer.WriteStartAttribute("value", string.Empty);
writer.WriteRaw(_settings.Get(i));
writer.WriteEndAttribute();
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.Close();
}
public static string FireEagleToken
{
get { return _settings.Get("FireEagleToken"); }
set { _settings.Set("FireEagleToken", value); }
}
public static string FireEagleSecret
{
get { return _settings.Get("FireEagleSecret"); }
set { _settings.Set("FireEagleSecret", value); }
}
public static string TwitterEmail
{
get { return _settings.Get("TwitterEmail"); }
set { _settings.Set("TwitterEmail", value); }
}
public static bool FireEagleEnabled
{
get { return bool.Parse(_settings.Get("FireEagleEnabled")); }
set { _settings.Set("FireEagleEnabled", value.ToString()); }
}
public static bool TwitterEnabled
{
get { return bool.Parse(_settings.Get("TwitterEnabled")); }
set { _settings.Set("TwitterEnabled", value.ToString()); }
}
public static string TwitterPassword
{
get { return _settings.Get("TwitterPassword"); }
set { _settings.Set("TwitterPassword", value); }
}
public static string YahooMapsApiKey
{
get { return _settings.Get("YahooMapsApiKey"); }
set { _settings.Set("YahooMapsApiKey", value); }
}
public static string OpenCellIDApiKey
{
get { return _settings.Get("OpenCellIDApiKey"); }
set { _settings.Set("OpenCellIDApiKey", value); }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm the founder of PageLabs, a web-based performance and SEO optimization site.
Give your site a boost in performance, even take a free speed test!
http://www.pagelabs.com