Skip to content

Commit

Permalink
Removed debug console output entries. Moved ConfigLoader and Updater …
Browse files Browse the repository at this point in the history
…calls to BedrockServiceWrapper to avoid being called while passing commands to to TopShelf.
  • Loading branch information
crowbarmaster authored and crowbarmaster committed Dec 27, 2020
1 parent 08fecc9 commit e2c7ee2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions BedrockService/BedrockServerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ private void WCFThread()
{
try
{
Console.WriteLine("Starting WCF server");

wcfConsoleServer = new WCFConsoleServer(process, GetCurrentConsole, ServerConfig.WCFPortNumber);
_log.Debug("Before process.WaitForExit()");
Expand Down Expand Up @@ -196,7 +195,7 @@ private bool MonitoredAppExists(string monitoredAppName)
}
catch (Exception ex)
{
Debug.WriteLine("ApplicationWatcher MonitoredAppExists Exception: " + ex.StackTrace);
Console.WriteLine("ApplicationWatcher MonitoredAppExists Exception: " + ex.StackTrace);
return true;
}
}
Expand Down
14 changes: 9 additions & 5 deletions BedrockService/BedrockServiceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class BedrockServiceWrapper : ServiceControl

public BedrockServiceWrapper(bool throwOnStart, bool throwOnStop, bool throwUnhandled)
{
LoadInit();
try
{
string pattern = @"^Service_(.*)$";
Expand Down Expand Up @@ -71,7 +72,6 @@ public BedrockServiceWrapper(bool throwOnStart, bool throwOnStop, bool throwUnha
config.ShortName = TestMatch.Groups[1].Value;
}
bedrockServers.Add(new BedrockServerWrapper(config));
Console.WriteLine("Added config!");
}
}

Expand Down Expand Up @@ -211,7 +211,6 @@ public bool Start(HostControl hostControl)
brs.Stopping = false;
brs.StartControl(hostControl);
Thread.Sleep(2000);
Console.WriteLine($"AppName was: {brs.ServerConfig.BedrockServerExeName.Substring(0, brs.ServerConfig.BedrockServerExeName.Length - 4)}");
}
return true;
}
Expand Down Expand Up @@ -244,7 +243,6 @@ private void ValidSettingsCheck()
File.Delete(server.ServerConfig.BedrockServerExeLocation + server.ServerConfig.BedrockServerExeName);
}
File.Copy(server.ServerConfig.BedrockServerExeLocation + "bedrock_server.exe", server.ServerConfig.BedrockServerExeLocation + server.ServerConfig.BedrockServerExeName);
Console.WriteLine($@"Copied {server.ServerConfig.BedrockServerExeLocation + "bedrock_server.exe"} to {server.ServerConfig.BedrockServerExeLocation + server.ServerConfig.BedrockServerExeName}");
}
if (!File.Exists(server.ServerConfig.BedrockServerExeLocation + server.ServerConfig.BedrockServerExeName))
{
Expand Down Expand Up @@ -437,7 +435,7 @@ public string[] WriteJSONFiles(string ShortName)
}
sb.Remove(sb.Length - 2, 2);
sb.Append("\n]");
Console.WriteLine($"JSON Output was: {sb}");

output[0] = sb.ToString();
sb = new StringBuilder();
sb.Append("[\n");
Expand All @@ -450,9 +448,15 @@ public string[] WriteJSONFiles(string ShortName)
}
sb.Remove(sb.Length - 2, 2);
sb.Append("\n]");
Console.WriteLine($"JSON Output was: {sb}");

output[1] = sb.ToString();
return output;
}

private void LoadInit()
{
ConfigLoader.LoadConfigs();
Updater.CheckUpdates().Wait();
}
}
}
10 changes: 2 additions & 8 deletions BedrockService/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using log4net.Config;
using System;
using System.IO;
using System.Text;
using System.Threading;
using Topshelf;

namespace BedrockService
Expand All @@ -14,8 +11,6 @@ static void Main(string[] args)
{

XmlConfigurator.Configure();
ConfigLoader.LoadConfigs();
Updater.CheckUpdates().Wait();

var rc = HostFactory.Run(x =>
{
Expand All @@ -28,8 +23,8 @@ static void Main(string[] args)
bool throwUnhandled = false;
x.Service(settings => new BedrockServiceWrapper(throwOnStart, throwOnStop, throwUnhandled), s =>
{
s.BeforeStartingService(_ => Console.WriteLine("BeforeStart"));
s.BeforeStoppingService(_ => Console.WriteLine("BeforeStop"));
s.BeforeStartingService(_ => Console.WriteLine("Starting service..."));
s.BeforeStoppingService(_ => Console.WriteLine("Stopping service..."));

});

Expand All @@ -41,7 +36,6 @@ static void Main(string[] args)

x.EnableServiceRecovery(src =>
{
src.OnCrashOnly();
src.RestartService(delayInMinutes: 0);
src.RestartService(delayInMinutes: 1);
src.SetResetPeriod(days: 1);
Expand Down

0 comments on commit e2c7ee2

Please sign in to comment.