Merge pull request #324 from Cyberboss/InstanceConfigInterface

Adds IInstanceConfig
This commit is contained in:
Jordan Brown
2017-11-06 16:05:41 -05:00
committed by GitHub
5 changed files with 154 additions and 84 deletions
+2 -2
View File
@@ -16,8 +16,8 @@ namespace TGServerService
/// <summary>
/// Convert the settings version 6 .NET settings file to a config json
/// </summary>
/// <returns>An <see cref="InstanceConfig"/> based off the old .NET setting file</returns>
public static InstanceConfig CreateFromNETSettings()
/// <returns>An <see cref="IInstanceConfig"/> based off the old .NET setting file</returns>
public static IInstanceConfig CreateFromNETSettings()
{
var Config = Properties.Settings.Default;
var result = new DeprecatedInstanceConfig(LoadPreviousNetPropertyOrDefault("ServerDirectory", "C:\\tgstation-server-3"));
+138 -68
View File
@@ -4,117 +4,189 @@ using TGServiceInterface;
namespace TGServerService
{
class InstanceConfig
/// <summary>
/// Configuration settings for a <see cref="ServerInstance"/>
/// </summary>
interface IInstanceConfig
{
/// <summary>
/// The <see cref="ServerInstance"/> directory this <see cref="IInstanceConfig"/> is for
/// </summary>
string Directory { get; }
/// <summary>
/// Actual version of the <see cref="IInstanceConfig"/>. Migrated up via <see cref="DeprecatedInstanceConfig"/>
/// </summary>
ulong Version { get; }
/// <summary>
/// The name of the <see cref="ServerInstance"/>
/// </summary>
string Name { get; set; }
/// <summary>
/// If the <see cref="ServerInstance"/> is active
/// </summary>
bool Enabled { get; set; }
/// <summary>
/// The name of the .dme/.dmb the <see cref="ServerInstance"/> uses
/// </summary>
string ProjectName { get; set; }
/// <summary>
/// The port the <see cref="ServerInstance"/> runs on
/// </summary>
ushort Port { get; set; }
/// <summary>
/// The <see cref="DreamDaemonSecurity"/> level for the <see cref="ServerInstance"/>
/// </summary>
DreamDaemonSecurity Security { get; set; }
/// <summary>
/// Whether or not the <see cref="ServerInstance"/> should immediately start DreamDaemon when activated
/// </summary>
bool Autostart { get; set; }
/// <summary>
/// Whether or not DreamDaemon allows connections from webclients
/// </summary>
bool Webclient { get; set; }
/// <summary>
/// Author and committer name for synchronize commits
/// </summary>
string CommitterName { get; set; }
/// <summary>
/// Author and committer e-mail for synchronize commits
/// </summary>
string CommitterEmail { get; set; }
/// <summary>
/// Encrypted serialized <see cref="ChatSetupInfo"/>s
/// </summary>
string ChatProviderData { get; set; }
/// <summary>
/// Entropy for <see cref="ChatProviderData"/>
/// </summary>
string ChatProviderEntropy { get; set; }
/// <summary>
/// If the <see cref="ServerInstance"/> should reattach to a running DreamDaemon <see cref="System.Diagnostics.Process"/>
/// </summary>
bool ReattachRequired { get; set; }
/// <summary>
/// The <see cref="System.Diagnostics.Process.Id"/> of the runnning DreamDaemon <see cref="System.Diagnostics.Process"/>
/// </summary>
int ReattachProcessID { get; set; }
/// <summary>
/// The port the runnning DreamDaemon <see cref="System.Diagnostics.Process"/> was launched on
/// </summary>
ushort ReattachPort { get; set; }
/// <summary>
/// The serviceCommsKey the runnning DreamDaemon <see cref="System.Diagnostics.Process"/> was launched on
/// </summary>
string ReattachCommsKey { get; set; }
/// <summary>
/// The API version of the runnning DreamDaemon <see cref="System.Diagnostics.Process"/>
/// </summary>
string ReattachAPIVersion { get; set; }
/// <summary>
/// The user group allowed to use the <see cref="ServerInstance"/>
/// </summary>
string AuthorizedUserGroupSID { get; set; }
/// <summary>
/// The auto update interval for the <see cref="ServerInstance"/>
/// </summary>
ulong AutoUpdateInterval { get; set; }
/// <summary>
/// Saves the <see cref="IInstanceConfig"/> to it's <see cref="ServerInstance"/> <see cref="Directory"/>
/// </summary>
void Save();
}
/// <inheritdoc />
class InstanceConfig : IInstanceConfig
{
/// <summary>
/// The name the file is saved as in the <see cref="Directory"/>
/// </summary>
//tell javascriptserializer to ignore these fields
[ScriptIgnore]
public const string JSONFilename = "Instance.json";
/// <summary>
/// The current version of the config
/// </summary>
[ScriptIgnore]
protected const ulong CurrentVersion = 0; //Literally any time you add/deprecated a field, this number needs to be bumped
/// <summary>
/// The <see cref="ServerInstance"/> directory this <see cref="InstanceConfig"/> is for
/// </summary>
/// <inheritdoc />
[ScriptIgnore]
public string Directory { get; private set; }
/// <summary>
/// Actual version of the <see cref="InstanceConfig"/>. Migrated up via <see cref="DeprecatedInstanceConfig"/>
/// </summary>
/// <inheritdoc />
public ulong Version { get; protected set; } = CurrentVersion;
/// <summary>
/// The name of the <see cref="ServerInstance"/>
/// </summary>
/// <inheritdoc />
public string Name { get; set; } = "TG Station Server";
/// <summary>
/// If the <see cref="ServerInstance"/> is active
/// </summary>
/// <inheritdoc />
public bool Enabled { get; set; } = true;
/// <summary>
/// The name of the .dme/.dmb the <see cref="ServerInstance"/> uses
/// </summary>
/// <inheritdoc />
public string ProjectName { get; set; } = "tgstation";
/// <summary>
/// The port the <see cref="ServerInstance"/> runs on
/// </summary>
/// <inheritdoc />
public ushort Port { get; set; } = 1337;
/// <summary>
/// The <see cref="DreamDaemonSecurity"/> level for the <see cref="ServerInstance"/>
/// </summary>
/// <inheritdoc />
public DreamDaemonSecurity Security { get; set; } = DreamDaemonSecurity.Trusted;
/// <summary>
/// Whether or not the <see cref="ServerInstance"/> should immediately start DreamDaemon when activated
/// </summary>
/// <inheritdoc />
public bool Autostart { get; set; } = false;
/// <summary>
/// Whether or not DreamDaemon allows connections from webclients
/// </summary>
/// <inheritdoc />
public bool Webclient { get; set; } = false;
/// <summary>
/// Author and committer name for synchronize commits
/// </summary>
/// <inheritdoc />
public string CommitterName { get; set; } = "tgstation-server";
/// <summary>
/// Author and committer e-mail for synchronize commits
/// </summary>
/// <inheritdoc />
public string CommitterEmail { get; set; } = "tgstation-server@tgstation13.org";
/// <summary>
/// Encrypted serialized <see cref="ChatSetupInfo"/>s
/// </summary>
/// <inheritdoc />
public string ChatProviderData { get; set; } = ServerInstance.UninitializedString;
/// <summary>
/// Entropy for <see cref="ChatProviderData"/>
/// </summary>
/// <inheritdoc />
public string ChatProviderEntropy { get; set; }
/// <summary>
/// If the <see cref="ServerInstance"/> should reattach to a running DreamDaemon <see cref="System.Diagnostics.Process"/>
/// </summary>
/// <inheritdoc />
public bool ReattachRequired { get; set; } = false;
/// <summary>
/// The <see cref="System.Diagnostics.Process.Id"/> of the runnning DreamDaemon <see cref="System.Diagnostics.Process"/>
/// </summary>
/// <inheritdoc />
public int ReattachProcessID { get; set; }
/// <summary>
/// The port the runnning DreamDaemon <see cref="System.Diagnostics.Process"/> was launched on
/// </summary>
/// <inheritdoc />
public ushort ReattachPort { get; set; }
/// <summary>
/// The serviceCommsKey the runnning DreamDaemon <see cref="System.Diagnostics.Process"/> was launched on
/// </summary>
/// <inheritdoc />
public string ReattachCommsKey { get; set; }
/// <summary>
/// The API version of the runnning DreamDaemon <see cref="System.Diagnostics.Process"/>
/// </summary>
/// <inheritdoc />
public string ReattachAPIVersion { get; set; }
/// <summary>
/// The user group allowed to use the <see cref="ServerInstance"/>
/// </summary>
/// <inheritdoc />
public string AuthorizedUserGroupSID { get; set; } = null;
/// <summary>
/// The auto update interval for the <see cref="ServerInstance"/>
/// </summary>
/// <inheritdoc />
public ulong AutoUpdateInterval { get; set; } = 0;
/// <summary>
@@ -126,9 +198,7 @@ namespace TGServerService
Directory = path;
}
/// <summary>
/// Saves the <see cref="InstanceConfig"/> to it's <see cref="ServerInstance"/> <see cref="Directory"/>
/// </summary>
/// <inheritdoc />
public void Save()
{
var data = new JavaScriptSerializer().Serialize(this);
@@ -137,11 +207,11 @@ namespace TGServerService
}
/// <summary>
/// Loads and migrates an <see cref="InstanceConfig"/> from a <see cref="ServerInstance"/> at <paramref name="path"/>
/// Loads and migrates an <see cref="IInstanceConfig"/> from a <see cref="ServerInstance"/> at <paramref name="path"/>
/// </summary>
/// <param name="path">The path to the <see cref="ServerInstance"/> directory</param>
/// <returns>The migrated <see cref="InstanceConfig"/></returns>
public static InstanceConfig Load(string path)
/// <returns>The migrated <see cref="IInstanceConfig"/></returns>
public static IInstanceConfig Load(string path)
{
var configtext = File.ReadAllText(Path.Combine(path, JSONFilename));
var res = new JavaScriptSerializer().Deserialize<DeprecatedInstanceConfig>(configtext);
@@ -24,11 +24,11 @@ namespace TGServerService
/// <summary>
/// The configuration settings for the instance
/// </summary>
readonly InstanceConfig Config;
readonly IInstanceConfig Config;
/// <summary>
/// Constructs and a <see cref="ServerInstance"/>
/// </summary>
public ServerInstance(InstanceConfig config, byte logID)
public ServerInstance(IInstanceConfig config, byte logID)
{
LoggingID = logID;
Config = config;
+11 -11
View File
@@ -118,10 +118,10 @@ namespace TGServerService
}
/// <summary>
/// Enumerates configured <see cref="InstanceConfig"/>s. Detaches those that fail to load
/// Enumerates configured <see cref="IInstanceConfig"/>s. Detaches those that fail to load
/// </summary>
/// <returns>Each configured <see cref="InstanceConfig"/></returns>
IEnumerable<InstanceConfig> GetInstanceConfigs()
/// <returns>Each configured <see cref="IInstanceConfig"/></returns>
IEnumerable<IInstanceConfig> GetInstanceConfigs()
{
var pathsToRemove = new List<string>();
lock (this)
@@ -129,7 +129,7 @@ namespace TGServerService
var IPS = Properties.Settings.Default.InstancePaths;
foreach (var I in IPS)
{
InstanceConfig ic;
IInstanceConfig ic;
try
{
ic = InstanceConfig.Load(I);
@@ -319,9 +319,9 @@ namespace TGServerService
/// <summary>
/// Creates and starts a <see cref="ServiceHost"/> for a <see cref="ServerInstance"/> at <paramref name="config"/>
/// </summary>
/// <param name="config">The <see cref="InstanceConfig"/> for the <see cref="ServerInstance"/></param>
/// <param name="config">The <see cref="IInstanceConfig"/> for the <see cref="ServerInstance"/></param>
/// <returns>The inactive <see cref="ServiceHost"/> on success, <see langword="null"/> on failure</returns>
ServiceHost SetupInstance(InstanceConfig config)
ServiceHost SetupInstance(IInstanceConfig config)
{
ServerInstance instance;
string instanceName;
@@ -484,7 +484,7 @@ namespace TGServerService
foreach (var oic in GetInstanceConfigs())
if (Name == oic.Name)
return String.Format("Instance named {0} already exists!", oic.Name);
InstanceConfig ic;
IInstanceConfig ic;
try
{
ic = new InstanceConfig(path)
@@ -506,9 +506,9 @@ namespace TGServerService
/// <summary>
/// Starts and onlines an instance located at <paramref name="config"/>
/// </summary>
/// <param name="config">The <see cref="InstanceConfig"/> for the <see cref="ServerInstance"/></param>
/// <param name="config">The <see cref="IInstanceConfig"/> for the <see cref="ServerInstance"/></param>
/// <returns><see langword="null"/> on success, error message on failure</returns>
string SetupOneInstance(InstanceConfig config)
string SetupOneInstance(IInstanceConfig config)
{
try
{
@@ -536,7 +536,7 @@ namespace TGServerService
return String.Format("Instance at {0} already exists!", path);
if(!Directory.Exists(path))
return String.Format("There is no instance located at {0}!", path);
InstanceConfig ic;
IInstanceConfig ic;
try
{
ic = InstanceConfig.Load(path);
@@ -635,7 +635,7 @@ namespace TGServerService
lock (this)
{
//we have to check em all anyway
InstanceConfig the_droid_were_looking_for = null;
IInstanceConfig the_droid_were_looking_for = null;
foreach (var ic in GetInstanceConfigs())
if (ic.Name == name)
{
+1 -1
View File
@@ -19,7 +19,7 @@ namespace TGServerService.Tests
/// Creates a default <see cref="InstanceConfig"/> at <see cref="TempPath"/>
/// </summary>
/// <returns></returns>
InstanceConfig CreateTempConfig()
IInstanceConfig CreateTempConfig()
{
return new InstanceConfig(TempPath);
}