From 29fbf308c1de77cfa2a19296a5a9a29a02243e0a Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 10:18:56 -0500 Subject: [PATCH 01/18] Move IServerInterface into its own file --- TGS.Interface/IServerInterface.cs | 71 ++++++++++++++++++++++++++++++ TGS.Interface/ServerInterface.cs | 67 ---------------------------- TGS.Interface/TGS.Interface.csproj | 1 + 3 files changed, 72 insertions(+), 67 deletions(-) create mode 100644 TGS.Interface/IServerInterface.cs diff --git a/TGS.Interface/IServerInterface.cs b/TGS.Interface/IServerInterface.cs new file mode 100644 index 0000000000..5f96e83302 --- /dev/null +++ b/TGS.Interface/IServerInterface.cs @@ -0,0 +1,71 @@ +using System; + +namespace TGS.Interface +{ + /// + /// Main for communicating the + /// + public interface IServerInterface : IDisposable + { + /// + /// The of the connected + /// + Version ServerVersion { get; } + + /// + /// The name of the current instance in use. Defaults to + /// + string InstanceName { get; } + + /// + /// The for the . Is for local connections + /// + RemoteLoginInfo LoginInfo { get; } + + /// + /// Checks if the is setup for a remote connection + /// + bool IsRemoteConnection { get; } + + /// + /// Targets as the instance to use with . Closes all connections to any previous instance + /// + /// The name of the instance to connect to + /// If set to , skips the connectivity and authentication checks, sets , and returns + /// The apporopriate + ConnectivityLevel ConnectToInstance(string instanceName = null, bool skipChecks = false); + + /// + /// Returns if the interface being used to connect to a service does not have the same release version as the service + /// + /// An error message to display to the user should this function return + /// if the interface being used to connect to a service does not have the same release version as the service + bool VersionMismatch(out string errorMessage); + + /// + /// Returns the requested component for the instance . This does not guarantee a successful connection. + /// + /// The component to retrieve + /// The correct component + T GetComponent(); + + /// + /// Returns a root service component + /// + /// The component for the service + T GetServiceComponent(); + + /// + /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors + /// + /// on successful connection, error message on failure + ConnectivityLevel ConnectionStatus(); + + /// + /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors + /// + /// String of the error that prevented an elevated connectivity level + /// The apporopriate + ConnectivityLevel ConnectionStatus(out string error); + } +} diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/ServerInterface.cs index 0c358d0ba5..728f1d253f 100644 --- a/TGS.Interface/ServerInterface.cs +++ b/TGS.Interface/ServerInterface.cs @@ -12,73 +12,6 @@ using TGS.Interface.Components; namespace TGS.Interface { - /// - /// Main for communicating the - /// - public interface IServerInterface : IDisposable - { - /// - /// The of the connected - /// - Version ServerVersion { get; } - - /// - /// The name of the current instance in use. Defaults to - /// - string InstanceName { get; } - - /// - /// The for the . Is for local connections - /// - RemoteLoginInfo LoginInfo { get; } - - /// - /// Checks if the is setup for a remote connection - /// - bool IsRemoteConnection { get; } - - /// - /// Targets as the instance to use with . Closes all connections to any previous instance - /// - /// The name of the instance to connect to - /// If set to , skips the connectivity and authentication checks, sets , and returns - /// The apporopriate - ConnectivityLevel ConnectToInstance(string instanceName = null, bool skipChecks = false); - - /// - /// Returns if the interface being used to connect to a service does not have the same release version as the service - /// - /// An error message to display to the user should this function return - /// if the interface being used to connect to a service does not have the same release version as the service - bool VersionMismatch(out string errorMessage); - - /// - /// Returns the requested component for the instance . This does not guarantee a successful connection. - /// - /// The component to retrieve - /// The correct component - T GetComponent(); - - /// - /// Returns a root service component - /// - /// The component for the service - T GetServiceComponent(); - - /// - /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors - /// - /// on successful connection, error message on failure - ConnectivityLevel ConnectionStatus(); - - /// - /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors - /// - /// String of the error that prevented an elevated connectivity level - /// The apporopriate - ConnectivityLevel ConnectionStatus(out string error); - } - /// sealed public class ServerInterface : IServerInterface { diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index a1b6f3d248..a6a0df7701 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -65,6 +65,7 @@ + From 842cee45be6bf4d57f40bd9d1477baabc690f90c Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 10:26:26 -0500 Subject: [PATCH 02/18] Move Definitions to their own class --- TGS.Interface/Definitions.cs | 37 +++++++++++++++++ TGS.Interface/IServerInterface.cs | 10 ++--- TGS.Interface/ServerInterface.cs | 65 +++--------------------------- TGS.Interface/TGS.Interface.csproj | 1 + TGS.Server/Server.cs | 28 ++++++++----- 5 files changed, 68 insertions(+), 73 deletions(-) create mode 100644 TGS.Interface/Definitions.cs diff --git a/TGS.Interface/Definitions.cs b/TGS.Interface/Definitions.cs new file mode 100644 index 0000000000..a39fd6ed7c --- /dev/null +++ b/TGS.Interface/Definitions.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using TGS.Interface.Components; + +namespace TGS.Interface +{ + /// + /// Contains constants for the interface + /// + public static class Definitions + { + /// + /// The maximum message size to and from a local server + /// + public const long TransferLimitLocal = Int32.MaxValue; //2GB can't go higher + + /// + /// The maximum message size to and from a remote server + /// + public const long TransferLimitRemote = 10485760; //10 MB + + /// + /// Base name of communication URLs + /// + public const string MasterInterfaceName = "TGStationServerService"; + /// + /// Base name of instance URLs + /// + public const string InstanceInterfaceName = MasterInterfaceName + "/Instance"; + + /// + /// Version of the interface + /// + public static readonly Version Version = Assembly.GetExecutingAssembly().GetName().Version; + } +} diff --git a/TGS.Interface/IServerInterface.cs b/TGS.Interface/IServerInterface.cs index 5f96e83302..fee48c91b9 100644 --- a/TGS.Interface/IServerInterface.cs +++ b/TGS.Interface/IServerInterface.cs @@ -3,12 +3,12 @@ namespace TGS.Interface { /// - /// Main for communicating the + /// Main for communicating the /// public interface IServerInterface : IDisposable { /// - /// The of the connected + /// The of the connected /// Version ServerVersion { get; } @@ -52,17 +52,17 @@ namespace TGS.Interface /// /// Returns a root service component /// - /// The component for the service + /// The component for the service T GetServiceComponent(); /// - /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors + /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors /// /// on successful connection, error message on failure ConnectivityLevel ConnectionStatus(); /// - /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors + /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors /// /// String of the error that prevented an elevated connectivity level /// The apporopriate diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/ServerInterface.cs index 728f1d253f..5045a3e2f8 100644 --- a/TGS.Interface/ServerInterface.cs +++ b/TGS.Interface/ServerInterface.cs @@ -15,39 +15,6 @@ namespace TGS.Interface /// sealed public class ServerInterface : IServerInterface { - /// - /// List of s that can be used with - /// - public static readonly IList ValidServiceInterfaces = new List { typeof(ITGSService), typeof(ITGInstanceManager), typeof(ITGConnectivity), typeof(ITGLanding) }; - - /// - /// Version of the interface - /// - public static readonly Version Version = Assembly.GetExecutingAssembly().GetName().Version; - - /// - /// List of s that can be used with - /// - public static readonly IList ValidInstanceInterfaces = CollectComponents(); - - /// - /// The maximum message size to and from a local server - /// - public const long TransferLimitLocal = Int32.MaxValue; //2GB can't go higher - - /// - /// The maximum message size to and from a remote server - /// - public const long TransferLimitRemote = 10485760; //10 MB - - /// - /// Base name of communication URLs - /// - public const string MasterInterfaceName = "TGStationServerService"; - /// - /// Base name of instance URLs - /// - public const string InstanceInterfaceName = MasterInterfaceName + "/Instance"; /// /// The @@ -92,23 +59,6 @@ namespace TGS.Interface /// IDictionary ChannelFactoryCache = new Dictionary(); - /// - /// Returns a of s that can be used with the service - /// - /// A of s that can be used with the service - static IList CollectComponents() - { - var ConnectivityComponent = typeof(ITGConnectivity); - //find all interfaces in this assembly in this namespace that have the service contract attribute - var query = from t in Assembly.GetExecutingAssembly().GetTypes() - where t.IsInterface - && t.Namespace == ConnectivityComponent.Namespace - && t.GetCustomAttribute(typeof(ServiceContractAttribute)) != null - && (t == ConnectivityComponent || !ValidServiceInterfaces.Contains(t)) - select t; - return query.ToList(); - } - /// /// Sets the function called when a remote login fails due to the server having an invalid SSL cert /// @@ -233,9 +183,10 @@ namespace TGS.Interface /// public bool VersionMismatch(out string errorMessage) { - if(ServerVersion.Major != Version.Major || ServerVersion.Minor != Version.Minor || ServerVersion.Build != Version.Build) //don't care about the patch level + var version = Definitions.Version; + if (ServerVersion.Major != version.Major || ServerVersion.Minor != version.Minor || ServerVersion.Build != version.Build) //don't care about the patch level { - errorMessage = String.Format("Version mismatch between interface version ({0}) and service version ({1}). Some functionality may crash this program.", Version, ServerVersion); + errorMessage = String.Format("Version mismatch between interface version ({0}) and service version ({1}). Some functionality may crash this program.", version, ServerVersion); return true; } errorMessage = null; @@ -246,8 +197,6 @@ namespace TGS.Interface public T GetComponent() { var ToT = typeof(T); - if (!ValidInstanceInterfaces.Contains(ToT)) - throw new Exception("Invalid type!"); return GetComponentImpl(true); } @@ -292,8 +241,6 @@ namespace TGS.Interface public T GetServiceComponent() { var ToT = typeof(T); - if (!ValidServiceInterfaces.Contains(ToT)) - throw new Exception("Invalid type!"); return GetComponentImpl(false); } @@ -305,7 +252,7 @@ namespace TGS.Interface /// The correct ChannelFactory CreateChannel(string instanceName) { - var accessPath = instanceName == null ? MasterInterfaceName : String.Format("{0}/{1}", InstanceInterfaceName, instanceName); + var accessPath = instanceName == null ? Definitions.MasterInterfaceName : String.Format("{0}/{1}", Definitions.InstanceInterfaceName, instanceName); if (!IsRemoteConnection) return CreateLocalChannel(instanceName, accessPath); return CreateRemoteChannel(instanceName, accessPath); @@ -324,7 +271,7 @@ namespace TGS.Interface { var interfaceName = typeof(T).Name; var res2 = new ChannelFactory( - new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", accessPath, interfaceName))); //10 megs + new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = Definitions.TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", accessPath, interfaceName))); //10 megs res2.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; return res2; } @@ -342,7 +289,7 @@ namespace TGS.Interface var binding = new BasicHttpsBinding() { SendTimeout = new TimeSpan(0, 0, 40), - MaxReceivedMessageSize = TransferLimitRemote + MaxReceivedMessageSize = Definitions.TransferLimitRemote }; var interfaceName = typeof(T).Name; diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index a6a0df7701..9bb024c521 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -62,6 +62,7 @@ + diff --git a/TGS.Server/Server.cs b/TGS.Server/Server.cs index 513e25e20f..4b4cfc7fcb 100644 --- a/TGS.Server/Server.cs +++ b/TGS.Server/Server.cs @@ -198,9 +198,11 @@ namespace TGS.Server /// void SetupService() { - serviceHost = CreateHost(this, ServerInterface.MasterInterfaceName); - foreach (var I in ServerInterface.ValidServiceInterfaces) - AddEndpoint(serviceHost, I); + serviceHost = CreateHost(this, Definitions.MasterInterfaceName); + AddEndpoint(serviceHost, typeof(ITGConnectivity)); + AddEndpoint(serviceHost, typeof(ITGInstanceManager)); + AddEndpoint(serviceHost, typeof(ITGLanding)); + AddEndpoint(serviceHost, typeof(ITGSService)); serviceHost.Authorization.ServiceAuthorizationManager = new RootAuthorizationManager(); //only admins can diddle us serviceHost.Authentication.ServiceAuthenticationManager = new AuthenticationHeaderDecoder(); } @@ -313,11 +315,19 @@ namespace TGS.Server return null; } - var host = CreateHost(instance, String.Format("{0}/{1}", ServerInterface.InstanceInterfaceName, instanceName)); + var host = CreateHost(instance, String.Format("{0}/{1}", Definitions.InstanceInterfaceName, instanceName)); hosts.Add(instanceName, host); - - foreach (var J in ServerInterface.ValidInstanceInterfaces) - AddEndpoint(host, J); + + AddEndpoint(host, typeof(ITGConnectivity)); + AddEndpoint(host, typeof(ITGAdministration)); + AddEndpoint(host, typeof(ITGChat)); + AddEndpoint(host, typeof(ITGCompiler)); + AddEndpoint(host, typeof(ITGConfig)); + AddEndpoint(host, typeof(ITGConnectivity)); + AddEndpoint(host, typeof(ITGDreamDaemon)); + AddEndpoint(host, typeof(ITGInstance)); + AddEndpoint(host, typeof(ITGInterop)); + AddEndpoint(host, typeof(ITGRepository)); host.Authorization.ServiceAuthorizationManager = instance; host.Authentication.ServiceAuthenticationManager = new AuthenticationHeaderDecoder(); @@ -332,11 +342,11 @@ namespace TGS.Server void AddEndpoint(ServiceHost host, Type typetype) { var bindingName = typetype.Name; - host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = ServerInterface.TransferLimitLocal }, bindingName); + host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = Definitions.TransferLimitLocal }, bindingName); var httpsBinding = new BasicHttpsBinding() { SendTimeout = new TimeSpan(0, 0, 40), - MaxReceivedMessageSize = ServerInterface.TransferLimitRemote + MaxReceivedMessageSize = Definitions.TransferLimitRemote }; var requireAuth = typetype.Name != typeof(ITGConnectivity).Name; host.AddServiceEndpoint(typetype, httpsBinding, bindingName); From 462a491c085a0486a2224413fa975208254891c0 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 10:36:48 -0500 Subject: [PATCH 03/18] Add IServer and IInstance --- TGS.Interface/IInstance.cs | 50 ++++++++++++++++++++++++++++++ TGS.Interface/IServer.cs | 34 ++++++++++++++++++++ TGS.Interface/TGS.Interface.csproj | 2 ++ 3 files changed, 86 insertions(+) create mode 100644 TGS.Interface/IInstance.cs create mode 100644 TGS.Interface/IServer.cs diff --git a/TGS.Interface/IInstance.cs b/TGS.Interface/IInstance.cs new file mode 100644 index 0000000000..c7e17c3e99 --- /dev/null +++ b/TGS.Interface/IInstance.cs @@ -0,0 +1,50 @@ +using TGS.Interface.Components; + +namespace TGS.Interface +{ + /// + /// Wrapper for components + /// + public interface IInstance : ITGInstance + { + /// + /// The component + /// + ITGAdministration Administration { get; } + + /// + /// The component + /// + ITGByond Byond { get; } + + /// + /// The component + /// + ITGChat Chat { get; } + + /// + /// The component + /// + ITGCompiler Compiler { get; } + + /// + /// The component + /// + ITGConfig Config { get; } + + /// + /// The component + /// + ITGDreamDaemon DreamDaemon { get; } + + /// + /// The component + /// + ITGInterop Interop { get; } + + /// + /// The component + /// + ITGRepository Repository { get; } + } +} diff --git a/TGS.Interface/IServer.cs b/TGS.Interface/IServer.cs new file mode 100644 index 0000000000..27125a44ba --- /dev/null +++ b/TGS.Interface/IServer.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using TGS.Interface.Components; + +namespace TGS.Interface +{ + /// + /// Wrapper representing a + /// + public interface IServer : ITGSService + { + /// + /// The of the + /// + new Version Version { get; } + + /// + /// Get the s the contains that the current user can access + /// + IEnumerable Instances { get; } + + /// + /// The component + /// + ITGInstanceManager InstanceManager { get; } + + /// + /// Gets the specified + /// + /// The name of the to get + /// The named on success, on failure + IInstance GetInstance(string name); + } +} diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index 9bb024c521..ebd639db8b 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -65,7 +65,9 @@ + + From ff7a8b83ad73f650db28d6ec7621c9572cfac8ae Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 10:41:52 -0500 Subject: [PATCH 04/18] Move IServer and IInstance to TGS.Interface.Wrappers --- TGS.Interface/TGS.Interface.csproj | 4 ++-- TGS.Interface/{ => Wrappers}/IInstance.cs | 2 +- TGS.Interface/{ => Wrappers}/IServer.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename TGS.Interface/{ => Wrappers}/IInstance.cs (97%) rename TGS.Interface/{ => Wrappers}/IServer.cs (96%) diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index ebd639db8b..a4c2eae616 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -65,9 +65,9 @@ - + - + diff --git a/TGS.Interface/IInstance.cs b/TGS.Interface/Wrappers/IInstance.cs similarity index 97% rename from TGS.Interface/IInstance.cs rename to TGS.Interface/Wrappers/IInstance.cs index c7e17c3e99..cf1f759785 100644 --- a/TGS.Interface/IInstance.cs +++ b/TGS.Interface/Wrappers/IInstance.cs @@ -1,6 +1,6 @@ using TGS.Interface.Components; -namespace TGS.Interface +namespace TGS.Interface.Wrappers { /// /// Wrapper for components diff --git a/TGS.Interface/IServer.cs b/TGS.Interface/Wrappers/IServer.cs similarity index 96% rename from TGS.Interface/IServer.cs rename to TGS.Interface/Wrappers/IServer.cs index 27125a44ba..ab7038ec34 100644 --- a/TGS.Interface/IServer.cs +++ b/TGS.Interface/Wrappers/IServer.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using TGS.Interface.Components; -namespace TGS.Interface +namespace TGS.Interface.Wrappers { /// /// Wrapper representing a From 79674a3536500f86ad67c8ee2e6c05f0897be524 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 10:54:37 -0500 Subject: [PATCH 05/18] Implement IInstance --- TGS.Interface/ServerInterface.cs | 22 +++++----- TGS.Interface/TGS.Interface.csproj | 1 + TGS.Interface/Wrappers/Instance.cs | 64 ++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 TGS.Interface/Wrappers/Instance.cs diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/ServerInterface.cs index 5045a3e2f8..bdb1d295aa 100644 --- a/TGS.Interface/ServerInterface.cs +++ b/TGS.Interface/ServerInterface.cs @@ -9,6 +9,7 @@ using System.Security.Principal; using System.ServiceModel; using System.ServiceModel.Description; using TGS.Interface.Components; +using TGS.Interface.Wrappers; namespace TGS.Interface { @@ -196,23 +197,24 @@ namespace TGS.Interface /// public T GetComponent() { - var ToT = typeof(T); - return GetComponentImpl(true); + if(InstanceName == null) + throw new InvalidOperationException("Instance not selected!"); + return GetComponent(InstanceName); } /// /// Returns the requested component for the instance . This does not guarantee a successful connection. s created this way are recycled for minimum latency and bandwidth usage /// /// The component to retrieve - /// If should be used to connect + /// The name of the to use /// The correct component - T GetComponentImpl(bool useInstanceName) + internal T GetComponent(string instanceName) { - if (useInstanceName & InstanceName == null) - throw new Exception("Instance not selected!"); + if (disposedValue) + throw new ObjectDisposedException(GetType().Name); var actualToT = typeof(T); var tot = actualToT.Name; - if (actualToT == typeof(ITGConnectivity) && !useInstanceName) + if (actualToT == typeof(ITGConnectivity) && instanceName == null) tot = 'S' + tot; ChannelFactory cf; @@ -231,7 +233,7 @@ namespace TGS.Interface ChannelFactoryCache[tot].Abort(); ChannelFactoryCache.Remove(tot); } - cf = CreateChannel(useInstanceName ? InstanceName : null); + cf = CreateChannel(instanceName); ChannelFactoryCache[tot] = cf; } return cf.CreateChannel(); @@ -241,7 +243,7 @@ namespace TGS.Interface public T GetServiceComponent() { var ToT = typeof(T); - return GetComponentImpl(false); + return GetComponent(null); } /// @@ -328,7 +330,7 @@ namespace TGS.Interface { try { - GetComponentImpl(false).VerifyConnection(); + GetComponent(null).VerifyConnection(); } catch (Exception e) { diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index a4c2eae616..80043925e2 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -67,6 +67,7 @@ + diff --git a/TGS.Interface/Wrappers/Instance.cs b/TGS.Interface/Wrappers/Instance.cs new file mode 100644 index 0000000000..355c0d831d --- /dev/null +++ b/TGS.Interface/Wrappers/Instance.cs @@ -0,0 +1,64 @@ +using TGS.Interface.Components; + +namespace TGS.Interface.Wrappers +{ + /// + sealed class Instance : IInstance + { + /// + /// The backing + /// + readonly ServerInterface serverInterface; + /// + /// The name of the + /// + readonly string instanceName; + + /// + /// Construct an + /// + /// The to use + /// The name to use + public Instance(ServerInterface _serverInterface, string _instanceName) + { + serverInterface = _serverInterface; + instanceName = _instanceName; + } + + /// + public ITGAdministration Administration => serverInterface.GetComponent(instanceName); + + /// + public ITGByond Byond => serverInterface.GetComponent(instanceName); + + /// + public ITGChat Chat => serverInterface.GetComponent(instanceName); + + /// + public ITGCompiler Compiler => serverInterface.GetComponent(instanceName); + + /// + public ITGConfig Config => serverInterface.GetComponent(instanceName); + + /// + public ITGDreamDaemon DreamDaemon => serverInterface.GetComponent(instanceName); + + /// + public ITGInterop Interop => serverInterface.GetComponent(instanceName); + + /// + public ITGRepository Repository => serverInterface.GetComponent(instanceName); + + /// + public string ServerDirectory() + { + return serverInterface.GetComponent(instanceName).ServerDirectory(); + } + + /// + public string Version() + { + return serverInterface.GetComponent(instanceName).Version(); + } + } +} From 6a1911e573f9bca47cd28a3cad16fbc898c529cb Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 11:09:47 -0500 Subject: [PATCH 06/18] Implement IServer. Add some missing things to IInstance --- TGS.Interface/TGS.Interface.csproj | 1 + TGS.Interface/Wrappers/IInstance.cs | 5 ++ TGS.Interface/Wrappers/Instance.cs | 43 +++++++++----- TGS.Interface/Wrappers/Server.cs | 88 +++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 15 deletions(-) create mode 100644 TGS.Interface/Wrappers/Server.cs diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index 80043925e2..fd1a344ca5 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -79,6 +79,7 @@ + diff --git a/TGS.Interface/Wrappers/IInstance.cs b/TGS.Interface/Wrappers/IInstance.cs index cf1f759785..a6895998d9 100644 --- a/TGS.Interface/Wrappers/IInstance.cs +++ b/TGS.Interface/Wrappers/IInstance.cs @@ -7,6 +7,11 @@ namespace TGS.Interface.Wrappers /// public interface IInstance : ITGInstance { + /// + /// Get the for the + /// + InstanceMetadata Metadata { get; } + /// /// The component /// diff --git a/TGS.Interface/Wrappers/Instance.cs b/TGS.Interface/Wrappers/Instance.cs index 355c0d831d..77e304af38 100644 --- a/TGS.Interface/Wrappers/Instance.cs +++ b/TGS.Interface/Wrappers/Instance.cs @@ -1,4 +1,5 @@ -using TGS.Interface.Components; +using System.Linq; +using TGS.Interface.Components; namespace TGS.Interface.Wrappers { @@ -12,53 +13,65 @@ namespace TGS.Interface.Wrappers /// /// The name of the /// - readonly string instanceName; + InstanceMetadata metadata; /// /// Construct an /// /// The to use - /// The name to use - public Instance(ServerInterface _serverInterface, string _instanceName) + /// The for the + public Instance(ServerInterface _serverInterface, InstanceMetadata _metadata) { serverInterface = _serverInterface; - instanceName = _instanceName; + metadata = _metadata; } /// - public ITGAdministration Administration => serverInterface.GetComponent(instanceName); + public InstanceMetadata Metadata + { + get + { + if (!metadata.Enabled) + //metadata needs populating + metadata = serverInterface.GetComponent(null).ListInstances().Where(x => x.Name == metadata.Name).First(); + return metadata; + } + } /// - public ITGByond Byond => serverInterface.GetComponent(instanceName); + public ITGAdministration Administration => serverInterface.GetComponent(metadata.Name); /// - public ITGChat Chat => serverInterface.GetComponent(instanceName); + public ITGByond Byond => serverInterface.GetComponent(metadata.Name); /// - public ITGCompiler Compiler => serverInterface.GetComponent(instanceName); + public ITGChat Chat => serverInterface.GetComponent(metadata.Name); /// - public ITGConfig Config => serverInterface.GetComponent(instanceName); + public ITGCompiler Compiler => serverInterface.GetComponent(metadata.Name); /// - public ITGDreamDaemon DreamDaemon => serverInterface.GetComponent(instanceName); + public ITGConfig Config => serverInterface.GetComponent(metadata.Name); /// - public ITGInterop Interop => serverInterface.GetComponent(instanceName); + public ITGDreamDaemon DreamDaemon => serverInterface.GetComponent(metadata.Name); /// - public ITGRepository Repository => serverInterface.GetComponent(instanceName); + public ITGInterop Interop => serverInterface.GetComponent(metadata.Name); + + /// + public ITGRepository Repository => serverInterface.GetComponent(metadata.Name); /// public string ServerDirectory() { - return serverInterface.GetComponent(instanceName).ServerDirectory(); + return serverInterface.GetComponent(metadata.Name).ServerDirectory(); } /// public string Version() { - return serverInterface.GetComponent(instanceName).Version(); + return serverInterface.GetComponent(metadata.Name).Version(); } } } diff --git a/TGS.Interface/Wrappers/Server.cs b/TGS.Interface/Wrappers/Server.cs new file mode 100644 index 0000000000..c45b1f820c --- /dev/null +++ b/TGS.Interface/Wrappers/Server.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using TGS.Interface.Components; + +namespace TGS.Interface.Wrappers +{ + /// + sealed class Server : IServer + { + /// + public Version Version => serverInterface.ServerVersion; + + /// + public IEnumerable Instances { get + { + lock (this) + if(knownInstances == null) + knownInstances = serverInterface.GetComponent().ListInstances(); + foreach(var I in knownInstances) + yield return new Instance(serverInterface, I); + } + } + + /// + public ITGInstanceManager InstanceManager => serverInterface.GetComponent(); + + /// + /// The backing + /// + readonly ServerInterface serverInterface; + + /// + /// Result of a call to + /// + IList knownInstances; + + /// + /// Construct an + /// + /// The to use + public Server(ServerInterface _serverInterface) + { + serverInterface = _serverInterface; + } + + /// + public IInstance GetInstance(string name) + { + return new Instance(serverInterface, new InstanceMetadata { Name = name, Enabled = false }); + } + + /// + public void PrepareForUpdate() + { + serverInterface.GetComponent().PrepareForUpdate(); + } + + /// + public string PythonPath() + { + return serverInterface.GetComponent().PythonPath(); + } + + /// + public ushort RemoteAccessPort() + { + return serverInterface.GetComponent().RemoteAccessPort(); + } + + /// + public bool SetPythonPath(string path) + { + return serverInterface.GetComponent().SetPythonPath(path); + } + + /// + public string SetRemoteAccessPort(ushort port) + { + return serverInterface.GetComponent().SetRemoteAccessPort(port); + } + + /// + string ITGSService.Version() + { + return serverInterface.GetComponent().Version(); + } + } +} From 5d21df71fdad6e7c45292ae088061094736505bb Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 11:13:42 -0500 Subject: [PATCH 07/18] Add IServer to IServerInterface --- TGS.Interface/IServerInterface.cs | 6 ++++++ TGS.Interface/ServerInterface.cs | 28 +++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/TGS.Interface/IServerInterface.cs b/TGS.Interface/IServerInterface.cs index fee48c91b9..42980e7e12 100644 --- a/TGS.Interface/IServerInterface.cs +++ b/TGS.Interface/IServerInterface.cs @@ -1,4 +1,5 @@ using System; +using TGS.Interface.Wrappers; namespace TGS.Interface { @@ -7,6 +8,11 @@ namespace TGS.Interface /// public interface IServerInterface : IDisposable { + /// + /// The the connects to + /// + IServer Server { get; } + /// /// The of the connected /// diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/ServerInterface.cs index bdb1d295aa..fe3b52f18b 100644 --- a/TGS.Interface/ServerInterface.cs +++ b/TGS.Interface/ServerInterface.cs @@ -16,11 +16,8 @@ namespace TGS.Interface /// sealed public class ServerInterface : IServerInterface { - - /// - /// The - /// - Version _serverVersion; + /// + public IServer Server => server; /// public Version ServerVersion { get @@ -47,13 +44,23 @@ namespace TGS.Interface /// public string InstanceName { get; private set; } + /// + public RemoteLoginInfo LoginInfo { get { return _loginInfo; } } + + /// + /// Backing field for + /// + readonly IServer server; + /// /// Backing field for /// readonly RemoteLoginInfo _loginInfo; - /// - public RemoteLoginInfo LoginInfo { get { return _loginInfo; } } + /// + /// The + /// + Version _serverVersion; /// /// Associated list of open s keyed by type name. A in this list may close or fault at any time. Must be locked before being accessed @@ -94,13 +101,16 @@ namespace TGS.Interface /// /// Construct an for a local connection /// - public ServerInterface() { } + public ServerInterface() + { + server = new Server(this); + } /// /// Construct an for a remote connection /// /// The for a remote connection - public ServerInterface(RemoteLoginInfo loginInfo) + public ServerInterface(RemoteLoginInfo loginInfo) : this() { if (!loginInfo.HasPassword) throw new InvalidOperationException("password must be set on loginInfo!"); From 4e1dbbb215875b80301c997286ed9ea44162a818 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 11:28:07 -0500 Subject: [PATCH 08/18] Fix a few calls to the wrong GetComponent --- TGS.Interface/Wrappers/IServer.cs | 2 +- TGS.Interface/Wrappers/Server.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/TGS.Interface/Wrappers/IServer.cs b/TGS.Interface/Wrappers/IServer.cs index ab7038ec34..130d622ca4 100644 --- a/TGS.Interface/Wrappers/IServer.cs +++ b/TGS.Interface/Wrappers/IServer.cs @@ -25,7 +25,7 @@ namespace TGS.Interface.Wrappers ITGInstanceManager InstanceManager { get; } /// - /// Gets the specified + /// Gets the specified without connectivity checks /// /// The name of the to get /// The named on success, on failure diff --git a/TGS.Interface/Wrappers/Server.cs b/TGS.Interface/Wrappers/Server.cs index c45b1f820c..9276c64e88 100644 --- a/TGS.Interface/Wrappers/Server.cs +++ b/TGS.Interface/Wrappers/Server.cs @@ -15,14 +15,14 @@ namespace TGS.Interface.Wrappers { lock (this) if(knownInstances == null) - knownInstances = serverInterface.GetComponent().ListInstances(); + knownInstances = serverInterface.GetComponent(null).ListInstances(); foreach(var I in knownInstances) yield return new Instance(serverInterface, I); } } /// - public ITGInstanceManager InstanceManager => serverInterface.GetComponent(); + public ITGInstanceManager InstanceManager => serverInterface.GetComponent(null); /// /// The backing @@ -52,37 +52,37 @@ namespace TGS.Interface.Wrappers /// public void PrepareForUpdate() { - serverInterface.GetComponent().PrepareForUpdate(); + serverInterface.GetComponent(null).PrepareForUpdate(); } /// public string PythonPath() { - return serverInterface.GetComponent().PythonPath(); + return serverInterface.GetComponent(null).PythonPath(); } /// public ushort RemoteAccessPort() { - return serverInterface.GetComponent().RemoteAccessPort(); + return serverInterface.GetComponent(null).RemoteAccessPort(); } /// public bool SetPythonPath(string path) { - return serverInterface.GetComponent().SetPythonPath(path); + return serverInterface.GetComponent(null).SetPythonPath(path); } /// public string SetRemoteAccessPort(ushort port) { - return serverInterface.GetComponent().SetRemoteAccessPort(port); + return serverInterface.GetComponent(null).SetRemoteAccessPort(port); } /// string ITGSService.Version() { - return serverInterface.GetComponent().Version(); + return serverInterface.GetComponent(null).Version(); } } } From 3ad606c3271bc1cdaa0a46b738735e1a9404fa50 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 11:34:52 -0500 Subject: [PATCH 09/18] Fix some safety connectivity issues regarding IInstance enumeration --- TGS.Interface/Wrappers/IServer.cs | 2 +- TGS.Interface/Wrappers/Instance.cs | 3 +++ TGS.Interface/Wrappers/Server.cs | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/TGS.Interface/Wrappers/IServer.cs b/TGS.Interface/Wrappers/IServer.cs index 130d622ca4..e06e7cb624 100644 --- a/TGS.Interface/Wrappers/IServer.cs +++ b/TGS.Interface/Wrappers/IServer.cs @@ -15,7 +15,7 @@ namespace TGS.Interface.Wrappers new Version Version { get; } /// - /// Get the s the contains that the current user can access + /// Get the s the contains that the current user can access and connect to /// IEnumerable Instances { get; } diff --git a/TGS.Interface/Wrappers/Instance.cs b/TGS.Interface/Wrappers/Instance.cs index 77e304af38..72d9e364b4 100644 --- a/TGS.Interface/Wrappers/Instance.cs +++ b/TGS.Interface/Wrappers/Instance.cs @@ -24,6 +24,9 @@ namespace TGS.Interface.Wrappers { serverInterface = _serverInterface; metadata = _metadata; + if (metadata.Enabled) + //run a connectivity check + serverInterface.GetComponent(metadata.Name).VerifyConnection(); } /// diff --git a/TGS.Interface/Wrappers/Server.cs b/TGS.Interface/Wrappers/Server.cs index 9276c64e88..71b918ffe2 100644 --- a/TGS.Interface/Wrappers/Server.cs +++ b/TGS.Interface/Wrappers/Server.cs @@ -14,10 +14,21 @@ namespace TGS.Interface.Wrappers public IEnumerable Instances { get { lock (this) - if(knownInstances == null) + if (knownInstances == null) knownInstances = serverInterface.GetComponent(null).ListInstances(); - foreach(var I in knownInstances) - yield return new Instance(serverInterface, I); + foreach (var I in knownInstances) + { + IInstance nextInstance; + try + { + nextInstance = new Instance(serverInterface, I); + } + catch + { + continue; + } + yield return nextInstance; + } } } From 61c7e3f1ee52f9bea4eb66b5683e2e07786247de Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 12:05:51 -0500 Subject: [PATCH 10/18] More security improvements to the wrappers --- TGS.Interface/Wrappers/IInstance.cs | 7 +++- TGS.Interface/Wrappers/IServer.cs | 11 +++-- TGS.Interface/Wrappers/Instance.cs | 26 +++++++++++- TGS.Interface/Wrappers/Server.cs | 63 +++++++++++++---------------- 4 files changed, 66 insertions(+), 41 deletions(-) diff --git a/TGS.Interface/Wrappers/IInstance.cs b/TGS.Interface/Wrappers/IInstance.cs index a6895998d9..81db529014 100644 --- a/TGS.Interface/Wrappers/IInstance.cs +++ b/TGS.Interface/Wrappers/IInstance.cs @@ -13,7 +13,12 @@ namespace TGS.Interface.Wrappers InstanceMetadata Metadata { get; } /// - /// The component + /// Check if the connected user is an administrator of the + /// + bool UserIsAdministrator { get; } + + /// + /// The component. Will be if is /// ITGAdministration Administration { get; } diff --git a/TGS.Interface/Wrappers/IServer.cs b/TGS.Interface/Wrappers/IServer.cs index e06e7cb624..48ffc3d6cf 100644 --- a/TGS.Interface/Wrappers/IServer.cs +++ b/TGS.Interface/Wrappers/IServer.cs @@ -7,12 +7,12 @@ namespace TGS.Interface.Wrappers /// /// Wrapper representing a /// - public interface IServer : ITGSService + public interface IServer { /// /// The of the /// - new Version Version { get; } + Version Version { get; } /// /// Get the s the contains that the current user can access and connect to @@ -20,10 +20,15 @@ namespace TGS.Interface.Wrappers IEnumerable Instances { get; } /// - /// The component + /// The component. Will be if the connected user is not an administrator of the /// ITGInstanceManager InstanceManager { get; } + /// + /// The component. Will be if the connected user is not an administrator of the + /// + ITGSService Management { get; } + /// /// Gets the specified without connectivity checks /// diff --git a/TGS.Interface/Wrappers/Instance.cs b/TGS.Interface/Wrappers/Instance.cs index 72d9e364b4..f90d2202c8 100644 --- a/TGS.Interface/Wrappers/Instance.cs +++ b/TGS.Interface/Wrappers/Instance.cs @@ -14,6 +14,10 @@ namespace TGS.Interface.Wrappers /// The name of the /// InstanceMetadata metadata; + /// + /// Whether or not the current user is known to be an administrator of the + /// + bool isAdministrator; /// /// Construct an @@ -41,8 +45,28 @@ namespace TGS.Interface.Wrappers } } + public bool UserIsAdministrator { get + { + lock (this) + { + if (isAdministrator) + return true; + try + { + Administration.GetCurrentAuthorizedGroup(); + isAdministrator = true; + return true; + } + catch + { + return false; + } + } + } + } + /// - public ITGAdministration Administration => serverInterface.GetComponent(metadata.Name); + public ITGAdministration Administration => UserIsAdministrator ? serverInterface.GetComponent(metadata.Name) : null; /// public ITGByond Byond => serverInterface.GetComponent(metadata.Name); diff --git a/TGS.Interface/Wrappers/Server.cs b/TGS.Interface/Wrappers/Server.cs index 71b918ffe2..a826b623f4 100644 --- a/TGS.Interface/Wrappers/Server.cs +++ b/TGS.Interface/Wrappers/Server.cs @@ -35,10 +35,37 @@ namespace TGS.Interface.Wrappers /// public ITGInstanceManager InstanceManager => serverInterface.GetComponent(null); + /// + public ITGSService Management + { + get + { + var component = serverInterface.GetComponent(null); + lock (this) + { + if (!userIsAdministrator) + try + { + var test = component.Version(); + userIsAdministrator = true; + } + catch + { + return null; + } + } + return component; + } + } + /// /// The backing /// readonly ServerInterface serverInterface; + /// + /// If the connected user is an administrator of the + /// + bool userIsAdministrator; /// /// Result of a call to @@ -59,41 +86,5 @@ namespace TGS.Interface.Wrappers { return new Instance(serverInterface, new InstanceMetadata { Name = name, Enabled = false }); } - - /// - public void PrepareForUpdate() - { - serverInterface.GetComponent(null).PrepareForUpdate(); - } - - /// - public string PythonPath() - { - return serverInterface.GetComponent(null).PythonPath(); - } - - /// - public ushort RemoteAccessPort() - { - return serverInterface.GetComponent(null).RemoteAccessPort(); - } - - /// - public bool SetPythonPath(string path) - { - return serverInterface.GetComponent(null).SetPythonPath(path); - } - - /// - public string SetRemoteAccessPort(ushort port) - { - return serverInterface.GetComponent(null).SetRemoteAccessPort(port); - } - - /// - string ITGSService.Version() - { - return serverInterface.GetComponent(null).Version(); - } } } From e15367c0e7210de5da10d7011e940c7474e6088f Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 12:26:45 -0500 Subject: [PATCH 11/18] More wrapper standardization --- TGS.Interface/Wrappers/IInstance.cs | 7 +-- TGS.Interface/Wrappers/Instance.cs | 83 +++++++++++++++++------------ TGS.Interface/Wrappers/Server.cs | 42 ++++++++------- 3 files changed, 74 insertions(+), 58 deletions(-) diff --git a/TGS.Interface/Wrappers/IInstance.cs b/TGS.Interface/Wrappers/IInstance.cs index 81db529014..9cfc086a98 100644 --- a/TGS.Interface/Wrappers/IInstance.cs +++ b/TGS.Interface/Wrappers/IInstance.cs @@ -13,12 +13,7 @@ namespace TGS.Interface.Wrappers InstanceMetadata Metadata { get; } /// - /// Check if the connected user is an administrator of the - /// - bool UserIsAdministrator { get; } - - /// - /// The component. Will be if is + /// The component. Will be if the connected user is not an administrator of the /// ITGAdministration Administration { get; } diff --git a/TGS.Interface/Wrappers/Instance.cs b/TGS.Interface/Wrappers/Instance.cs index f90d2202c8..92ca59499d 100644 --- a/TGS.Interface/Wrappers/Instance.cs +++ b/TGS.Interface/Wrappers/Instance.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using TGS.Interface.Components; namespace TGS.Interface.Wrappers @@ -6,6 +7,43 @@ namespace TGS.Interface.Wrappers /// sealed class Instance : IInstance { + /// + public InstanceMetadata Metadata + { + get + { + if (!metadata.Enabled) + //metadata needs populating + metadata = serverInterface.GetComponent(null).ListInstances().Where(x => x.Name == metadata.Name).First(); + return metadata; + } + } + + /// + /// Whether or not the current user is known to be an administrator of the + /// + bool UserIsAdministrator + { + get + { + lock (this) + { + if (isAdministrator) + return true; + try + { + serverInterface.GetComponent(metadata.Name).GetCurrentAuthorizedGroup(); + isAdministrator = true; + return true; + } + catch + { + return false; + } + } + } + } + /// /// The backing /// @@ -15,7 +53,7 @@ namespace TGS.Interface.Wrappers /// InstanceMetadata metadata; /// - /// Whether or not the current user is known to be an administrator of the + /// Backing field for /// bool isAdministrator; @@ -33,38 +71,6 @@ namespace TGS.Interface.Wrappers serverInterface.GetComponent(metadata.Name).VerifyConnection(); } - /// - public InstanceMetadata Metadata - { - get - { - if (!metadata.Enabled) - //metadata needs populating - metadata = serverInterface.GetComponent(null).ListInstances().Where(x => x.Name == metadata.Name).First(); - return metadata; - } - } - - public bool UserIsAdministrator { get - { - lock (this) - { - if (isAdministrator) - return true; - try - { - Administration.GetCurrentAuthorizedGroup(); - isAdministrator = true; - return true; - } - catch - { - return false; - } - } - } - } - /// public ITGAdministration Administration => UserIsAdministrator ? serverInterface.GetComponent(metadata.Name) : null; @@ -100,5 +106,14 @@ namespace TGS.Interface.Wrappers { return serverInterface.GetComponent(metadata.Name).Version(); } + + /// + /// Get a string representation of the + /// + /// A string representation of the + public override string ToString() + { + return String.Format("{0}: {1} - {2} - {3}", metadata.LoggingID, metadata.Name, metadata.Path, metadata.Enabled ? "ONLINE" : "OFFLINE"); + } } } diff --git a/TGS.Interface/Wrappers/Server.cs b/TGS.Interface/Wrappers/Server.cs index a826b623f4..2d38580c00 100644 --- a/TGS.Interface/Wrappers/Server.cs +++ b/TGS.Interface/Wrappers/Server.cs @@ -33,28 +33,33 @@ namespace TGS.Interface.Wrappers } /// - public ITGInstanceManager InstanceManager => serverInterface.GetComponent(null); + public ITGInstanceManager InstanceManager => UserIsAdministrator ? serverInterface.GetComponent(null) : null; /// - public ITGSService Management + public ITGSService Management => UserIsAdministrator ? serverInterface.GetComponent(null) : null; + + /// + /// If the connected user is an administrator of the + /// + bool UserIsAdministrator { get { - var component = serverInterface.GetComponent(null); lock (this) { - if (!userIsAdministrator) - try - { - var test = component.Version(); - userIsAdministrator = true; - } - catch - { - return null; - } + if (isAdministrator) + return true; + try + { + serverInterface.GetComponent(null).Version(); + isAdministrator = true; + return true; + } + catch + { + return false; + } } - return component; } } @@ -62,16 +67,17 @@ namespace TGS.Interface.Wrappers /// The backing /// readonly ServerInterface serverInterface; - /// - /// If the connected user is an administrator of the - /// - bool userIsAdministrator; /// /// Result of a call to /// IList knownInstances; + /// + /// Backing field for + /// + bool isAdministrator; + /// /// Construct an /// From 50054f089a4c53b334dd4c34efcad4350fc612aa Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 12:29:10 -0500 Subject: [PATCH 12/18] Removes Wrappers namespace and old ServerInterface functions --- TGS.Interface/{Wrappers => }/IInstance.cs | 2 +- TGS.Interface/{Wrappers => }/IServer.cs | 2 +- TGS.Interface/IServerInterface.cs | 35 +----- TGS.Interface/{Wrappers => }/Instance.cs | 2 +- TGS.Interface/{Wrappers => }/Server.cs | 2 +- TGS.Interface/ServerInterface.cs | 144 +++------------------- TGS.Interface/TGS.Interface.csproj | 8 +- 7 files changed, 29 insertions(+), 166 deletions(-) rename TGS.Interface/{Wrappers => }/IInstance.cs (97%) rename TGS.Interface/{Wrappers => }/IServer.cs (97%) rename TGS.Interface/{Wrappers => }/Instance.cs (99%) rename TGS.Interface/{Wrappers => }/Server.cs (98%) diff --git a/TGS.Interface/Wrappers/IInstance.cs b/TGS.Interface/IInstance.cs similarity index 97% rename from TGS.Interface/Wrappers/IInstance.cs rename to TGS.Interface/IInstance.cs index 9cfc086a98..66ca33e94f 100644 --- a/TGS.Interface/Wrappers/IInstance.cs +++ b/TGS.Interface/IInstance.cs @@ -1,6 +1,6 @@ using TGS.Interface.Components; -namespace TGS.Interface.Wrappers +namespace TGS.Interface { /// /// Wrapper for components diff --git a/TGS.Interface/Wrappers/IServer.cs b/TGS.Interface/IServer.cs similarity index 97% rename from TGS.Interface/Wrappers/IServer.cs rename to TGS.Interface/IServer.cs index 48ffc3d6cf..a81c6de744 100644 --- a/TGS.Interface/Wrappers/IServer.cs +++ b/TGS.Interface/IServer.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using TGS.Interface.Components; -namespace TGS.Interface.Wrappers +namespace TGS.Interface { /// /// Wrapper representing a diff --git a/TGS.Interface/IServerInterface.cs b/TGS.Interface/IServerInterface.cs index 42980e7e12..9848bcb588 100644 --- a/TGS.Interface/IServerInterface.cs +++ b/TGS.Interface/IServerInterface.cs @@ -1,5 +1,4 @@ using System; -using TGS.Interface.Wrappers; namespace TGS.Interface { @@ -13,16 +12,6 @@ namespace TGS.Interface /// IServer Server { get; } - /// - /// The of the connected - /// - Version ServerVersion { get; } - - /// - /// The name of the current instance in use. Defaults to - /// - string InstanceName { get; } - /// /// The for the . Is for local connections /// @@ -33,14 +22,6 @@ namespace TGS.Interface /// bool IsRemoteConnection { get; } - /// - /// Targets as the instance to use with . Closes all connections to any previous instance - /// - /// The name of the instance to connect to - /// If set to , skips the connectivity and authentication checks, sets , and returns - /// The apporopriate - ConnectivityLevel ConnectToInstance(string instanceName = null, bool skipChecks = false); - /// /// Returns if the interface being used to connect to a service does not have the same release version as the service /// @@ -49,22 +30,8 @@ namespace TGS.Interface bool VersionMismatch(out string errorMessage); /// - /// Returns the requested component for the instance . This does not guarantee a successful connection. + /// See without the error argument /// - /// The component to retrieve - /// The correct component - T GetComponent(); - - /// - /// Returns a root service component - /// - /// The component for the service - T GetServiceComponent(); - - /// - /// Used to test if the is avaiable on the target machine. Note that state can change at any time and any call into the may throw an exception because of communcation errors - /// - /// on successful connection, error message on failure ConnectivityLevel ConnectionStatus(); /// diff --git a/TGS.Interface/Wrappers/Instance.cs b/TGS.Interface/Instance.cs similarity index 99% rename from TGS.Interface/Wrappers/Instance.cs rename to TGS.Interface/Instance.cs index 92ca59499d..a02a833685 100644 --- a/TGS.Interface/Wrappers/Instance.cs +++ b/TGS.Interface/Instance.cs @@ -2,7 +2,7 @@ using System.Linq; using TGS.Interface.Components; -namespace TGS.Interface.Wrappers +namespace TGS.Interface { /// sealed class Instance : IInstance diff --git a/TGS.Interface/Wrappers/Server.cs b/TGS.Interface/Server.cs similarity index 98% rename from TGS.Interface/Wrappers/Server.cs rename to TGS.Interface/Server.cs index 2d38580c00..0e0050022b 100644 --- a/TGS.Interface/Wrappers/Server.cs +++ b/TGS.Interface/Server.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using TGS.Interface.Components; -namespace TGS.Interface.Wrappers +namespace TGS.Interface { /// sealed class Server : IServer diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/ServerInterface.cs index fe3b52f18b..f233b70b4e 100644 --- a/TGS.Interface/ServerInterface.cs +++ b/TGS.Interface/ServerInterface.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; using System.Net; using System.Net.Security; using System.Reflection; @@ -9,7 +8,6 @@ using System.Security.Principal; using System.ServiceModel; using System.ServiceModel.Description; using TGS.Interface.Components; -using TGS.Interface.Wrappers; namespace TGS.Interface { @@ -29,11 +27,11 @@ namespace TGS.Interface //check ITGSService first for compatiblity reasons try { - rawVersion = GetServiceComponent().Version(); + rawVersion = GetComponent(null).Version(); } catch { - rawVersion = GetServiceComponent().Version(); + rawVersion = GetComponent(null).Version(); } var splits = rawVersion.Split(' '); _serverVersion = new Version(splits[splits.Length - 1].Substring(1)); @@ -63,9 +61,9 @@ namespace TGS.Interface Version _serverVersion; /// - /// Associated list of open s keyed by type name. A in this list may close or fault at any time. Must be locked before being accessed + /// Associated list of open s keyed by type name. A in this list may close or fault at any time. must be locked before being accessed /// - IDictionary ChannelFactoryCache = new Dictionary(); + IDictionary ChannelFactoryCache; /// /// Sets the function called when a remote login fails due to the server having an invalid SSL cert @@ -103,6 +101,7 @@ namespace TGS.Interface /// public ServerInterface() { + ChannelFactoryCache = new Dictionary(); server = new Server(this); } @@ -117,64 +116,20 @@ namespace TGS.Interface _loginInfo = loginInfo; } - /// - public ConnectivityLevel ConnectToInstance(string instanceName = null, bool skipChecks = false) - { - if (instanceName == null) - instanceName = InstanceName; - if (!skipChecks && !ConnectionStatus().HasFlag(ConnectivityLevel.Connected)) - return ConnectivityLevel.None; - var prevInstance = InstanceName; - if (prevInstance != instanceName) - CloseAllChannels(false); - InstanceName = instanceName; - if (skipChecks) - return ConnectivityLevel.Connected; - try - { - GetComponent().VerifyConnection(); - } - catch - { - InstanceName = prevInstance; - return ConnectivityLevel.None; - } - try - { - GetComponent().ServerDirectory(); - } - catch - { - return ConnectivityLevel.Connected; - } - try - { - GetComponent().GetCurrentAuthorizedGroup(); - return ConnectivityLevel.Administrator; - } - catch - { - return ConnectivityLevel.Authenticated; - } - } - /// public bool IsRemoteConnection { get { return LoginInfo != null; } } /// - /// Closes all s stored in and clears it + /// Closes all s stored in and it /// - /// If set to , doesn't clear the channels that are used by - void CloseAllChannels(bool includingRoot) + public void Dispose() { - string[] RootThings = { typeof(ITGSService).Name, 'S' + typeof(ITGConnectivity).Name }; - lock (ChannelFactoryCache) + lock (this) { - var toRemove = new List(); + if (ChannelFactoryCache == null) + return; foreach (var I in ChannelFactoryCache) { - if (RootThings.Contains(I.Key)) - continue; var cf = I.Value; try { @@ -184,10 +139,8 @@ namespace TGS.Interface { cf.Abort(); } - toRemove.Add(I.Key); } - foreach (var I in toRemove) - ChannelFactoryCache.Remove(I); + ChannelFactoryCache = null; } } @@ -204,14 +157,6 @@ namespace TGS.Interface return false; } - /// - public T GetComponent() - { - if(InstanceName == null) - throw new InvalidOperationException("Instance not selected!"); - return GetComponent(InstanceName); - } - /// /// Returns the requested component for the instance . This does not guarantee a successful connection. s created this way are recycled for minimum latency and bandwidth usage /// @@ -220,16 +165,16 @@ namespace TGS.Interface /// The correct component internal T GetComponent(string instanceName) { - if (disposedValue) - throw new ObjectDisposedException(GetType().Name); var actualToT = typeof(T); var tot = actualToT.Name; - if (actualToT == typeof(ITGConnectivity) && instanceName == null) - tot = 'S' + tot; + if (instanceName != null) + tot = instanceName + tot; ChannelFactory cf; - lock (ChannelFactoryCache) + lock (this) { + if (ChannelFactoryCache == null) + throw new ObjectDisposedException(GetType().Name); if (ChannelFactoryCache.ContainsKey(tot)) try { @@ -249,13 +194,6 @@ namespace TGS.Interface return cf.CreateChannel(); } - /// - public T GetServiceComponent() - { - var ToT = typeof(T); - return GetComponent(null); - } - /// /// Directly creates a for without caching. This should be eventually closed by the caller /// @@ -347,18 +285,20 @@ namespace TGS.Interface error = e.ToString(); return ConnectivityLevel.None; } + try { - GetServiceComponent().Version(); + GetComponent(null).Version(); } catch(Exception e) { error = e.ToString(); return ConnectivityLevel.Connected; } + try { - GetServiceComponent().Version(); + GetComponent(null).Version(); error = null; return ConnectivityLevel.Administrator; } @@ -368,49 +308,5 @@ namespace TGS.Interface return ConnectivityLevel.Authenticated; } } - -#region IDisposable Support - /// - /// To detect redundant calls - /// - private bool disposedValue = false; - - /// - /// Implements the pattern. Calls - /// - /// if was called manually, if it was from the finalizer - void Dispose(bool disposing) - { - if (!disposedValue) - { - if (disposing) - { - CloseAllChannels(true); - } - - // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. - // TODO: set large fields to null. - - disposedValue = true; - } - } - - // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. - // ~Interface() { - // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - // Dispose(false); - // } - - /// - /// Implements the pattern - /// - public void Dispose() - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose(true); - // TODO: uncomment the following line if the finalizer is overridden above. - // GC.SuppressFinalize(this); - } -#endregion } } diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index fd1a344ca5..5ef6e8a5af 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -65,10 +65,10 @@ - + - - + + @@ -79,7 +79,7 @@ - + From d20a79c3f992261665b41203207621be9aee9100 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 12:29:52 -0500 Subject: [PATCH 13/18] Update bridge to use new interface --- TGS.Interface.Bridge/DreamDaemonBridge.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/TGS.Interface.Bridge/DreamDaemonBridge.cs b/TGS.Interface.Bridge/DreamDaemonBridge.cs index 7a6795c39a..ac609f4060 100644 --- a/TGS.Interface.Bridge/DreamDaemonBridge.cs +++ b/TGS.Interface.Bridge/DreamDaemonBridge.cs @@ -2,8 +2,6 @@ using RGiesecke.DllExport; using System; using System.Collections.Generic; using System.Runtime.InteropServices; -using TGS.Interface; -using TGS.Interface.Components; namespace TGS.Interface.Bridge { @@ -28,8 +26,7 @@ namespace TGS.Interface.Bridge var instance = parsedArgs[0]; parsedArgs.RemoveAt(0); using (var I = new ServerInterface()) - if(I.ConnectToInstance(instance, true).HasFlag(ConnectivityLevel.Connected)) - I.GetComponent().InteropMessage(String.Join(" ", parsedArgs)); + I.Server.GetInstance(instance).Interop.InteropMessage(String.Join(" ", parsedArgs)); } catch { } return 0; From 50a78b3193feaf0d8cf4bf61ce44a28557c9233c Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 12:47:13 -0500 Subject: [PATCH 14/18] Update ControlPanel to use the new IServerInterface --- TGS.ControlPanel/ControlPanel/ByondPage.cs | 8 +- TGS.ControlPanel/ControlPanel/ChatPage.cs | 8 +- TGS.ControlPanel/ControlPanel/ControlPanel.cs | 31 +++--- TGS.ControlPanel/ControlPanel/RepoPage.cs | 10 +- TGS.ControlPanel/ControlPanel/ServerPage.cs | 56 +++++----- TGS.ControlPanel/ControlPanel/StaticPage.cs | 18 +-- TGS.ControlPanel/InstanceSelector.Designer.cs | 1 - TGS.ControlPanel/InstanceSelector.cs | 104 ++++++------------ TGS.ControlPanel/Login.cs | 34 +++--- TGS.ControlPanel/Program.cs | 14 ++- TGS.ControlPanel/TestMergeManager.cs | 18 +-- 11 files changed, 136 insertions(+), 166 deletions(-) diff --git a/TGS.ControlPanel/ControlPanel/ByondPage.cs b/TGS.ControlPanel/ControlPanel/ByondPage.cs index 4935b7b3e4..f5ec5546d7 100644 --- a/TGS.ControlPanel/ControlPanel/ByondPage.cs +++ b/TGS.ControlPanel/ControlPanel/ByondPage.cs @@ -10,7 +10,7 @@ namespace TGS.ControlPanel string lastReadError = null; void InitBYONDPage() { - var BYOND = Interface.GetComponent(); + var BYOND = Instance.Byond; var CV = BYOND.GetVersion(ByondVersion.Installed); if (CV == null) CV = BYOND.GetVersion(ByondVersion.Staged); @@ -45,7 +45,7 @@ namespace TGS.ControlPanel private void UpdateButton_Click(object sender, EventArgs e) { UpdateBYONDButtons(); - if (!Interface.GetComponent().UpdateToVersion((int)MajorVersionNumeric.Value, (int)MinorVersionNumeric.Value)) + if (!Instance.Byond.UpdateToVersion((int)MajorVersionNumeric.Value, (int)MinorVersionNumeric.Value)) MessageBox.Show("Unable to begin update, there is another operation in progress."); } @@ -55,7 +55,7 @@ namespace TGS.ControlPanel } void UpdateBYONDButtons() { - var BYOND = Interface.GetComponent(); + var BYOND = Instance.Byond; VersionLabel.Text = BYOND.GetVersion(ByondVersion.Installed) ?? "Not Installed"; @@ -88,7 +88,7 @@ namespace TGS.ControlPanel UpdateButton.Enabled = false; break; } - var error = Interface.GetComponent().GetError(); + var error = Instance.Byond.GetError(); if (error != lastReadError) { lastReadError = error; diff --git a/TGS.ControlPanel/ControlPanel/ChatPage.cs b/TGS.ControlPanel/ControlPanel/ChatPage.cs index 96a666d5c6..d512d0d6ef 100644 --- a/TGS.ControlPanel/ControlPanel/ChatPage.cs +++ b/TGS.ControlPanel/ControlPanel/ChatPage.cs @@ -19,7 +19,7 @@ namespace TGS.ControlPanel void LoadChatPage() { updatingChat = true; - var Chat = Interface.GetComponent(); + var Chat = Instance.Chat; var PI = Chat.ProviderInfos()[(int)ModifyingProvider]; ChatAdminsTextBox.Visible = true; IRCModesComboBox.Visible = false; @@ -112,7 +112,7 @@ namespace TGS.ControlPanel private void ChatReconnectButton_Click(object sender, EventArgs e) { - Interface.GetComponent().Reconnect(ModifyingProvider); + Instance.Chat.Reconnect(ModifyingProvider); LoadChatPage(); } @@ -149,7 +149,7 @@ namespace TGS.ControlPanel } void SetAdminsAreSpecial(bool value) { - var Chat = Interface.GetComponent(); + var Chat = Instance.Chat; var PI = Chat.ProviderInfos()[(int)ModifyingProvider]; PI.AdminsAreSpecial = value; var res = Chat.SetProviderInfo(PI); @@ -208,7 +208,7 @@ namespace TGS.ControlPanel wip.Enabled = ChatEnabledCheckbox.Checked; wip.AdminsAreSpecial = AdminModeSpecial.Checked; - res = Interface.GetComponent().SetProviderInfo(wip); + res = Instance.Chat.SetProviderInfo(wip); } if (res != null) MessageBox.Show(res); diff --git a/TGS.ControlPanel/ControlPanel/ControlPanel.cs b/TGS.ControlPanel/ControlPanel/ControlPanel.cs index 5ebbf73f1b..8f9368a096 100644 --- a/TGS.ControlPanel/ControlPanel/ControlPanel.cs +++ b/TGS.ControlPanel/ControlPanel/ControlPanel.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.ControlPanel { @@ -18,29 +17,34 @@ namespace TGS.ControlPanel public static IDictionary InstancesInUse { get; private set; } = new Dictionary(); /// - /// The instance for this + /// The for this /// - readonly IServerInterface Interface; + readonly IInstance Instance; /// /// Constructs a /// - /// The for the - public ControlPanel(IServerInterface I) + /// The to use + /// The to use + public ControlPanel(IServer server, IInstance instance) { InitializeComponent(); + FormClosed += ControlPanel_FormClosed; - Interface = I; - if (Interface.IsRemoteConnection) - Text = String.Format("TGS {0}: {1}:{2}", Interface.ServerVersion, Interface.LoginInfo.IP, Interface.LoginInfo.Port); - Text = String.Format("{0} Instance: {1}", Text, I.InstanceName); Panels.SelectedIndexChanged += Panels_SelectedIndexChanged; Panels.SelectedIndex += Math.Min(Properties.Settings.Default.LastPageIndex, Panels.TabCount - 1); + + Instance = instance; + + InstancesInUse.Add(Instance.Metadata.Name, this); + + Text = String.Format("TGS {0} Instance: {1}", server.Version, Instance.Metadata.Name); + InitRepoPage(); InitBYONDPage(); InitServerPage(); + UpdateSelectedPanel(); - InstancesInUse.Add(I.InstanceName, this); } /// @@ -50,7 +54,7 @@ namespace TGS.ControlPanel /// The void ControlPanel_FormClosed(object sender, FormClosedEventArgs e) { - InstancesInUse.Remove(Interface.InstanceName); + InstancesInUse.Remove(Instance.Metadata.Name); } /// @@ -58,8 +62,7 @@ namespace TGS.ControlPanel /// void Cleanup() { - InstancesInUse.Remove(Interface.InstanceName); - Interface.Dispose(); + InstancesInUse.Remove(Instance.Metadata.Name); } private void Main_Resize(object sender, EventArgs e) @@ -102,7 +105,7 @@ namespace TGS.ControlPanel bool CheckAdminWithWarning() { - if (!Interface.ConnectToInstance().HasFlag(ConnectivityLevel.Administrator)) + if (Instance.Administration != null) { MessageBox.Show("Only system administrators may use this command!"); return false; diff --git a/TGS.ControlPanel/ControlPanel/RepoPage.cs b/TGS.ControlPanel/ControlPanel/RepoPage.cs index c6b5658e9d..5743cc5d17 100644 --- a/TGS.ControlPanel/ControlPanel/RepoPage.cs +++ b/TGS.ControlPanel/ControlPanel/RepoPage.cs @@ -76,7 +76,7 @@ namespace TGS.ControlPanel if (RepoBusyCheck()) return; - var Repo = Interface.GetComponent(); + var Repo = Instance.Repository; RepoProgressBar.Style = ProgressBarStyle.Marquee; RepoProgressBar.Visible = false; @@ -148,7 +148,7 @@ namespace TGS.ControlPanel bool RepoBusyCheck() { - if (Interface.GetComponent().OperationInProgress()) + if (Instance.Repository.OperationInProgress()) { DoAsyncOp(RepoAction.Wait, "Waiting for repository to finish another action..."); return true; @@ -170,7 +170,7 @@ namespace TGS.ControlPanel private void RepoBGW_DoWork(object sender, DoWorkEventArgs e) { //Only for clones - var Repo = Interface.GetComponent(); + var Repo = Instance.Repository; switch (action) { case RepoAction.Clone: @@ -273,7 +273,7 @@ namespace TGS.ControlPanel } private void RepoApplyButton_Click(object sender, EventArgs e) { - var Repo = Interface.GetComponent(); + var Repo = Instance.Repository; if (RepoBusyCheck()) return; @@ -344,7 +344,7 @@ namespace TGS.ControlPanel { if (MessageBox.Show("This will update the cached TGS3.json to the current repository version, potentially redefining symlinks. Proceed?", "Json Update", MessageBoxButtons.YesNo) != DialogResult.Yes) return; - var res = Interface.GetComponent().UpdateTGS3Json(); + var res = Instance.Repository.UpdateTGS3Json(); if (res != null) MessageBox.Show(res); } diff --git a/TGS.ControlPanel/ControlPanel/ServerPage.cs b/TGS.ControlPanel/ControlPanel/ServerPage.cs index 50a459c943..dee3c04e36 100644 --- a/TGS.ControlPanel/ControlPanel/ServerPage.cs +++ b/TGS.ControlPanel/ControlPanel/ServerPage.cs @@ -46,7 +46,7 @@ namespace TGS.ControlPanel private void CompileCancelButton_Click(object sender, EventArgs e) { - var res = Interface.GetComponent().Cancel(); + var res = Instance.Compiler.Cancel(); if (res != null) MessageBox.Show(res); LoadServerPage(); @@ -54,7 +54,7 @@ namespace TGS.ControlPanel void LoadServerPage() { - var RepoExists = Interface.GetComponent().Exists(); + var RepoExists = Instance.Repository.Exists(); compileButton.Visible = RepoExists; AutoUpdateCheckbox.Visible = RepoExists; initializeButton.Visible = RepoExists; @@ -83,16 +83,16 @@ namespace TGS.ControlPanel if (updatingFields) return; - var DM = Interface.GetComponent(); - var DD = Interface.GetComponent(); - var Config = Interface.GetComponent(); - var Repo = Interface.GetComponent(); + var DM = Instance.Compiler; + var DD = Instance.DreamDaemon; + var Config = Instance.Config; + var Repo = Instance.Repository; try { updatingFields = true; - ServerPathLabel.Text = "Server Path: " + Interface.GetComponent().ServerDirectory(); + ServerPathLabel.Text = "Server Path: " + Instance.ServerDirectory(); SecuritySelector.SelectedIndex = (int)DD.SecurityLevel(); @@ -197,13 +197,13 @@ namespace TGS.ControlPanel void UpdateProjectName() { if (!updatingFields) - Interface.GetComponent().SetProjectName(projectNameText.Text); + Instance.Compiler.SetProjectName(projectNameText.Text); } private void PortSelector_ValueChanged(object sender, EventArgs e) { if (!updatingFields) - Interface.GetComponent().SetPort((ushort)PortSelector.Value); + Instance.DreamDaemon.SetPort((ushort)PortSelector.Value); } private void ServerPageRefreshButton_Click(object sender, EventArgs e) @@ -213,13 +213,13 @@ namespace TGS.ControlPanel private void InitializeButton_Click(object sender, EventArgs e) { - if (!Interface.GetComponent().Initialize()) + if (!Instance.Compiler.Initialize()) MessageBox.Show("Unable to start initialization!"); LoadServerPage(); } private void CompileButton_Click(object sender, EventArgs e) { - if (!Interface.GetComponent().Compile()) + if (!Instance.Compiler.Compile()) MessageBox.Show("Unable to start compilation!"); LoadServerPage(); } @@ -227,7 +227,7 @@ namespace TGS.ControlPanel private void AutostartCheckbox_CheckedChanged(object sender, System.EventArgs e) { if (!updatingFields) - Interface.GetComponent().SetAutostart(AutostartCheckbox.Checked); + Instance.DreamDaemon.SetAutostart(AutostartCheckbox.Checked); } private void ServerStartButton_Click(object sender, System.EventArgs e) { @@ -239,7 +239,7 @@ namespace TGS.ControlPanel { try { - e.Result = Interface.GetComponent().Start(); + e.Result = Instance.DreamDaemon.Start(); } catch (Exception ex) { @@ -252,7 +252,7 @@ namespace TGS.ControlPanel var DialogResult = MessageBox.Show("This will immediately shut down the server. Continue?", "Confim", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.No) return; - var res = Interface.GetComponent().Stop(); + var res = Instance.DreamDaemon.Stop(); if (res != null) MessageBox.Show(res); } @@ -262,7 +262,7 @@ namespace TGS.ControlPanel var DialogResult = MessageBox.Show("This will immediately restart the server. Continue?", "Confim", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.No) return; - var res = Interface.GetComponent().Restart(); + var res = Instance.DreamDaemon.Restart(); if (res != null) MessageBox.Show(res); } @@ -274,7 +274,7 @@ namespace TGS.ControlPanel var DialogResult = MessageBox.Show("This will shut down the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.No) return; - Interface.GetComponent().RequestStop(); + Instance.DreamDaemon.RequestStop(); LoadServerPage(); } @@ -283,7 +283,7 @@ namespace TGS.ControlPanel var DialogResult = MessageBox.Show("This will restart the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.No) return; - Interface.GetComponent().RequestRestart(); + Instance.DreamDaemon.RequestRestart(); } /// @@ -293,7 +293,7 @@ namespace TGS.ControlPanel /// The void TestMergeManagerButton_Click(object sender, System.EventArgs e) { - using (var TMM = new TestMergeManager(Interface, ghclient)) + using (var TMM = new TestMergeManager(Instance, ghclient)) TMM.ShowDialog(); LoadServerPage(); } @@ -320,7 +320,7 @@ namespace TGS.ControlPanel try { string res = null; - var repo = Interface.GetComponent(); + var repo = Instance.Repository; var pulls = await Task.Run(() => repo.MergedPullRequests(out res)); if (pulls == null) @@ -364,7 +364,7 @@ namespace TGS.ControlPanel pulls.RemoveAll(x => x.Number == I.Result.Number); var mergeResults = await Task.Run(() => repo.MergePullRequests(pulls, true)); - var compileStartResult = await Task.Run(() => Interface.GetComponent().Compile(true)); + var compileStartResult = await Task.Run(() => Instance.Compiler.Compile(true)); //Show any errors for (var I = 0; I < mergeResults.Count(); ++I) @@ -410,7 +410,7 @@ namespace TGS.ControlPanel Enabled = false; try { - var repo = Interface.GetComponent(); + var repo = Instance.Repository; var res = await Task.Run(() => repo.Reset(true)); @@ -425,7 +425,7 @@ namespace TGS.ControlPanel if (res != null) MessageBox.Show(res, "Error generating changelog"); - await Task.Run(() => Interface.GetComponent().Compile(false)); + await Task.Run(() => Instance.Compiler.Compile(false)); if (res != null) MessageBox.Show(res, "Error starting compile!"); } @@ -452,7 +452,7 @@ namespace TGS.ControlPanel private void SecuritySelector_SelectedIndexChanged(object sender, EventArgs e) { if (!updatingFields) - if (!Interface.GetComponent().SetSecurityLevel((DreamDaemonSecurity)SecuritySelector.SelectedIndex)) + if (!Instance.DreamDaemon.SetSecurityLevel((DreamDaemonSecurity)SecuritySelector.SelectedIndex)) MessageBox.Show("Security change will be applied after next server reboot."); } @@ -461,7 +461,7 @@ namespace TGS.ControlPanel var msg = WorldAnnounceField.Text; if (!String.IsNullOrWhiteSpace(msg)) { - var res = Interface.GetComponent().WorldAnnounce(msg); + var res = Instance.DreamDaemon.WorldAnnounce(msg); if (res != null) { MessageBox.Show(res); @@ -474,13 +474,13 @@ namespace TGS.ControlPanel private void WebclientCheckBox_CheckedChanged(object sender, EventArgs e) { if (!updatingFields) - Interface.GetComponent().SetWebclient(WebclientCheckBox.Checked); + Instance.DreamDaemon.SetWebclient(WebclientCheckBox.Checked); } private void AutoUpdateInterval_ValueChanged(object sender, EventArgs e) { if (!updatingFields) - Interface.GetComponent().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value); + Instance.Repository.SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value); } private void AutoUpdateCheckbox_CheckedChanged(object sender, EventArgs e) @@ -491,9 +491,9 @@ namespace TGS.ControlPanel AutoUpdateInterval.Visible = on; AutoUpdateMLabel.Visible = on; if (!on) - Interface.GetComponent().SetAutoUpdateInterval(0); + Instance.Repository.SetAutoUpdateInterval(0); else - Interface.GetComponent().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value); + Instance.Repository.SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value); } } } diff --git a/TGS.ControlPanel/ControlPanel/StaticPage.cs b/TGS.ControlPanel/ControlPanel/StaticPage.cs index 0d53e7b680..76ad9b6943 100644 --- a/TGS.ControlPanel/ControlPanel/StaticPage.cs +++ b/TGS.ControlPanel/ControlPanel/StaticPage.cs @@ -29,7 +29,7 @@ namespace TGS.ControlPanel { if (initializedStaticPage) return; - if(!Interface.ConnectToInstance().HasFlag(ConnectivityLevel.Administrator)) + if(Instance.Administration != null) RecreateStaticButton.Visible = false; BuildFileList(); initializedStaticPage = true; @@ -41,7 +41,7 @@ namespace TGS.ControlPanel IndexesToPaths.Clear(); StaticFileListBox.Items.Clear(); IndexesToPaths.Add(StaticFileListBox.Items.Add("/"), "/"); - if (EnumeratePath("", Interface.GetComponent(), 1) == EnumResult.Unauthorized) + if (EnumeratePath("", Instance.Config, 1) == EnumResult.Unauthorized) { StaticFileListBox.Items[0] += " (UNAUTHORIZED)"; IndexesToPaths[0] = null; @@ -147,7 +147,7 @@ namespace TGS.ControlPanel if (error == null) try { - error = Interface.GetComponent().WriteText(FileName, fileContents, out bool unauthorized); + error = Instance.Config.WriteText(FileName, fileContents, out bool unauthorized); } catch (Exception ex) { @@ -171,7 +171,7 @@ namespace TGS.ControlPanel string text, error; try { - text = Interface.GetComponent().ReadText(remotePath, false, out error, out bool unauthorized); + text = Instance.Config.ReadText(remotePath, false, out error, out bool unauthorized); } catch (Exception ex) { @@ -213,7 +213,7 @@ namespace TGS.ControlPanel { if (MessageBox.Show("Are you sure you want to delete " + ((string)StaticFileListBox.SelectedItem).Trim() + "?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes) return; - var res = Interface.GetComponent().DeleteFile(IndexesToPaths[StaticFileListBox.SelectedIndex], out bool unauthorized); + var res = Instance.Config.DeleteFile(IndexesToPaths[StaticFileListBox.SelectedIndex], out bool unauthorized); if (res != null) MessageBox.Show(res); BuildFileList(); @@ -236,7 +236,7 @@ namespace TGS.ControlPanel var FullFileName = Path.Combine(IndexesToPaths[StaticFileListBox.SelectedIndex], FileName); if (resu == DialogResult.Yes) FullFileName = Path.Combine(FullFileName, "__TGS3_CP_DIRECTORY_CREATOR__"); - var config = Interface.GetComponent(); + var config = Instance.Config; var res = config.WriteText(FullFileName, "", out bool unauthorized); if (res != null) MessageBox.Show(res); @@ -255,7 +255,7 @@ namespace TGS.ControlPanel bool unauthorized; try { - res = Interface.GetComponent().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized); + res = Instance.Config.WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized); } catch (Exception ex) { @@ -307,7 +307,7 @@ namespace TGS.ControlPanel bool unauthorized; try { - entry = Interface.GetComponent().ReadText(path, false, out error, out unauthorized); + entry = Instance.Config.ReadText(path, false, out error, out unauthorized); } catch(Exception e) { @@ -344,7 +344,7 @@ namespace TGS.ControlPanel RecreateStaticButton.Visible = false; return; } - var res = Interface.GetComponent().RecreateStaticFolder(); + var res = Instance.Administration.RecreateStaticFolder(); if (res != null) MessageBox.Show(res); BuildFileList(); diff --git a/TGS.ControlPanel/InstanceSelector.Designer.cs b/TGS.ControlPanel/InstanceSelector.Designer.cs index 87ce1038b7..f9a745d34e 100644 --- a/TGS.ControlPanel/InstanceSelector.Designer.cs +++ b/TGS.ControlPanel/InstanceSelector.Designer.cs @@ -15,7 +15,6 @@ { if (disposing && (components != null)) { - Cleanup(); components.Dispose(); } base.Dispose(disposing); diff --git a/TGS.ControlPanel/InstanceSelector.cs b/TGS.ControlPanel/InstanceSelector.cs index 066fb9c6a9..6794995db2 100644 --- a/TGS.ControlPanel/InstanceSelector.cs +++ b/TGS.ControlPanel/InstanceSelector.cs @@ -3,23 +3,18 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Forms; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.ControlPanel { /// - /// Form used for managing manipulation functions + /// Form used for managing s /// sealed partial class InstanceSelector : CountedForm { /// - /// The we build instance connections from + /// The we build instance connections from /// - readonly IServerInterface masterInterface; - /// - /// List of from - /// - IList InstanceData; + readonly IServer server; /// /// Used for modifying without invoking its side effects /// @@ -28,17 +23,17 @@ namespace TGS.ControlPanel /// /// Construct an /// - /// An connected a the - public InstanceSelector(IServerInterface I) + /// The value of + public InstanceSelector(IServer _server) { InitializeComponent(); InstanceListBox.MouseDoubleClick += InstanceListBox_MouseDoubleClick; - masterInterface = I; + server = _server; RefreshInstances(); } /// - /// Connects to a if it is double clicked in + /// Connects to a if it is double clicked in /// /// The sender of the event /// The @@ -53,36 +48,25 @@ namespace TGS.ControlPanel /// The associated with 's current selected index if it exists, otherwise InstanceMetadata GetSelectedInstanceMetadata() { - var index = InstanceListBox.SelectedIndex; - return index != ListBox.NoMatches ? InstanceData[index] : null; + var index = (IInstance)InstanceListBox.SelectedItem; + return index?.Metadata; } /// - /// Called by + /// Loads the using /// - void Cleanup() - { - masterInterface.Dispose(); - } - - /// - /// Loads the using - /// - async void RefreshInstances() + void RefreshInstances() { InstanceListBox.Items.Clear(); - await WrapServerOp(() => { - InstanceData = masterInterface.GetServiceComponent().ListInstances(); - }); - foreach(var I in InstanceData) - InstanceListBox.Items.Add(String.Format("{0}: {1} - {2} - {3}", I.LoggingID, I.Name, I.Path, I.Enabled ? "ONLINE" : "OFFLINE")); - var HasServerAdmin = masterInterface.ConnectionStatus().HasFlag(ConnectivityLevel.Administrator); + foreach(var I in server.Instances) + InstanceListBox.Items.Add(I); + var HasServerAdmin = server.InstanceManager != null; CreateInstanceButton.Enabled = HasServerAdmin; ImportInstanceButton.Enabled = HasServerAdmin; RenameInstanceButton.Enabled = HasServerAdmin; DetachInstanceButton.Enabled = HasServerAdmin; EnabledCheckBox.Enabled = HasServerAdmin; - if(InstanceData.Count > 0) + if(InstanceListBox.Items.Count > 0) InstanceListBox.SelectedIndex = 0; } @@ -90,40 +74,22 @@ namespace TGS.ControlPanel /// Tries to start a for a given /// /// The of to connect to - async void TryConnectToIndexInstance(int index) + void TryConnectToIndexInstance(int index) { if (index == ListBox.NoMatches) return; - var instanceName = InstanceData[index].Name; - if (ControlPanel.InstancesInUse.TryGetValue(instanceName, out ControlPanel activeCP)) + var instance = (IInstance)InstanceListBox.Items[index]; + if (ControlPanel.InstancesInUse.TryGetValue(instance.Metadata.Name, out ControlPanel activeCP)) { activeCP.BringToFront(); return; } - var InstanceAccessor = masterInterface.IsRemoteConnection ? new ServerInterface(masterInterface.LoginInfo) : new ServerInterface(); - try - { - ConnectivityLevel res = ConnectivityLevel.None; - await WrapServerOp(() => { res = InstanceAccessor.ConnectToInstance(instanceName); }); - if (!res.HasFlag(ConnectivityLevel.Connected)) - { - MessageBox.Show("Unable to connect to instance! Does it exist?"); - RefreshInstances(); - } - else if (!res.HasFlag(ConnectivityLevel.Authenticated)) - MessageBox.Show("The current user is not authorized to access this instance!"); - else - new ControlPanel(InstanceAccessor).Show(); - } - catch - { - InstanceAccessor.Dispose(); - throw; - } + + new ControlPanel(server, instance).Show(); } /// - /// Prompts the user for parameters to + /// Prompts the user for parameters to /// /// The sender of the event /// The @@ -135,7 +101,7 @@ namespace TGS.ControlPanel if (MessageBox.Show(String.Format("This will dissociate the server instance at \"{0}\"! Are you sure?", imd.Path), "Instance Detach", MessageBoxButtons.YesNo) != DialogResult.Yes) return; string res = null; - await WrapServerOp(() => res = masterInterface.GetServiceComponent().DetachInstance(imd.Name)); + await WrapServerOp(() => res = server.InstanceManager.DetachInstance(imd.Name)); if (res != null) MessageBox.Show(res); RefreshInstances(); @@ -152,7 +118,7 @@ namespace TGS.ControlPanel } /// - /// Prompts the user for parameters to + /// Prompts the user for parameters to /// /// The sender of the event /// The @@ -167,14 +133,14 @@ namespace TGS.ControlPanel if (imd.Enabled && MessageBox.Show(String.Format("This will temporarily offline the server instance! Are you sure?", imd.Path), "Instance Restart", MessageBoxButtons.YesNo) != DialogResult.Yes) return; string res = null; - await WrapServerOp(() => res = masterInterface.GetServiceComponent().RenameInstance(imd.Name, new_name)); + await WrapServerOp(() => res = server.InstanceManager.RenameInstance(imd.Name, new_name)); if (res != null) MessageBox.Show(res); RefreshInstances(); } /// - /// Prompts the user for parameters to + /// Prompts the user for parameters to /// /// The sender of the event /// The @@ -184,14 +150,14 @@ namespace TGS.ControlPanel if (instance_path == null) return; string res = null; - await WrapServerOp(() => res = masterInterface.GetServiceComponent().ImportInstance(instance_path)); + await WrapServerOp(() => res = server.InstanceManager.ImportInstance(instance_path)); if (res != null) MessageBox.Show(res); RefreshInstances(); } /// - /// Prompts the user for parameters to + /// Prompts the user for parameters to /// /// The sender of the event /// The @@ -204,14 +170,14 @@ namespace TGS.ControlPanel if (instance_path == null) return; string res = null; - await WrapServerOp(() => res = masterInterface.GetServiceComponent().CreateInstance(instance_name, instance_path)); + await WrapServerOp(() => res = server.InstanceManager.CreateInstance(instance_name, instance_path)); if (res != null) MessageBox.Show(res); RefreshInstances(); } /// - /// Attempts to connect the user to an based on the of + /// Attempts to connect the user to an based on the of /// /// The sender of the event /// The @@ -221,7 +187,7 @@ namespace TGS.ControlPanel } /// - /// Prompts the user if they want to call to either online or offline an based on its current state + /// Prompts the user if they want to call to either online or offline an based on its current state /// /// The sender of the event /// The @@ -235,8 +201,7 @@ namespace TGS.ControlPanel if (MessageBox.Show(String.Format("Are you sure you want to {0} this instance?", enabling ? "online" : "offline"), "Instance Status Change", MessageBoxButtons.YesNo) != DialogResult.Yes) return; string res = null; - var index = InstanceListBox.SelectedIndex; - await WrapServerOp(() => res = masterInterface.GetServiceComponent().SetInstanceEnabled(InstanceData[index].Name, enabling)); + await WrapServerOp(() => res = server.InstanceManager.SetInstanceEnabled(GetSelectedInstanceMetadata().Name, enabling)); if (res != null) MessageBox.Show(res); } @@ -247,17 +212,16 @@ namespace TGS.ControlPanel } /// - /// Update based on the selected 's property + /// Update based on the selected 's property /// /// The sender of the event /// The void InstanceListBox_SelectedIndexChanged(object sender, EventArgs e) { - var index = InstanceListBox.SelectedIndex; - if (index != ListBox.NoMatches) + if (InstanceListBox.SelectedIndex != ListBox.NoMatches) { UpdatingEnabledCheckbox = true; - EnabledCheckBox.Checked = InstanceData[index].Enabled; + EnabledCheckBox.Checked = GetSelectedInstanceMetadata().Enabled; UpdatingEnabledCheckbox = false; } } diff --git a/TGS.ControlPanel/Login.cs b/TGS.ControlPanel/Login.cs index 1a1328cbda..f4c44e9523 100644 --- a/TGS.ControlPanel/Login.cs +++ b/TGS.ControlPanel/Login.cs @@ -5,7 +5,7 @@ using TGS.Interface; namespace TGS.ControlPanel { - sealed partial class Login : CountedForm + sealed partial class Login : Form { /// /// Currently selected saved @@ -92,24 +92,22 @@ namespace TGS.ControlPanel loginInfo.Password = PasswordTextBox.Text; } - using (var I = new ServerInterface(loginInfo)) + var I = new ServerInterface(loginInfo); + var Config = Properties.Settings.Default; + //This needs to be read here because V&C Closing us will corrupt the data + var savePassword = SavePasswordCheckBox.Checked; + if (VerifyAndConnect(I)) { - var Config = Properties.Settings.Default; - //This needs to be read here because V&C Closing us will corrupt the data - var savePassword = SavePasswordCheckBox.Checked; - if (VerifyAndConnect(I)) - { - Config.RemoteDefault = true; + Config.RemoteDefault = true; - if (!savePassword) - loginInfo.Password = null; - - Config.RemoteLoginInfo = new StringCollection { loginInfo.ToJSON() }; - - foreach (RemoteLoginInfo info in IPComboBox.Items) - if (!info.Equals(loginInfo)) - Config.RemoteLoginInfo.Add(info.ToJSON()); - } + if (!savePassword) + loginInfo.Password = null; + + Config.RemoteLoginInfo = new StringCollection { loginInfo.ToJSON() }; + + foreach (RemoteLoginInfo info in IPComboBox.Items) + if (!info.Equals(loginInfo)) + Config.RemoteLoginInfo.Add(info.ToJSON()); } } @@ -143,8 +141,8 @@ namespace TGS.ControlPanel if (I.VersionMismatch(out error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel) return true; - new InstanceSelector(I).Show(); Close(); + Program.ServerInterface = I; return true; } catch diff --git a/TGS.ControlPanel/Program.cs b/TGS.ControlPanel/Program.cs index b72f48eb78..c0472c87c4 100644 --- a/TGS.ControlPanel/Program.cs +++ b/TGS.ControlPanel/Program.cs @@ -7,6 +7,7 @@ namespace TGS.ControlPanel { static class Program { + public static IServerInterface ServerInterface; [STAThread] static void Main(string[] args) { @@ -20,13 +21,18 @@ namespace TGS.ControlPanel } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - ServerInterface.SetBadCertificateHandler(BadCertificateHandler); - var login = new Login(); - login.Show(); - Application.Run(); + Interface.ServerInterface.SetBadCertificateHandler(BadCertificateHandler); + Application.Run(new Login()); + if(ServerInterface != null) + { + new InstanceSelector(ServerInterface.Server).Show(); + Application.Run(); + } } catch (Exception e) { + if (ServerInterface != null) + ServerInterface.Dispose(); ServiceDisconnectException(e); } finally diff --git a/TGS.ControlPanel/TestMergeManager.cs b/TGS.ControlPanel/TestMergeManager.cs index a7bcb7d6f5..6df18e1793 100644 --- a/TGS.ControlPanel/TestMergeManager.cs +++ b/TGS.ControlPanel/TestMergeManager.cs @@ -17,9 +17,9 @@ namespace TGS.ControlPanel const string MergedPullsError = "Error retrieving currently merged pull requests: {0}"; /// - /// The connected to an to handle the pull requests for + /// The to handle pull requests for /// - readonly IServerInterface currentInterface; + readonly IInstance currentInterface; /// /// The to use to read PR lists @@ -38,9 +38,9 @@ namespace TGS.ControlPanel /// /// Construct a /// - /// The to use for managing the + /// The to manage pull requests for /// The to use for getting pull request information - public TestMergeManager(IServerInterface interfaceToUse, GitHubClient clientToUse) + public TestMergeManager(IInstance interfaceToUse, GitHubClient clientToUse) { InitializeComponent(); DialogResult = DialogResult.Cancel; @@ -88,7 +88,7 @@ namespace TGS.ControlPanel { PullRequestListBox.Items.Clear(); - var repo = currentInterface.GetComponent(); + var repo = currentInterface.Repository; string error = null; List pulls = null; @@ -197,7 +197,7 @@ namespace TGS.ControlPanel void PullRequestManager_Load(object sender, EventArgs e) { Enabled = false; - var repo = currentInterface.GetComponent(); + var repo = currentInterface.Repository; if(!Program.GetRepositoryRemote(repo, out repoOwner, out repoName)) { Close(); @@ -256,7 +256,7 @@ namespace TGS.ControlPanel } } - var repo = currentInterface.GetComponent(); + var repo = currentInterface.Repository; string error = null; //Do standard repo updates @@ -297,7 +297,7 @@ namespace TGS.ControlPanel GenerateChangelog(repo); //Start the compile - var compileStarted = await Task.Run(() => currentInterface.GetComponent().Compile(pulls.Count == 1)); + var compileStarted = await Task.Run(() => currentInterface.Compiler.Compile(pulls.Count == 1)); if (error != null) MessageBox.Show(String.Format("Error sychronizing repo: {0}", error)); @@ -341,7 +341,7 @@ namespace TGS.ControlPanel { IList pulls = null; string error = null; - var mergedPullsTask = WrapServerOp(() => pulls = currentInterface.GetComponent().MergedPullRequests(out error)); + var mergedPullsTask = WrapServerOp(() => pulls = currentInterface.Repository.MergedPullRequests(out error)); int PRNumber; try From e58f09eef45ce85e7791b6edf31d573540a0b9e5 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 13:08:48 -0500 Subject: [PATCH 15/18] Update CommandLine to use the new IServerInterface --- TGS.CommandLine/AdminCommands.cs | 11 +++--- TGS.CommandLine/BYONDCommands.cs | 9 ++--- TGS.CommandLine/ChatCommands.cs | 39 +++++++++---------- TGS.CommandLine/ConfigCommands.cs | 13 +++---- TGS.CommandLine/ConsoleCommand.cs | 8 +++- TGS.CommandLine/DDCommands.cs | 21 +++++----- TGS.CommandLine/DMCommands.cs | 17 ++++---- TGS.CommandLine/InstanceRootCommand.cs | 33 ---------------- TGS.CommandLine/Program.cs | 22 +++++------ TGS.CommandLine/RepoCommands.cs | 31 +++++++-------- TGS.CommandLine/RootCommands.cs | 17 ++++---- TGS.CommandLine/ServiceCommands.cs | 26 ++++++------- TGS.CommandLine/TGS.CommandLine.csproj | 1 - .../Repository/RepositoryCommandTest.cs | 6 +-- .../TestRepoSetPushTestmergeCommitsCommand.cs | 4 +- .../Repository/TestRepoStatusCommand.cs | 4 +- 16 files changed, 111 insertions(+), 151 deletions(-) delete mode 100644 TGS.CommandLine/InstanceRootCommand.cs diff --git a/TGS.CommandLine/AdminCommands.cs b/TGS.CommandLine/AdminCommands.cs index 953c002b07..41addc7b7b 100644 --- a/TGS.CommandLine/AdminCommands.cs +++ b/TGS.CommandLine/AdminCommands.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { - class AdminCommand : InstanceRootCommand + sealed class AdminCommand : RootCommand { public AdminCommand() { @@ -26,7 +25,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().RecreateStaticFolder(); + var res = Instance.Administration.RecreateStaticFolder(); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -50,7 +49,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var group = Interface.GetComponent().GetCurrentAuthorizedGroup(); + var group = Instance.Administration.GetCurrentAuthorizedGroup(); OutputProc(group ?? "ERROR"); return group != null ? ExitCode.Normal : ExitCode.ServerError; } @@ -75,7 +74,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var result = Interface.GetComponent().SetAuthorizedGroup(parameters[0]); + var result = Instance.Administration.SetAuthorizedGroup(parameters[0]); if(result != null) { OutputProc("Group set to: " + result); @@ -103,7 +102,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().SetAuthorizedGroup(null); + var res = Instance.Administration.SetAuthorizedGroup(null); if(res != "ADMIN") { OutputProc("Failed to clear the group??? We are currently set to: " + res); diff --git a/TGS.CommandLine/BYONDCommands.cs b/TGS.CommandLine/BYONDCommands.cs index 869c1ccfd3..84e1209781 100644 --- a/TGS.CommandLine/BYONDCommands.cs +++ b/TGS.CommandLine/BYONDCommands.cs @@ -2,11 +2,10 @@ using System.Collections.Generic; using System.Threading; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { - class BYONDCommand : InstanceRootCommand + class BYONDCommand : RootCommand { public BYONDCommand() { @@ -33,7 +32,7 @@ namespace TGS.CommandLine type = ByondVersion.Staged; else if (parameters[0].ToLower() == "--latest") type = ByondVersion.Latest; - OutputProc(Interface.GetComponent().GetVersion(type) ?? "Unistalled"); + OutputProc(Instance.Byond.GetVersion(type) ?? "Unistalled"); return ExitCode.Normal; } public override string GetArgumentString() @@ -56,7 +55,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - switch (Interface.GetComponent().CurrentStatus()) + switch (Instance.Byond.CurrentStatus()) { case ByondStatus.Downloading: OutputProc("Downloading update..."); @@ -109,7 +108,7 @@ namespace TGS.CommandLine return ExitCode.BadCommand; } - var BYOND = Interface.GetComponent(); + var BYOND = Instance.Byond; if (!BYOND.UpdateToVersion(Major, Minor)) { diff --git a/TGS.CommandLine/ChatCommands.cs b/TGS.CommandLine/ChatCommands.cs index bf5fd5d3aa..6e87e34944 100644 --- a/TGS.CommandLine/ChatCommands.cs +++ b/TGS.CommandLine/ChatCommands.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { - class IRCCommand : InstanceRootCommand + class IRCCommand : RootCommand { public IRCCommand() { @@ -17,7 +16,7 @@ namespace TGS.CommandLine return "Manages the IRC bot"; } } - class DiscordCommand : InstanceRootCommand + class DiscordCommand : RootCommand { public DiscordCommand() { @@ -48,7 +47,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var Chat = Interface.GetComponent(); + var Chat = Instance.Chat; Chat.SetProviderInfo(new IRCSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.IRC]) { Nickname = parameters[0], @@ -78,7 +77,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = IRC.ProviderInfos()[providerIndex]; List channels; @@ -156,7 +155,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = IRC.ProviderInfos()[providerIndex]; List channels; @@ -222,7 +221,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var info = Interface.GetComponent().ProviderInfos()[providerIndex]; + var info = Instance.Chat.ProviderInfos()[providerIndex]; string authType; switch ((ChatProvider)providerIndex) { @@ -281,7 +280,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().Reconnect(providerIndex); + var res = Instance.Chat.Reconnect(providerIndex); if (res != null) { OutputProc("Error: " + res); @@ -310,7 +309,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = IRC.ProviderInfos()[providerIndex]; var newmin = parameters[0].ToLower(); @@ -355,7 +354,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = IRC.ProviderInfos()[(int)ChatProvider.IRC]; var lowerparam = parameters[0].ToLower(); if (lowerparam == "channel-mode") @@ -394,7 +393,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = IRC.ProviderInfos()[(int)ChatProvider.Discord]; var lowerparam = parameters[0].ToLower(); if (lowerparam == "role-id") @@ -433,7 +432,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC]); switch (parameters[0]) { @@ -482,7 +481,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = IRC.ProviderInfos()[providerIndex]; var newmin = parameters[0].ToLower(); @@ -529,7 +528,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; IRC.SetProviderInfo(new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC]) { AuthTarget = parameters[0], @@ -551,7 +550,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; IRC.SetProviderInfo(new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC]) { AuthTarget = null, @@ -575,7 +574,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Interface.GetComponent(); + var IRC = Instance.Chat; var info = IRC.ProviderInfos()[providerIndex]; OutputProc("Currently configured channels:"); OutputProc("Admin:"); @@ -610,7 +609,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var Chat = Interface.GetComponent(); + var Chat = Instance.Chat; var info = Chat.ProviderInfos()[providerIndex]; info.Enabled = true; var res = Chat.SetProviderInfo(info); @@ -638,7 +637,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var Chat = Interface.GetComponent(); + var Chat = Instance.Chat; var info = Chat.ProviderInfos()[providerIndex]; info.Enabled = false; var res = Chat.SetProviderInfo(info); @@ -675,7 +674,7 @@ namespace TGS.CommandLine OutputProc("Invalid parameter!"); return ExitCode.BadCommand; } - var Chat = Interface.GetComponent(); + var Chat = Instance.Chat; var PI = new IRCSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.IRC]) { URL = splits[0] @@ -713,7 +712,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var Chat = Interface.GetComponent(); + var Chat = Instance.Chat; var res = Chat.SetProviderInfo(new DiscordSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.Discord]) { BotToken = parameters[0] }); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; diff --git a/TGS.CommandLine/ConfigCommands.cs b/TGS.CommandLine/ConfigCommands.cs index ab4191a5d6..c047d6c3dd 100644 --- a/TGS.CommandLine/ConfigCommands.cs +++ b/TGS.CommandLine/ConfigCommands.cs @@ -2,11 +2,10 @@ using System.Collections.Generic; using System.IO; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { - class ConfigCommand : InstanceRootCommand + class ConfigCommand : RootCommand { public ConfigCommand() { @@ -28,7 +27,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().DeleteFile(parameters[0], out bool unauthorized); + var res = Instance.Config.DeleteFile(parameters[0], out bool unauthorized); if (res != null) { OutputProc(res); @@ -64,7 +63,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var list = Interface.GetComponent().ListStaticDirectory(parameters.Count > 0 ? parameters[0] : null, out string error, out bool unauthorized); + var list = Instance.Config.ListStaticDirectory(parameters.Count > 0 ? parameters[0] : null, out string error, out bool unauthorized); if(list == null) { OutputProc(error); @@ -88,7 +87,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - OutputProc(Interface.GetComponent().ServerDirectory()); + OutputProc(Instance.ServerDirectory()); return ExitCode.Normal; } @@ -108,7 +107,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var bytes = Interface.GetComponent().ReadText(parameters[0], parameters.Count > 2 && parameters[2].ToLower() == "--repo", out string error, out bool unauthorized); + var bytes = Instance.Config.ReadText(parameters[0], parameters.Count > 2 && parameters[2].ToLower() == "--repo", out string error, out bool unauthorized); if(bytes == null) { OutputProc("Error: " + error); @@ -148,7 +147,7 @@ namespace TGS.CommandLine { try { - var res = Interface.GetComponent().WriteText(parameters[0], File.ReadAllText(parameters[1]), out bool unauthorized); + var res = Instance.Config.WriteText(parameters[0], File.ReadAllText(parameters[1]), out bool unauthorized); if (res != null) { OutputProc("Error: " + res); diff --git a/TGS.CommandLine/ConsoleCommand.cs b/TGS.CommandLine/ConsoleCommand.cs index 1aa0e3f773..56b0381ee1 100644 --- a/TGS.CommandLine/ConsoleCommand.cs +++ b/TGS.CommandLine/ConsoleCommand.cs @@ -5,8 +5,12 @@ namespace TGS.CommandLine abstract class ConsoleCommand : Command { /// - /// The currently in use by the + /// The currently in use by the /// - public static IServerInterface Interface; + public static IServer Server; + /// + /// The currently in use by the + /// + public static IInstance Instance; } } diff --git a/TGS.CommandLine/DDCommands.cs b/TGS.CommandLine/DDCommands.cs index 9681589cf8..41ad8fe94d 100644 --- a/TGS.CommandLine/DDCommands.cs +++ b/TGS.CommandLine/DDCommands.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { - class DDCommand : InstanceRootCommand + class DDCommand : RootCommand { public DDCommand() { @@ -38,7 +37,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().WorldAnnounce(String.Join(" ", parameters)); + var res = Instance.DreamDaemon.WorldAnnounce(String.Join(" ", parameters)); OutputProc(res ?? "Success!"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -58,7 +57,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().Start(); + var res = Instance.DreamDaemon.Start(); OutputProc(res ?? "Success!"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -82,7 +81,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var DD = Interface.GetComponent(); + var DD = Instance.DreamDaemon; if (parameters.Count > 0 && parameters[0].ToLower() == "--graceful") { if (DD.DaemonStatus() != DreamDaemonStatus.Online) @@ -111,7 +110,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var DD = Interface.GetComponent(); + var DD = Instance.DreamDaemon; if (parameters.Count > 0 && parameters[0].ToLower() == "--graceful") { if (DD.DaemonStatus() != DreamDaemonStatus.Online) @@ -146,7 +145,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var DD = Interface.GetComponent(); + var DD = Instance.DreamDaemon; OutputProc(DD.StatusString(true)); if (DD.ShutdownInProgress()) OutputProc("The server will shutdown once the current round completes."); @@ -167,7 +166,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var DD = Interface.GetComponent(); + var DD = Instance.DreamDaemon; switch (parameters[0].ToLower()) { case "on": @@ -205,7 +204,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var DD = Interface.GetComponent(); + var DD = Instance.DreamDaemon; switch (parameters[0].ToLower()) { case "on": @@ -255,7 +254,7 @@ namespace TGS.CommandLine return ExitCode.BadCommand; } - Interface.GetComponent().SetPort(port); + Instance.DreamDaemon.SetPort(port); return ExitCode.Normal; } @@ -298,7 +297,7 @@ namespace TGS.CommandLine OutputProc("Invalid security word!"); return ExitCode.BadCommand; } - Interface.GetComponent().SetSecurityLevel(sec); + Instance.DreamDaemon.SetSecurityLevel(sec); return ExitCode.Normal; } diff --git a/TGS.CommandLine/DMCommands.cs b/TGS.CommandLine/DMCommands.cs index 380f2307e7..47d9959e4f 100644 --- a/TGS.CommandLine/DMCommands.cs +++ b/TGS.CommandLine/DMCommands.cs @@ -2,11 +2,10 @@ using System.Collections.Generic; using System.Threading; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { - class DMCommand : InstanceRootCommand + class DMCommand : RootCommand { public DMCommand() { @@ -28,7 +27,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var DM = Interface.GetComponent(); + var DM = Instance.Compiler; var stat = DM.GetStatus(); if (stat != CompilerStatus.Initialized) { @@ -36,7 +35,7 @@ namespace TGS.CommandLine return ExitCode.ServerError; } - if (Interface.GetComponent().GetVersion(ByondVersion.Installed) == null) + if (Instance.Byond.GetVersion(ByondVersion.Installed) == null) { Console.Write("Error: BYOND is not installed!"); return ExitCode.ServerError; @@ -84,14 +83,14 @@ namespace TGS.CommandLine void ShowError() { - var error = Interface.GetComponent().CompileError(); + var error = Instance.Compiler.CompileError(); if (error != null) OutputProc("Last error: " + error); } protected override ExitCode Run(IList parameters) { - var DM = Interface.GetComponent(); + var DM = Instance.Compiler; OutputProc(String.Format("Target Project: /{0}.dme", DM.ProjectName())); Console.Write("Compilier is currently: "); switch (DM.GetStatus()) @@ -142,7 +141,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - Interface.GetComponent().SetProjectName(parameters[0]); + Instance.Compiler.SetProjectName(parameters[0]); return ExitCode.Normal; } } @@ -166,7 +165,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var DM = Interface.GetComponent(); + var DM = Instance.Compiler; var stat = DM.GetStatus(); if (stat == CompilerStatus.Compiling || stat == CompilerStatus.Initializing) { @@ -206,7 +205,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().Cancel(); + var res = Instance.Compiler.Cancel(); OutputProc(res ?? "Success!"); return ExitCode.Normal; //because failing cancellation implys it's already cancelled } diff --git a/TGS.CommandLine/InstanceRootCommand.cs b/TGS.CommandLine/InstanceRootCommand.cs deleted file mode 100644 index 107fe20689..0000000000 --- a/TGS.CommandLine/InstanceRootCommand.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; -using TGS.Interface; - -namespace TGS.CommandLine -{ - abstract class InstanceRootCommand : RootCommand - { - public static IServerInterface currentInterface; - public override ExitCode DoRun(IList parameters) - { - if (currentInterface.InstanceName == null) - { - OutputProc("Missing instance!"); - return ExitCode.BadCommand; - } - else - { - var res = currentInterface.ConnectToInstance(); - if (!res.HasFlag(ConnectivityLevel.Connected)) - { - OutputProc("Unable to connect to instance!"); - return ExitCode.ConnectionError; - } - else if (!res.HasFlag(ConnectivityLevel.Authenticated)) - { - OutputProc("The current user is not authorized to use this instance!"); - return ExitCode.ConnectionError; - } - } - return base.DoRun(parameters); - } - } -} diff --git a/TGS.CommandLine/Program.cs b/TGS.CommandLine/Program.cs index 0e2986d944..59d41f71da 100644 --- a/TGS.CommandLine/Program.cs +++ b/TGS.CommandLine/Program.cs @@ -84,7 +84,7 @@ namespace TGS.CommandLine } else if (interactive && !saidSrvVersion) { - Console.WriteLine("Connectd to service version: " + currentInterface.GetServiceComponent().Version()); + Console.WriteLine("Connectd to service version: " + currentInterface.Server.Version); saidSrvVersion = true; } @@ -102,8 +102,8 @@ namespace TGS.CommandLine static void ReplaceInterface(IServerInterface I) { currentInterface = I; - ConsoleCommand.Interface = I; - InstanceRootCommand.currentInterface = I; + ConsoleCommand.Server = I.Server; + ConsoleCommand.Instance = null; saidSrvVersion = false; } @@ -156,20 +156,18 @@ namespace TGS.CommandLine /// /// The name of the to test /// If , does not output on success - /// if a was achieved with , otherwise + /// if the connection was made, otherwise static bool CheckInstanceConnectivity(string instanceName, bool silentSuccess) { - var res = currentInterface.ConnectToInstance(instanceName); - if (!res.HasFlag(ConnectivityLevel.Connected)) - Console.WriteLine("Unable to connect to instance! Does it exist?"); - else if (!res.HasFlag(ConnectivityLevel.Authenticated)) - Console.WriteLine("The current user is not authorized to use this instance!"); - else + var res = currentInterface.Server.Instances.Where(x => x.Metadata.Name == instanceName).FirstOrDefault(); + if (res != null) { - if(!silentSuccess) + ConsoleCommand.Instance = res; + if (!silentSuccess) Console.WriteLine("Successfully conected to instance!"); return true; } + Console.WriteLine("Unable to connect to instance! Does it exist?"); return false; } @@ -262,7 +260,7 @@ namespace TGS.CommandLine case "exit": return (int)Command.ExitCode.Normal; case "debug-upgrade": - currentInterface.GetServiceComponent().PrepareForUpdate(); + currentInterface.Server.Management.PrepareForUpdate(); return (int)Command.ExitCode.Normal; default: //linq voodoo to get quoted strings diff --git a/TGS.CommandLine/RepoCommands.cs b/TGS.CommandLine/RepoCommands.cs index a24a26d68f..30a7a0613d 100644 --- a/TGS.CommandLine/RepoCommands.cs +++ b/TGS.CommandLine/RepoCommands.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { @@ -40,10 +39,10 @@ namespace TGS.CommandLine switch (parameters[0].ToLower()) { case "on": - Interface.GetComponent().SetPushTestmergeCommits(true); + Instance.Repository.SetPushTestmergeCommits(true); break; case "off": - Interface.GetComponent().SetPushTestmergeCommits(false); + Instance.Repository.SetPushTestmergeCommits(false); break; default: OutputProc("Invalid option!"); @@ -67,7 +66,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().UpdateTGS3Json(); + var res = Instance.Repository.UpdateTGS3Json(); if (res != null) { OutputProc(res); @@ -86,7 +85,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().Setup(parameters[0], parameters.Count > 1 ? parameters[1] : "master"); + var res = Instance.Repository.Setup(parameters[0], parameters.Count > 1 ? parameters[1] : "master"); if (res != null) { OutputProc("Error: " + res); @@ -113,7 +112,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var Repo = Interface.GetComponent(); + var Repo = Instance.Repository; var busy = Repo.OperationInProgress(); if (!busy) { @@ -167,7 +166,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var result = Interface.GetComponent().Reset(parameters.Count > 0 && parameters[0].ToLower() == "--origin"); + var result = Instance.Repository.Reset(parameters.Count > 0 && parameters[0].ToLower() == "--origin"); OutputProc(result ?? "Success!"); return result == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -203,7 +202,7 @@ namespace TGS.CommandLine OutputProc("Invalid parameter: " + parameters[0]); return ExitCode.BadCommand; } - var res = Interface.GetComponent().Update(hard); + var res = Instance.Repository.Update(hard); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -224,7 +223,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var result = Interface.GetComponent().GenerateChangelog(out string error); + var result = Instance.Repository.GenerateChangelog(out string error); OutputProc(error ?? "Success!"); if (result != null) OutputProc(result); @@ -244,7 +243,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var result = Interface.GetComponent().SynchronizePush(); + var result = Instance.Repository.SynchronizePush(); if(result != null) OutputProc(result); return result == null ? ExitCode.Normal : ExitCode.ServerError; @@ -264,7 +263,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - Interface.GetComponent().SetCommitterEmail(parameters[0]); + Instance.Repository.SetCommitterEmail(parameters[0]); return ExitCode.Normal; } @@ -286,7 +285,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - Interface.GetComponent().SetCommitterName(parameters[0]); + Instance.Repository.SetCommitterName(parameters[0]); return ExitCode.Normal; } public override string GetArgumentString() @@ -319,7 +318,7 @@ namespace TGS.CommandLine OutputProc("Invalid PR Number!"); return ExitCode.BadCommand; } - var res = Interface.GetComponent().MergePullRequest(PR); + var res = Instance.Repository.MergePullRequest(PR); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -346,7 +345,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var data = Interface.GetComponent().MergedPullRequests(out string error); + var data = Instance.Repository.MergedPullRequests(out string error); if (data == null) { OutputProc(error); @@ -373,7 +372,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var data = Interface.GetComponent().ListBackups(out string error); + var data = Instance.Repository.ListBackups(out string error); if (data == null) { OutputProc(error); @@ -400,7 +399,7 @@ namespace TGS.CommandLine } protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().Checkout(parameters[0]); + var res = Instance.Repository.Checkout(parameters[0]); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } diff --git a/TGS.CommandLine/RootCommands.cs b/TGS.CommandLine/RootCommands.cs index de6edae4ac..99188d4009 100644 --- a/TGS.CommandLine/RootCommands.cs +++ b/TGS.CommandLine/RootCommands.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using TGS.Interface; -using TGS.Interface.Components; namespace TGS.CommandLine { @@ -10,9 +9,9 @@ namespace TGS.CommandLine public CLICommand(IServerInterface I) { var tmp = new List { new UpdateCommand(), new TestmergeCommand(), new RepoCommand(), new BYONDCommand(), new DMCommand(), new DDCommand(), new ConfigCommand(), new IRCCommand(), new DiscordCommand(), new AutoUpdateCommand(), new SetAutoUpdateCommand() }; - if (I.ConnectToInstance().HasFlag(ConnectivityLevel.Administrator)) + if (ConsoleCommand.Instance.Administration != null) tmp.Add(new AdminCommand()); - if (I.ConnectionStatus().HasFlag(ConnectivityLevel.Administrator)) + if (ConsoleCommand.Server.Management != null) tmp.Add(new ServiceCommand()); Children = tmp.ToArray(); } @@ -37,7 +36,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { - var res = Interface.GetComponent().AutoUpdateInterval(); + var res = Instance.Repository.AutoUpdateInterval(); OutputProc(res == 0 ? "OFF" : String.Format("Auto updating every {0} minutes", res)); return ExitCode.Normal; } @@ -76,7 +75,7 @@ namespace TGS.CommandLine return ExitCode.BadCommand; } - Interface.GetComponent().SetAutoUpdateInterval(NewInterval); + Instance.Repository.SetAutoUpdateInterval(NewInterval); return ExitCode.Normal; } @@ -91,7 +90,7 @@ namespace TGS.CommandLine protected override ExitCode Run(IList parameters) { var gen_cl = parameters.Count > 1 && parameters[1].ToLower() == "--cl"; - var Repo = Interface.GetComponent(); + var Repo = Instance.Repository; switch (parameters[0].ToLower()) { case "hard": @@ -126,7 +125,7 @@ namespace TGS.CommandLine OutputProc(res); } } - var resu = Interface.GetComponent().Compile(true); + var resu = Instance.Compiler.Compile(true); OutputProc(resu ? "Compilation started!" : "Compilation could not be started!"); return resu ? ExitCode.Normal : ExitCode.ServerError; } @@ -163,7 +162,7 @@ namespace TGS.CommandLine OutputProc("Invalid tesmerge #: " + parameters[0]); return ExitCode.BadCommand; } - var Repo = Interface.GetComponent(); + var Repo = Instance.Repository; var res = Repo.MergePullRequest(tm); if (res != null) { @@ -176,7 +175,7 @@ namespace TGS.CommandLine OutputProc(res); return ExitCode.ServerError; } - var resu = Interface.GetComponent().Compile(true); + var resu = Instance.Compiler.Compile(true); OutputProc(resu ? "Compilation started!" : "Compilation could not be started!"); return resu ? ExitCode.Normal : ExitCode.ServerError; } diff --git a/TGS.CommandLine/ServiceCommands.cs b/TGS.CommandLine/ServiceCommands.cs index 833469d0c8..d1a3274d60 100644 --- a/TGS.CommandLine/ServiceCommands.cs +++ b/TGS.CommandLine/ServiceCommands.cs @@ -55,7 +55,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - var res = Interface.GetServiceComponent().CreateInstance(parameters[0], parameters[1]); + var res = Server.InstanceManager.CreateInstance(parameters[0], parameters[1]); if (res != null) { OutputProc(res); @@ -87,8 +87,8 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - foreach (var I in Interface.GetServiceComponent().ListInstances()) - OutputProc(String.Format("{0} ({1}):\t{2}{3}", I.Name, I.Path, I.Enabled ? "Online" : "Offline", I.Enabled ? String.Format(" ({0})", I.LoggingID) : "")); + foreach (var I in Server.Instances) + OutputProc(I.ToString()); return ExitCode.Normal; } } @@ -122,7 +122,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - var res = Interface.GetServiceComponent().DetachInstance(parameters[0]); + var res = Server.InstanceManager.DetachInstance(parameters[0]); if (res != null) { OutputProc(res); @@ -161,7 +161,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - var res = Interface.GetServiceComponent().ImportInstance(parameters[0]); + var res = Server.InstanceManager.ImportInstance(parameters[0]); if (res != null) { OutputProc(res); @@ -193,7 +193,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - var res = Interface.GetServiceComponent().PythonPath(); + var res = Server.Management.PythonPath(); if (res != null) { OutputProc(res); @@ -232,7 +232,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - Interface.GetServiceComponent().SetPythonPath(parameters[0]); + Server.Management.SetPythonPath(parameters[0]); return ExitCode.Normal; } } @@ -266,7 +266,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - var res = Interface.GetServiceComponent().SetInstanceEnabled(parameters[0], true); + var res = Server.InstanceManager.SetInstanceEnabled(parameters[0], true); if (res != null) { OutputProc(res); @@ -305,7 +305,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - var res = Interface.GetServiceComponent().SetInstanceEnabled(parameters[0], false); + var res = Server.InstanceManager.SetInstanceEnabled(parameters[0], false); if (res != null) { OutputProc(res); @@ -316,7 +316,7 @@ namespace TGS.CommandLine } /// - /// Command for calling + /// Command for calling /// class ServiceRemoteAccessPortCommand : ConsoleCommand { @@ -337,7 +337,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - OutputProc(Interface.GetServiceComponent().RemoteAccessPort().ToString()); + OutputProc(Server.Management.RemoteAccessPort().ToString()); return ExitCode.Normal; } } @@ -382,7 +382,7 @@ namespace TGS.CommandLine return ExitCode.BadCommand; } - var res = Interface.GetServiceComponent().SetRemoteAccessPort(port); + var res = Server.Management.SetRemoteAccessPort(port); if (res != null) { OutputProc(res); @@ -422,7 +422,7 @@ namespace TGS.CommandLine /// protected override ExitCode Run(IList parameters) { - var res = Interface.GetServiceComponent().RenameInstance(parameters[0], parameters[1]); + var res = Server.InstanceManager.RenameInstance(parameters[0], parameters[1]); if (res != null) { OutputProc(res); diff --git a/TGS.CommandLine/TGS.CommandLine.csproj b/TGS.CommandLine/TGS.CommandLine.csproj index a4086c5979..d0369c4c5d 100644 --- a/TGS.CommandLine/TGS.CommandLine.csproj +++ b/TGS.CommandLine/TGS.CommandLine.csproj @@ -51,7 +51,6 @@ - diff --git a/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs b/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs index 04d6bc1343..937c1780c5 100644 --- a/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs +++ b/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs @@ -12,10 +12,10 @@ namespace TGS.CommandLine.Commands.Repository.Tests /// /// The the resulting should return /// A mock - protected IServerInterface MockInterfaceToRepo(ITGRepository repo) + protected IInstance MockInterfaceToRepo(ITGRepository repo) { - var mock = new Mock(); - mock.Setup(foo => foo.GetComponent()).Returns(repo); + var mock = new Mock(); + mock.Setup(foo => foo.Repository).Returns(repo); return mock.Object; } } diff --git a/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs b/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs index 54df717166..19301b5172 100644 --- a/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs +++ b/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs @@ -21,7 +21,7 @@ namespace TGS.CommandLine.Commands.Repository.Tests var ran = false; var repo = new Mock(); repo.Setup(foo => foo.SetPushTestmergeCommits(true)).Callback(() => { ran = true; }); - ConsoleCommand.Interface = MockInterfaceToRepo(repo.Object); + ConsoleCommand.Server = MockInterfaceToRepo(repo.Object); Assert.AreEqual(new RepoSetPushTestmergeCommitsCommand().DoRun(new List { "on" }), Command.ExitCode.Normal); Assert.IsTrue(ran); } @@ -36,7 +36,7 @@ namespace TGS.CommandLine.Commands.Repository.Tests var ran = false; var repo = new Mock(); repo.Setup(foo => foo.SetPushTestmergeCommits(false)).Callback(() => { ran = true; }); - ConsoleCommand.Interface = MockInterfaceToRepo(repo.Object); + ConsoleCommand.Server = MockInterfaceToRepo(repo.Object); Assert.AreEqual(new RepoSetPushTestmergeCommitsCommand().DoRun(new List { "off" }), Command.ExitCode.Normal); Assert.IsTrue(ran); } diff --git a/TGS.Tests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs b/TGS.Tests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs index 3efebced20..f1aea5ce1d 100644 --- a/TGS.Tests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs +++ b/TGS.Tests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs @@ -32,13 +32,13 @@ namespace TGS.CommandLine.Commands.Repository.Tests var ran = false; var mock = GetDefaultMock(); mock.Setup(foo => foo.PushTestmergeCommits()).Returns(false).Callback(() => ran = true); - ConsoleCommand.Interface = MockInterfaceToRepo(mock.Object); + ConsoleCommand.Instance = MockInterfaceToRepo(mock.Object); Assert.AreEqual(new RepoStatusCommand().DoRun(new List { }), Command.ExitCode.Normal); Assert.IsTrue(ran); ran = false; mock.Setup(foo => foo.PushTestmergeCommits()).Returns(true).Callback(() => ran = true); - ConsoleCommand.Interface = MockInterfaceToRepo(mock.Object); + ConsoleCommand.Instance = MockInterfaceToRepo(mock.Object); Assert.AreEqual(new RepoStatusCommand().DoRun(new List { }), Command.ExitCode.Normal); Assert.IsTrue(ran); } From 4d5b4735fb02e35d6e46bd17447ed1200c87f315 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 13:12:18 -0500 Subject: [PATCH 16/18] Update Installer.UI and tests to use the new IServerInterface --- TGS.Installer.UI/Main.cs | 12 ++++++------ .../TestRepoSetPushTestmergeCommitsCommand.cs | 4 ++-- TGS.Tests/ControlPanel/TestInstanceSelector.cs | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/TGS.Installer.UI/Main.cs b/TGS.Installer.UI/Main.cs index 57e33887d4..caea2cf03c 100644 --- a/TGS.Installer.UI/Main.cs +++ b/TGS.Installer.UI/Main.cs @@ -79,7 +79,7 @@ namespace TGS.Installer.UI var verifiedConnection = Interface.ConnectionStatus().HasFlag(ConnectivityLevel.Administrator); try { - var realVersion = Interface.ServerVersion; + var realVersion = Interface.Server.Version; var isV0 = realVersion < new Version(3, 1, 0, 0); if (isV0) //OH GOD!!!! MessageBox.Show("Upgrading from version 3.0 may trigger a bug that can delete /config and /data. IT IS STRONGLY RECCOMMENDED THAT YOU BACKUP THESE FOLDERS BEFORE UPDATING!", "Warning"); @@ -106,7 +106,7 @@ namespace TGS.Installer.UI var connectionVerified = Interface.ConnectionStatus().HasFlag(ConnectivityLevel.Administrator); try { - Interface.GetServiceComponent().PrepareForUpdate(); + Interface.Server.Management.PrepareForUpdate(); Thread.Sleep(3000); //chat messages return true; } @@ -194,18 +194,18 @@ namespace TGS.Installer.UI var sc = new ServerConfig(); try { - sc.PythonPath = Interface.GetServiceComponent().PythonPath(); + sc.PythonPath = Interface.Server.Management.PythonPath(); } catch { } try { - sc.RemoteAccessPort = Interface.GetServiceComponent().RemoteAccessPort(); + sc.RemoteAccessPort = Interface.Server.Management.RemoteAccessPort(); } catch { } try { - foreach (var I in Interface.GetServiceComponent().ListInstances()) - sc.InstancePaths.Add(I.Path); + foreach (var I in Interface.Server.Instances) + sc.InstancePaths.Add(I.Metadata.Path); } catch { } diff --git a/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs b/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs index 19301b5172..a5f2b72ede 100644 --- a/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs +++ b/TGS.Tests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs @@ -21,7 +21,7 @@ namespace TGS.CommandLine.Commands.Repository.Tests var ran = false; var repo = new Mock(); repo.Setup(foo => foo.SetPushTestmergeCommits(true)).Callback(() => { ran = true; }); - ConsoleCommand.Server = MockInterfaceToRepo(repo.Object); + ConsoleCommand.Instance = MockInterfaceToRepo(repo.Object); Assert.AreEqual(new RepoSetPushTestmergeCommitsCommand().DoRun(new List { "on" }), Command.ExitCode.Normal); Assert.IsTrue(ran); } @@ -36,7 +36,7 @@ namespace TGS.CommandLine.Commands.Repository.Tests var ran = false; var repo = new Mock(); repo.Setup(foo => foo.SetPushTestmergeCommits(false)).Callback(() => { ran = true; }); - ConsoleCommand.Server = MockInterfaceToRepo(repo.Object); + ConsoleCommand.Instance = MockInterfaceToRepo(repo.Object); Assert.AreEqual(new RepoSetPushTestmergeCommitsCommand().DoRun(new List { "off" }), Command.ExitCode.Normal); Assert.IsTrue(ran); } diff --git a/TGS.Tests/ControlPanel/TestInstanceSelector.cs b/TGS.Tests/ControlPanel/TestInstanceSelector.cs index 913d89017d..2d65a3b1db 100644 --- a/TGS.Tests/ControlPanel/TestInstanceSelector.cs +++ b/TGS.Tests/ControlPanel/TestInstanceSelector.cs @@ -20,8 +20,7 @@ namespace TGS.ControlPanel.Tests { var mockLanding = new Mock(); mockLanding.Setup(x => x.ListInstances()).Returns(new List()); - var mockInter = new Mock(); - mockInter.Setup(x => x.GetComponent()).Returns(mockLanding.Object); + var mockInter = new Mock(); new InstanceSelector(mockInter.Object).Dispose(); } From 827604f3416a540403b35cfc335095268a9c4f36 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 13:19:28 -0500 Subject: [PATCH 17/18] Rename (I)ServerInterface to (I)Client --- TGS.CommandLine/Program.cs | 20 +++++++++---------- TGS.CommandLine/RootCommands.cs | 2 +- TGS.ControlPanel/Login.cs | 10 +++++----- TGS.ControlPanel/Program.cs | 4 ++-- TGS.ControlPanel/ServerOpForm.cs | 6 +++--- TGS.Installer.UI/Main.cs | 4 ++-- TGS.Interface.Bridge/DreamDaemonBridge.cs | 2 +- .../{ServerInterface.cs => Client.cs} | 12 +++++------ .../{IServerInterface.cs => IClient.cs} | 12 +++++------ TGS.Interface/Instance.cs | 8 ++++---- TGS.Interface/Server.cs | 8 ++++---- TGS.Interface/TGS.Interface.csproj | 4 ++-- TGS.Server/Instance/Compiler.cs | 2 +- TGS.Server/Instance/DreamDaemon.cs | 2 +- .../Repository/RepositoryCommandTest.cs | 6 +++--- TGS.Tests/ServiceInterface/TestInterface.cs | 14 ++++++------- 16 files changed, 58 insertions(+), 58 deletions(-) rename TGS.Interface/{ServerInterface.cs => Client.cs} (94%) rename TGS.Interface/{IServerInterface.cs => IClient.cs} (63%) diff --git a/TGS.CommandLine/Program.cs b/TGS.CommandLine/Program.cs index 59d41f71da..369652de33 100644 --- a/TGS.CommandLine/Program.cs +++ b/TGS.CommandLine/Program.cs @@ -9,7 +9,7 @@ namespace TGS.CommandLine class Program { static bool interactive = false, saidSrvVersion = false; - static IServerInterface currentInterface; + static IClient currentInterface; static Command.ExitCode RunCommandLine(IList argsAsList) { //first lookup the connection string @@ -52,7 +52,7 @@ namespace TGS.CommandLine } argsAsList.RemoveAt(I); argsAsList.RemoveAt(I); - ReplaceInterface(new ServerInterface(new RemoteLoginInfo(address, port, username, password))); + ReplaceInterface(new Client(new RemoteLoginInfo(address, port, username, password))); break; } } @@ -99,7 +99,7 @@ namespace TGS.CommandLine }; } - static void ReplaceInterface(IServerInterface I) + static void ReplaceInterface(IClient I) { currentInterface = I; ConsoleCommand.Server = I.Server; @@ -173,7 +173,7 @@ namespace TGS.CommandLine static int Main(string[] args) { - ReplaceInterface(new ServerInterface()); + ReplaceInterface(new Client()); Command.OutputProcVar.Value = Console.WriteLine; if (args.Length != 0) { @@ -191,13 +191,13 @@ namespace TGS.CommandLine { argsAsList.RemoveAt(I); --I; - ServerInterface.SetBadCertificateHandler(_ => false); + Client.SetBadCertificateHandler(_ => false); } } return (int)RunCommandLine(argsAsList); } //interactive mode - ServerInterface.SetBadCertificateHandler(BadCertificateInteractive); + Client.SetBadCertificateHandler(BadCertificateInteractive); Console.WriteLine("Type 'instance' to connect to a server instance"); Console.WriteLine("Type 'remote' to connect to a remote service"); while (true) @@ -228,17 +228,17 @@ namespace TGS.CommandLine var username = Console.ReadLine(); Console.Write("Enter password: "); var password = ReadLineSecure(); - ReplaceInterface(new ServerInterface(new RemoteLoginInfo(address, port, username, password))); + ReplaceInterface(new Client(new RemoteLoginInfo(address, port, username, password))); var res = currentInterface.ConnectionStatus(out string error); if (!res.HasFlag(ConnectivityLevel.Connected)) { Console.WriteLine("Unable to connect: " + error); - ReplaceInterface(new ServerInterface()); + ReplaceInterface(new Client()); } else if (!res.HasFlag(ConnectivityLevel.Authenticated)) { Console.WriteLine("Authentication error: Username/password/windows identity is not authorized! Returning to local mode..."); - ReplaceInterface(new ServerInterface()); + ReplaceInterface(new Client()); } else { @@ -253,7 +253,7 @@ namespace TGS.CommandLine break; case "disconnect": SentVMMWarning = false; - ReplaceInterface(new ServerInterface()); + ReplaceInterface(new Client()); Console.WriteLine("Switch to local mode"); break; case "quit": diff --git a/TGS.CommandLine/RootCommands.cs b/TGS.CommandLine/RootCommands.cs index 99188d4009..0de21674cd 100644 --- a/TGS.CommandLine/RootCommands.cs +++ b/TGS.CommandLine/RootCommands.cs @@ -6,7 +6,7 @@ namespace TGS.CommandLine { class CLICommand : RootCommand { - public CLICommand(IServerInterface I) + public CLICommand(IClient I) { var tmp = new List { new UpdateCommand(), new TestmergeCommand(), new RepoCommand(), new BYONDCommand(), new DMCommand(), new DDCommand(), new ConfigCommand(), new IRCCommand(), new DiscordCommand(), new AutoUpdateCommand(), new SetAutoUpdateCommand() }; if (ConsoleCommand.Instance.Administration != null) diff --git a/TGS.ControlPanel/Login.cs b/TGS.ControlPanel/Login.cs index f4c44e9523..070ed683d5 100644 --- a/TGS.ControlPanel/Login.cs +++ b/TGS.ControlPanel/Login.cs @@ -92,7 +92,7 @@ namespace TGS.ControlPanel loginInfo.Password = PasswordTextBox.Text; } - var I = new ServerInterface(loginInfo); + var I = new Client(loginInfo); var Config = Properties.Settings.Default; //This needs to be read here because V&C Closing us will corrupt the data var savePassword = SavePasswordCheckBox.Checked; @@ -114,15 +114,15 @@ namespace TGS.ControlPanel void LocalLoginButton_Click(object sender, EventArgs e) { Properties.Settings.Default.RemoteDefault = false; - VerifyAndConnect(new ServerInterface()); + VerifyAndConnect(new Client()); } /// - /// Attempts a connection on a given + /// Attempts a connection on a given /// - /// The to attempt a connection on + /// The to attempt a connection on /// if the connection was made and authenticated, otherwise - bool VerifyAndConnect(IServerInterface I) + bool VerifyAndConnect(IClient I) { try { diff --git a/TGS.ControlPanel/Program.cs b/TGS.ControlPanel/Program.cs index c0472c87c4..50768d847a 100644 --- a/TGS.ControlPanel/Program.cs +++ b/TGS.ControlPanel/Program.cs @@ -7,7 +7,7 @@ namespace TGS.ControlPanel { static class Program { - public static IServerInterface ServerInterface; + public static IClient ServerInterface; [STAThread] static void Main(string[] args) { @@ -21,7 +21,7 @@ namespace TGS.ControlPanel } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Interface.ServerInterface.SetBadCertificateHandler(BadCertificateHandler); + Interface.Client.SetBadCertificateHandler(BadCertificateHandler); Application.Run(new Login()); if(ServerInterface != null) { diff --git a/TGS.ControlPanel/ServerOpForm.cs b/TGS.ControlPanel/ServerOpForm.cs index 19c083b0a5..5188cd2b31 100644 --- a/TGS.ControlPanel/ServerOpForm.cs +++ b/TGS.ControlPanel/ServerOpForm.cs @@ -5,7 +5,7 @@ using System.Windows.Forms; namespace TGS.ControlPanel { /// - /// Used to provide an ATP function for calls into an + /// Used to provide an ATP function for calls into an /// #if !DEBUG abstract @@ -13,9 +13,9 @@ namespace TGS.ControlPanel class ServerOpForm : Form { /// - /// Used to wrap calls in a non-blocking fashion while disabling the and enabling the wait cursor + /// Used to wrap calls in a non-blocking fashion while disabling the and enabling the wait cursor /// - /// The operation to wrap + /// The operation to wrap /// A wrapping protected Task WrapServerOp(Action action) { diff --git a/TGS.Installer.UI/Main.cs b/TGS.Installer.UI/Main.cs index caea2cf03c..955283ed10 100644 --- a/TGS.Installer.UI/Main.cs +++ b/TGS.Installer.UI/Main.cs @@ -26,7 +26,7 @@ namespace TGS.Installer.UI /// bool attemptNetSettingsMigration = false; - IServerInterface Interface; + IClient Interface; /// /// Construct an installer form @@ -75,7 +75,7 @@ namespace TGS.Installer.UI } void CheckForExistingVersion() { - Interface = new ServerInterface(); + Interface = new Client(); var verifiedConnection = Interface.ConnectionStatus().HasFlag(ConnectivityLevel.Administrator); try { diff --git a/TGS.Interface.Bridge/DreamDaemonBridge.cs b/TGS.Interface.Bridge/DreamDaemonBridge.cs index ac609f4060..8465beb682 100644 --- a/TGS.Interface.Bridge/DreamDaemonBridge.cs +++ b/TGS.Interface.Bridge/DreamDaemonBridge.cs @@ -25,7 +25,7 @@ namespace TGS.Interface.Bridge parsedArgs.AddRange(args); var instance = parsedArgs[0]; parsedArgs.RemoveAt(0); - using (var I = new ServerInterface()) + using (var I = new Client()) I.Server.GetInstance(instance).Interop.InteropMessage(String.Join(" ", parsedArgs)); } catch { } diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/Client.cs similarity index 94% rename from TGS.Interface/ServerInterface.cs rename to TGS.Interface/Client.cs index f233b70b4e..b13b16364b 100644 --- a/TGS.Interface/ServerInterface.cs +++ b/TGS.Interface/Client.cs @@ -12,7 +12,7 @@ using TGS.Interface.Components; namespace TGS.Interface { /// - sealed public class ServerInterface : IServerInterface + sealed public class Client : IClient { /// public IServer Server => server; @@ -97,19 +97,19 @@ namespace TGS.Interface } /// - /// Construct an for a local connection + /// Construct an for a local connection /// - public ServerInterface() + public Client() { ChannelFactoryCache = new Dictionary(); server = new Server(this); } /// - /// Construct an for a remote connection + /// Construct an for a remote connection /// /// The for a remote connection - public ServerInterface(RemoteLoginInfo loginInfo) : this() + public Client(RemoteLoginInfo loginInfo) : this() { if (!loginInfo.HasPassword) throw new InvalidOperationException("password must be set on loginInfo!"); @@ -158,7 +158,7 @@ namespace TGS.Interface } /// - /// Returns the requested component for the instance . This does not guarantee a successful connection. s created this way are recycled for minimum latency and bandwidth usage + /// Returns the requested component for the instance . This does not guarantee a successful connection. s created this way are recycled for minimum latency and bandwidth usage /// /// The component to retrieve /// The name of the to use diff --git a/TGS.Interface/IServerInterface.cs b/TGS.Interface/IClient.cs similarity index 63% rename from TGS.Interface/IServerInterface.cs rename to TGS.Interface/IClient.cs index 9848bcb588..02394200fa 100644 --- a/TGS.Interface/IServerInterface.cs +++ b/TGS.Interface/IClient.cs @@ -5,28 +5,28 @@ namespace TGS.Interface /// /// Main for communicating the /// - public interface IServerInterface : IDisposable + public interface IClient : IDisposable { /// - /// The the connects to + /// The the connects to /// IServer Server { get; } /// - /// The for the . Is for local connections + /// The for the . Is for local connections /// RemoteLoginInfo LoginInfo { get; } /// - /// Checks if the is setup for a remote connection + /// Checks if the is setup for a remote connection /// bool IsRemoteConnection { get; } /// - /// Returns if the interface being used to connect to a service does not have the same release version as the service + /// Returns if the interface being used to connect to a service does not have the same release version as the service /// /// An error message to display to the user should this function return - /// if the interface being used to connect to a service does not have the same release version as the service + /// if the interface being used to connect to a service does not have the same release version as the service bool VersionMismatch(out string errorMessage); /// diff --git a/TGS.Interface/Instance.cs b/TGS.Interface/Instance.cs index a02a833685..31d2c31a44 100644 --- a/TGS.Interface/Instance.cs +++ b/TGS.Interface/Instance.cs @@ -45,9 +45,9 @@ namespace TGS.Interface } /// - /// The backing + /// The backing /// - readonly ServerInterface serverInterface; + readonly Client serverInterface; /// /// The name of the /// @@ -60,9 +60,9 @@ namespace TGS.Interface /// /// Construct an /// - /// The to use + /// The to use /// The for the - public Instance(ServerInterface _serverInterface, InstanceMetadata _metadata) + public Instance(Client _serverInterface, InstanceMetadata _metadata) { serverInterface = _serverInterface; metadata = _metadata; diff --git a/TGS.Interface/Server.cs b/TGS.Interface/Server.cs index 0e0050022b..d934528832 100644 --- a/TGS.Interface/Server.cs +++ b/TGS.Interface/Server.cs @@ -64,9 +64,9 @@ namespace TGS.Interface } /// - /// The backing + /// The backing /// - readonly ServerInterface serverInterface; + readonly Client serverInterface; /// /// Result of a call to @@ -81,8 +81,8 @@ namespace TGS.Interface /// /// Construct an /// - /// The to use - public Server(ServerInterface _serverInterface) + /// The to use + public Server(Client _serverInterface) { serverInterface = _serverInterface; } diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index 5ef6e8a5af..42cb6b71b0 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -69,13 +69,13 @@ - + - + diff --git a/TGS.Server/Instance/Compiler.cs b/TGS.Server/Instance/Compiler.cs index 87e933ea33..90ae74a4eb 100644 --- a/TGS.Server/Instance/Compiler.cs +++ b/TGS.Server/Instance/Compiler.cs @@ -119,7 +119,7 @@ namespace TGS.Server //what is says on the tin CompilerStatus IsInitialized() { - if (File.Exists(RelativePath(Path.Combine(GameDirLive, BridgeDLLName))) || File.Exists(RelativePath(Path.Combine(GameDirLive, Assembly.GetAssembly(typeof(IServerInterface)).GetName().Name + ".dll")))) //its a good tell, jim + if (File.Exists(RelativePath(Path.Combine(GameDirLive, BridgeDLLName))) || File.Exists(RelativePath(Path.Combine(GameDirLive, Assembly.GetAssembly(typeof(IClient)).GetName().Name + ".dll")))) //its a good tell, jim return CompilerStatus.Initialized; return CompilerStatus.Uninitialized; } diff --git a/TGS.Server/Instance/DreamDaemon.cs b/TGS.Server/Instance/DreamDaemon.cs index 805c315d09..9f7d13774f 100644 --- a/TGS.Server/Instance/DreamDaemon.cs +++ b/TGS.Server/Instance/DreamDaemon.cs @@ -535,7 +535,7 @@ namespace TGS.Server return; //Copy the interface dll to the static dir - var InterfacePath = Assembly.GetAssembly(typeof(IServerInterface)).Location; + var InterfacePath = Assembly.GetAssembly(typeof(IClient)).Location; //bridge is installed next to the interface var BridgePath = Path.Combine(Path.GetDirectoryName(InterfacePath), BridgeDLLName); #if DEBUG diff --git a/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs b/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs index 937c1780c5..4735b8ccd5 100644 --- a/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs +++ b/TGS.Tests/CommandLine/Commands/Repository/RepositoryCommandTest.cs @@ -8,10 +8,10 @@ namespace TGS.CommandLine.Commands.Repository.Tests public abstract class RepositoryCommandTest : OutputProcOverriderTest { /// - /// Creates a mock that returns a specific when that component is requested + /// Creates a mock that returns a specific when that component is requested /// - /// The the resulting should return - /// A mock + /// The the resulting should return + /// A mock protected IInstance MockInterfaceToRepo(ITGRepository repo) { var mock = new Mock(); diff --git a/TGS.Tests/ServiceInterface/TestInterface.cs b/TGS.Tests/ServiceInterface/TestInterface.cs index 5afeaadc6e..1b51fa2b50 100644 --- a/TGS.Tests/ServiceInterface/TestInterface.cs +++ b/TGS.Tests/ServiceInterface/TestInterface.cs @@ -27,7 +27,7 @@ namespace TGS.Interface.Tests Assert.IsFalse(String.IsNullOrWhiteSpace(message)); return true; }; - ServerInterface.SetBadCertificateHandler(func); + Client.SetBadCertificateHandler(func); } /// @@ -37,7 +37,7 @@ namespace TGS.Interface.Tests public void TestBadCertificateHandler() { var ran = false; - ServerInterface.SetBadCertificateHandler(_ => + Client.SetBadCertificateHandler(_ => { ran = true; return true; @@ -50,9 +50,9 @@ namespace TGS.Interface.Tests /// Creates a remote configured pointing at an invalid address /// /// The created - ServerInterface CreateFakeRemoteInterface() + Client CreateFakeRemoteInterface() { - return new ServerInterface(new RemoteLoginInfo("some.fake.url.420", 34752, "user", "password")); + return new Client(new RemoteLoginInfo("some.fake.url.420", 34752, "user", "password")); } /// @@ -61,7 +61,7 @@ namespace TGS.Interface.Tests [TestMethod] public void TestLocalInstantiation() { - Assert.IsFalse(new ServerInterface().IsRemoteConnection); + Assert.IsFalse(new Client().IsRemoteConnection); } /// @@ -77,7 +77,7 @@ namespace TGS.Interface.Tests public void TestCopyRemoteInterface() { var first = CreateFakeRemoteInterface(); - var second = new ServerInterface(first.LoginInfo); + var second = new Client(first.LoginInfo); Assert.AreEqual(first.LoginInfo.IP, second.LoginInfo.IP); Assert.AreEqual(first.LoginInfo.Port, second.LoginInfo.Port); Assert.AreEqual(first.LoginInfo.Username, second.LoginInfo.Username); @@ -88,7 +88,7 @@ namespace TGS.Interface.Tests [TestMethod] public void TestLocalAccessInterfaceAllowsWindowsImpersonation() { - var inter = new ServerInterface(); + var inter = new Client(); var po = new PrivateObject(inter); var cf = (ChannelFactory)po.Invoke("CreateChannel", new Type[] { typeof(string) }, new object[] { TestInstanceName }, new Type[] { typeof(ITGConfig) }); Assert.AreEqual(cf.Credentials.Windows.AllowedImpersonationLevel, System.Security.Principal.TokenImpersonationLevel.Impersonation); From e0766b42e1e952d5bd9c6bdb31b492b800ae72ce Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 14:58:18 -0500 Subject: [PATCH 18/18] Move Version from Definitions to Client --- TGS.Interface/Client.cs | 10 +++++++--- TGS.Interface/Definitions.cs | 5 ----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/TGS.Interface/Client.cs b/TGS.Interface/Client.cs index b13b16364b..4d36381950 100644 --- a/TGS.Interface/Client.cs +++ b/TGS.Interface/Client.cs @@ -14,6 +14,11 @@ namespace TGS.Interface /// sealed public class Client : IClient { + /// + /// Version of the + /// + public static readonly Version Version = Assembly.GetExecutingAssembly().GetName().Version; + /// public IServer Server => server; @@ -147,10 +152,9 @@ namespace TGS.Interface /// public bool VersionMismatch(out string errorMessage) { - var version = Definitions.Version; - if (ServerVersion.Major != version.Major || ServerVersion.Minor != version.Minor || ServerVersion.Build != version.Build) //don't care about the patch level + if (ServerVersion.Major != Version.Major || ServerVersion.Minor != Version.Minor || ServerVersion.Build != Version.Build) //don't care about the patch level { - errorMessage = String.Format("Version mismatch between interface version ({0}) and service version ({1}). Some functionality may crash this program.", version, ServerVersion); + errorMessage = String.Format("Version mismatch between interface version ({0}) and service version ({1}). Some functionality may crash this program.", Version, ServerVersion); return true; } errorMessage = null; diff --git a/TGS.Interface/Definitions.cs b/TGS.Interface/Definitions.cs index a39fd6ed7c..05cc952c33 100644 --- a/TGS.Interface/Definitions.cs +++ b/TGS.Interface/Definitions.cs @@ -28,10 +28,5 @@ namespace TGS.Interface /// Base name of instance URLs /// public const string InstanceInterfaceName = MasterInterfaceName + "/Instance"; - - /// - /// Version of the interface - /// - public static readonly Version Version = Assembly.GetExecutingAssembly().GetName().Version; } }