Adds a preaction framework so we can run a .bat file before or after compiling the code

This commit is contained in:
Jamie Hankins
2017-09-09 05:28:31 +01:00
parent f920c65eed
commit 68957d8802
5 changed files with 85 additions and 1 deletions
+3
View File
@@ -89,6 +89,9 @@ The process to update the server while DD is running is a functioning work in pr
* `RepoKey/`
* This contains ssh key information for automatic changelog pushing.
* `EventHandlers/`
* This contains batch files that run after certain events, currently only precompile and postcompile events are implemented.
* `BYOND/`
* This contains the actual BYOND installation the server uses
+14 -1
View File
@@ -378,6 +378,13 @@ namespace TGServerService
}
}
if (!PrecompileHook())
{
lastCompilerError = "The precompile hook failed";
compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid
return;
}
using (var DM = new Process()) //will kill the process if the thread is terminated
{
DM.StartInfo.FileName = ByondDirectory + "/bin/dm.exe";
@@ -468,7 +475,13 @@ namespace TGServerService
}
}
var staged = DaemonStatus() != TGDreamDaemonStatus.Offline;
var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round.");
if (!PostcompileHook())
{
lastCompilerError = "The postcompile hook failed";
compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid
return;
}
var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round.");
SendMessage("DM: " + msg, ChatMessageType.DeveloperInfo);
TGServerService.WriteInfo(msg, TGServerService.EventID.DMCompileSuccess);
lock (CompilerLock)
+65
View File
@@ -0,0 +1,65 @@
using System;
using System.Diagnostics;
using System.IO;
namespace TGServerService
{
// Some useful functions for triggering pre action events
partial class TGStationServer
{
const string EventFolder = "EventHandlers/";
string GetPath(string eventName)
{
return string.Format("{}{}.bat", EventFolder, eventName);
}
bool EventHandlerExists(string eventName)
{
return File.Exists(GetPath(eventName));
}
bool HandleEvent(string eventName)
{
if (!EventHandlerExists(eventName))
{
// We don't need a handler, so let's just fail silently.
return true;
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = GetPath(eventName),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
process.Start();
process.WaitForExit();
var stdout = process.StandardOutput.ReadToEnd();
var stderr = process.StandardError.ReadToEnd();
TGServerService.WriteInfo(
String.Format("Preaction Event ran. Stdout:\n{}\nStderr:\n{}", stdout, stderr),
process.ExitCode == 0 ? TGServerService.EventID.PreactionEvent : TGServerService.EventID.PreactionFail
);
return process.ExitCode == 0 ? true : false;
}
public bool PrecompileHook()
{
return HandleEvent("precompile");
}
public bool PostcompileHook()
{
return HandleEvent("postcompile");
}
}
}
+2
View File
@@ -75,6 +75,8 @@ namespace TGServerService
ServerUpdateApplied = 6300,
ChatBroadcastFail = 6400,
IRCLogModes = 6500,
PreactionEvent = 6600,
PreactionFail = 6700
}
static TGServerService ActiveService; //So everyone else can write to our eventlog
+1
View File
@@ -93,6 +93,7 @@
<Compile Include="InterfaceBase.cs" />
<Compile Include="IRC.cs" />
<Compile Include="Interop.cs" />
<Compile Include="PreactionHandler.cs" />
<Compile Include="ProcessExtension.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>