Refactor to api connections. Update Checker.
This commit is contained in:
54
PWAPPv2/Source/Config/Configuration.cs
Normal file
54
PWAPPv2/Source/Config/Configuration.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
|
||||
namespace PWAPPv2.Source.Config
|
||||
{
|
||||
public class Configuration
|
||||
{
|
||||
private Dictionary<string, string> values;
|
||||
|
||||
public Configuration(string file)
|
||||
{
|
||||
values = new Dictionary<string, string>();
|
||||
if(!File.Exists(file))
|
||||
{
|
||||
throw new ConfigFileNotFoundException();
|
||||
}
|
||||
|
||||
string f = File.ReadAllText(file);
|
||||
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(f);
|
||||
|
||||
XmlNodeList xmlNodeList = xmlDoc.DocumentElement.ChildNodes;
|
||||
foreach (XmlNode xmlNode in xmlNodeList)
|
||||
{
|
||||
values.Add(xmlNode.Name, xmlNode.InnerText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public string Get(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
return values[key];
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ConfigValueNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class ConfigFileNotFoundException : Exception { }
|
||||
|
||||
public class ConfigValueNotFoundException: Exception { }
|
||||
}
|
||||
Reference in New Issue
Block a user