diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 0a88927638..8fef0d4865 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -1,5 +1,7 @@ -using System; +using RGiesecke.DllExport; +using System; using System.Collections.Generic; +using System.Runtime.InteropServices; using System.ServiceModel; namespace TGServiceInterface { @@ -8,7 +10,7 @@ namespace TGServiceInterface /// /// List of types that can be used with GetComponen /// - public static readonly IList ValidInterfaces = new List { typeof(ITGByond), typeof(ITGChat), typeof(ITGCompiler), typeof(ITGConfig), typeof(ITGDreamDaemon), typeof(ITGRepository), typeof(ITGServerUpdater), typeof(ITGSService) }; + public static readonly IList ValidInterfaces = new List { typeof(ITGByond), typeof(ITGChat), typeof(ITGCompiler), typeof(ITGConfig), typeof(ITGDreamDaemon), typeof(ITGRepository), typeof(ITGServerUpdater), typeof(ITGSService), typeof(ITGServiceBridge) }; /// /// Base name of the communication pipe @@ -29,7 +31,7 @@ namespace TGServiceInterface return new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterPipeName, typeof(T).Name))).CreateChannel(); } - + /// /// Used to test if the service is avaiable on the machine /// Note that state can technically change at any time @@ -43,7 +45,7 @@ namespace TGServiceInterface GetComponent().VerifyConnection(); return null; } - catch(Exception e) + catch (Exception e) { return e.ToString(); } @@ -120,4 +122,42 @@ namespace TGServiceInterface string UpdateServer(TGRepoUpdateMethod updateType, bool push_changelog_if_enabled, ushort testmerge_pr = 0); } + /// + /// Used by DD to access the interop API with call()() + /// + [ServiceContract] + public interface ITGServiceBridge + { + /// + /// Called from /world/ExportService(command) + /// + /// The command to run + /// + [OperationContract] + string InteropMessage(string command); + } + + /// + /// Holds the proc that DD calls to access + /// + class DDInteropCallHolder + { + /// + /// The proc that DD calls to access + /// + /// The arguments passed + /// The result of the command + [DllExport("DDEntryPoint", CallingConvention = CallingConvention.Cdecl)] + public static string DDEntryPoint(string[] args) + { + try + { + return Server.GetComponent().InteropMessage(String.Join(" ", args)); + } + catch (Exception e) + { + return "Service Error: " + e.Message; + } + } + } }