Refactor to api connections. Update Checker.

This commit is contained in:
Matthew Burke
2023-08-24 12:45:56 -04:00
parent 4a4bcc81e0
commit 87a73ff24b
14 changed files with 355 additions and 45 deletions

View 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 { }
}