diff --git a/TGServerService/ServerInstance/PreactionHandler.cs b/TGServerService/ServerInstance/PreactionHandler.cs
index 668bd7932d..7a4ef27723 100644
--- a/TGServerService/ServerInstance/PreactionHandler.cs
+++ b/TGServerService/ServerInstance/PreactionHandler.cs
@@ -7,18 +7,44 @@ namespace TGServerService
// Some useful functions for triggering pre action events
sealed partial class ServerInstance
{
+ ///
+ /// The instance directory for Preaction handlers
+ ///
const string EventFolder = "EventHandlers/";
- string GetPath(string eventName)
+ ///
+ /// Creates the
+ ///
+ void InitEventHandlers()
+ {
+ Directory.CreateDirectory(EventFolder);
+ }
+
+ ///
+ /// Gets the path of an event given an
+ ///
+ /// The name of the event
+ /// The path to the event handler
+ string GetEventPath(string eventName)
{
return string.Format("{0}{1}.bat", EventFolder, eventName);
}
+ ///
+ /// Check if an event handler for exists
+ ///
+ /// The name of the event
+ /// if the event handler exists, otherwise
bool EventHandlerExists(string eventName)
{
- return File.Exists(GetPath(eventName));
+ return File.Exists(GetEventPath(eventName));
}
+ ///
+ /// Runs an event named if it exists
+ ///
+ /// The name of the event
+ /// if the event handler exists and failed to run, otherwise
bool HandleEvent(string eventName)
{
@@ -32,7 +58,7 @@ namespace TGServerService
{
StartInfo = new ProcessStartInfo
{
- FileName = GetPath(eventName),
+ FileName = GetEventPath(eventName),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
@@ -45,7 +71,7 @@ namespace TGServerService
var stdout = process.StandardOutput.ReadToEnd();
var stderr = process.StandardError.ReadToEnd();
var success = process.ExitCode == 0;
- var eventData = String.Format("Preaction Event: {0} @ {1} ran. Stdout:\n{2}\nStderr:\n{3}", eventName, GetPath(eventName), stdout, stderr);
+ var eventData = String.Format("Preaction Event: {0} @ {1} ran. Stdout:\n{2}\nStderr:\n{3}", eventName, GetEventPath(eventName), stdout, stderr);
if (success)
Service.WriteInfo(eventData, EventID.PreactionEvent);
@@ -55,11 +81,19 @@ namespace TGServerService
return success;
}
+ ///
+ /// Run the "precompile" event
+ ///
+ /// if the event handler exists and failed to run, otherwise
public bool PrecompileHook()
{
return HandleEvent("precompile");
}
+ ///
+ /// Run the "postcompile" event
+ ///
+ /// if the event handler exists and failed to run, otherwise
public bool PostcompileHook()
{
return HandleEvent("postcompile");
diff --git a/TGServerService/ServerInstance/ServerInstance.cs b/TGServerService/ServerInstance/ServerInstance.cs
index 7175e93c51..5006d2cd82 100644
--- a/TGServerService/ServerInstance/ServerInstance.cs
+++ b/TGServerService/ServerInstance/ServerInstance.cs
@@ -21,6 +21,7 @@ namespace TGServerService
public ServerInstance()
{
FindTheDroidsWereLookingFor();
+ InitEventHandlers();
InitChat();
InitRepo();
InitByond();