Modify Interface to accept instance switching. Add ITGInstance

This commit is contained in:
Cyberboss
2017-10-31 13:14:28 -04:00
parent da7814e3d9
commit 8672a9d5c6
10 changed files with 102 additions and 19 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ namespace TGCommandLine
protected override ExitCode Run(IList<string> parameters)
{
OutputProc(Interface.GetComponent<ITGConfig>().ServerDirectory());
OutputProc(Interface.GetComponent<ITGInstance>().ServerDirectory());
return ExitCode.Normal;
}
+1 -1
View File
@@ -106,7 +106,7 @@ namespace TGControlPanel
{
updatingFields = true;
ServerPathLabel.Text = "Server Path: " + Config.ServerDirectory();
ServerPathLabel.Text = "Server Path: " + Interface.GetComponent<ITGInstance>().ServerDirectory();
SecuritySelector.SelectedIndex = (int)DD.SecurityLevel();
-5
View File
@@ -13,11 +13,6 @@ namespace TGServerService
/// Used for multithreading safety
/// </summary>
object configLock = new object(); //for atomic reads/writes
/// <inheritdoc />
public string ServerDirectory()
{
return Config.InstanceDirectory;
}
/// <inheritdoc />
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
@@ -15,7 +15,7 @@ namespace TGServerService
/// The class which holds all interface components. There are no safeguards for call race conditions so these must be guarded against internally
/// </summary>
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
sealed partial class ServerInstance : IDisposable, ITGConnectivity
sealed partial class ServerInstance : IDisposable, ITGConnectivity, ITGInstance
{
/// <summary>
/// Used to assign the instance to event IDs
@@ -120,6 +120,13 @@ namespace TGServerService
SendMessage("SERVICE: Update started...", MessageType.DeveloperInfo);
}
/// <inheritdoc />
public string ServerDirectory()
{
return Config.InstanceDirectory;
}
//mostly generated code with a call to RunDisposals()
//you don't need to open this
#region IDisposable Support
-6
View File
@@ -10,12 +10,6 @@ namespace TGServiceInterface.Components
[ServiceContract]
public interface ITGConfig
{
/// <summary>
/// Return the directory of the server on the host machine
/// </summary>
/// <returns>The path to the directory on success, null on failure</returns>
[OperationContract]
string ServerDirectory();
/// <summary>
/// Returns the file contents of the specified server directory
+18
View File
@@ -0,0 +1,18 @@
using System.ServiceModel;
namespace TGServiceInterface.Components
{
/// <summary>
/// Metadata for a server instance
/// </summary>
[ServiceContract]
public interface ITGInstance
{
/// <summary>
/// Return the directory of the server on the host machine
/// </summary>
/// <returns>The path to the directory on success, null on failure</returns>
[OperationContract]
string ServerDirectory();
}
}
+2 -2
View File
@@ -24,10 +24,10 @@ namespace TGServiceInterface
{
var parsedArgs = new List<string>();
parsedArgs.AddRange(args);
Interface.InstanceName = parsedArgs[0];
parsedArgs.RemoveAt(0);
using (var I = new Interface())
I.GetComponent<ITGInterop>().InteropMessage(String.Join(" ", parsedArgs));
if(I.ConnectToInstanceImpl(parsedArgs[0], true).HasFlag(InstanceConnectivity.Connected))
I.GetComponent<ITGInterop>().InteropMessage(String.Join(" ", parsedArgs));
}
catch { }
return 0;
+27 -1
View File
@@ -1,5 +1,31 @@
namespace TGServiceInterface
using System;
namespace TGServiceInterface
{
/// <summary>
/// Description of the connectivity level to an <see cref="Components.ITGInstance"/>
/// </summary>
[Flags]
public enum InstanceConnectivity
{
/// <summary>
/// The connection could not be made, either a communication error occurred or the specified <see cref="Components.ITGInstance"/> does not exist
/// </summary>
None = 0,
/// <summary>
/// The connection could be made
/// </summary>
Connected = 1,
/// <summary>
/// The connected user is authenticated
/// </summary>
Authenticated = 2,
/// <summary>
/// The connected user is an administrator
/// </summary>
Administrator = 4,
}
/// <summary>
/// The status of a BYOND update job
/// </summary>
+44 -2
View File
@@ -46,9 +46,9 @@ namespace TGServiceInterface
/// <summary>
/// The name of the current instance in use
/// The name of the current instance in use. Defaults to <see langword="null"/>
/// </summary>
public static string InstanceName;
public string InstanceName { get; private set; }
/// <summary>
/// If this is set, we will try and connect to an HTTPS server running at this address
@@ -112,6 +112,48 @@ namespace TGServiceInterface
HTTPSPassword = password;
}
/// <summary>
/// Targets <paramref name="instanceName"/> as the instance to use with <see cref="GetComponent{T}"/>. Closes all connections to any previous instance
/// </summary>
/// <param name="instanceName">The name of the instance to connect to</param>
/// <returns>The apporopriate <see cref="InstanceConnectivity"/> value</returns>
public InstanceConnectivity ConnectToInstance(string instanceName)
{
return ConnectToInstanceImpl(instanceName, false);
}
/// <summary>
/// Targets <paramref name="instanceName"/> as the instance to use with <see cref="GetComponent{T}"/>. Closes all connections to any previous instance
/// </summary>
/// <param name="instanceName">The name of the instance to connect to</param>
/// <param name="skipAuthChecks">If set to <see langword="true"/>, skips the connectivity and authentication checks and returns <see cref="InstanceConnectivity.Connected"/></param>
/// <returns>The apporopriate <see cref="InstanceConnectivity"/> value</returns>
internal InstanceConnectivity ConnectToInstanceImpl(string instanceName, bool skipAuthChecks) {
if (VerifyConnection() != null)
return InstanceConnectivity.None;
var prevInstance = InstanceName;
CloseAllChannels();
InstanceName = instanceName;
if (skipAuthChecks)
return InstanceConnectivity.Connected;
try
{
GetComponent<ITGConnectivity>().VerifyConnection();
}
catch
{
InstanceName = prevInstance;
return InstanceConnectivity.None;
}
try
{
GetComponent<ITGInstance>().ServerDirectory();
return InstanceConnectivity.Authenticated;
} catch {
return InstanceConnectivity.Connected;
}
}
/// <summary>
/// Sets the function called when a remote login fails due to the server having an invalid SSL cert
/// </summary>
@@ -56,6 +56,7 @@
<Compile Include="Components\Connectivity.cs" />
<Compile Include="Components\DreamDaemon.cs" />
<Compile Include="Components\Chat.cs" />
<Compile Include="Components\Instance.cs" />
<Compile Include="DreamDaemonBridge.cs" />
<Compile Include="Enumerations.cs" />
<Compile Include="Helpers.cs" />