Harrison Deng 6467c178c3 Basic service entity completed and tested.
added UML to guide actual implementation for Host.

ModuleLoader, ServiceGateway, are written but untested.
2020-12-24 16:33:17 -06:00

46 lines
1.4 KiB
C#

using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Xml.Serialization;
namespace GameServiceWarden.Host.Preferences
{
[Serializable]
public class GeneralPreferences : IPersistable
{
//XML serialization invariants.
private readonly XmlSerializer xmlSerializer;
private readonly string APP_DATA_DIR;
//Preferences stored.
public int Port = 8080;
public string ListeningIP = IPAddress.Any.ToString();
public string ModuleDataPath;
public GeneralPreferences()
{
APP_DATA_DIR = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/" + Assembly.GetAssembly(GetType()).GetName().Name + "/";
xmlSerializer = new XmlSerializer(GetType());
this.ModuleDataPath = APP_DATA_DIR + "modules/";
Load();
}
public void Save()
{
using (FileStream writer = new FileStream(APP_DATA_DIR + GetType().Name + ".xml", FileMode.OpenOrCreate))
{
xmlSerializer.Serialize(writer, this);
}
}
public void Load()
{
using (FileStream reader = new FileStream(APP_DATA_DIR + GetType().Name + ".xml", FileMode.Open))
{
xmlSerializer.Deserialize(reader);
}
}
}
}