Finish remaining stylecop issues

This commit is contained in:
Jordan Brown
2018-11-28 16:52:01 -05:00
parent 846f143f5d
commit c27467bade
7 changed files with 46 additions and 30 deletions
@@ -25,7 +25,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<DocumentationFile></DocumentationFile>
<DocumentationFile>D:\tgstation-server\src\Tgstation.Server.Client\Tgstation.Server.Client.xml</DocumentationFile>
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>
@@ -37,6 +37,7 @@ namespace Tgstation.Server.Host.Console
loggerFactory.CreateLogger(nameof(Program)).LogCritical("Please specify only 1 of --trace-host-watchdog or --debug-host-watchdog!");
return;
}
using (var cts = new CancellationTokenSource())
{
void AppDomainHandler(object a, EventArgs b) => cts.Cancel();
+19 -14
View File
@@ -20,6 +20,13 @@ namespace Tgstation.Server.Host.Service
/// </summary>
sealed class Program
{
#pragma warning disable SA1401 // Fields should be private
/// <summary>
/// The <see cref="IWatchdogFactory"/> for the <see cref="Program"/>
/// </summary>
internal static IWatchdogFactory WatchdogFactory = new WatchdogFactory();
#pragma warning restore SA1401 // Fields should be private
/// <summary>
/// The --uninstall or -u option
/// </summary>
@@ -50,8 +57,6 @@ namespace Tgstation.Server.Host.Service
[Option(ShortName = "d")]
public bool Debug { get; set; }
static readonly IWatchdogFactory watchdogFactory = new WatchdogFactory();
/// <summary>
/// Check if the running user is a system administrator
/// </summary>
@@ -63,9 +68,15 @@ namespace Tgstation.Server.Host.Service
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
/// <summary>
/// Entrypoint for the application
/// </summary>
static Task<int> Main(string[] args) => CommandLineApplication.ExecuteAsync<Program>(args);
/// <summary>
/// Command line handler, always runs
/// </summary>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
public async Task OnExecuteAsync()
{
if (Environment.UserInteractive)
@@ -81,8 +92,8 @@ namespace Tgstation.Server.Host.Service
if (!IsAdministrator())
{
//try to restart as admin
//its windows, first arg is .exe name guaranteed
// try to restart as admin
// its windows, first arg is .exe name guaranteed
var exe = Environment.GetCommandLineArgs().First();
var startInfo = new ProcessStartInfo
{
@@ -100,13 +111,12 @@ namespace Tgstation.Server.Host.Service
using (var loggerFactory = new LoggerFactory())
{
if (Configure)
await watchdogFactory.CreateWatchdog(loggerFactory).RunAsync(true, Array.Empty<string>(), default).ConfigureAwait(false);
await WatchdogFactory.CreateWatchdog(loggerFactory).RunAsync(true, Array.Empty<string>(), default).ConfigureAwait(false);
if (Install)
{
if (Uninstall)
//oh no, it's retarded...
return;
return; // oh no, it's retarded...
using (var processInstaller = new ServiceProcessInstaller())
using (var installer = new ServiceInstaller())
{
@@ -132,14 +142,9 @@ namespace Tgstation.Server.Host.Service
installer.ServiceName = ServerService.Name;
installer.Uninstall(null);
}
else if(!Configure)
ServiceBase.Run(new ServerService(watchdogFactory, loggerFactory, Trace ? LogLevel.Trace : Debug ? LogLevel.Debug : LogLevel.Information));
else if (!Configure)
ServiceBase.Run(new ServerService(WatchdogFactory, loggerFactory, Trace ? LogLevel.Trace : Debug ? LogLevel.Debug : LogLevel.Information));
}
}
/// <summary>
/// Entrypoint for the application
/// </summary>
static Task<int> Main(string[] args) => CommandLineApplication.ExecuteAsync<Program>(args);
}
}
@@ -88,11 +88,12 @@ namespace Tgstation.Server.Host.Service
EventLog.WriteEntry(String.Format(CultureInfo.InvariantCulture, "Error stopping service! Exception: {0}", e));
}
}
StopServiceAsync();
}
/// <inheritdoc />
[SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "cancellationTokenSource")]
[SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "cancellationTokenSource", Justification = "IT'S DISPOSED RIGHT THERE YOU FUCCBOI!")]
protected override void Dispose(bool disposing)
{
cancellationTokenSource?.Dispose();
@@ -40,7 +40,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet />
<NoWarn>SA1652</NoWarn>
<NoWarn>SA1101;SA1121;SA1200;SA1202;SA1208;SA1400;SA1413;SA1501;SA1503;SA1519;SA1520;SA1623;SA1629;SA1633;SA1642</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -51,6 +51,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Release\Tgstation.Server.Host.Service.xml</DocumentationFile>
<CodeAnalysisRuleSet />
<NoWarn>SA1101;SA1121;SA1200;SA1202;SA1208;SA1400;SA1413;SA1501;SA1503;SA1519;SA1520;SA1623;SA1629;SA1633;SA1642</NoWarn>
</PropertyGroup>
<PropertyGroup>
<StartupObject>Tgstation.Server.Host.Service.Program</StartupObject>
+21 -13
View File
@@ -15,7 +15,6 @@ namespace Tgstation.Server.Host.Watchdog
/// <inheritdoc />
sealed class Watchdog : IWatchdog
{
/// <summary>
/// The <see cref="ILogger"/> for the <see cref="Watchdog"/>
/// </summary>
@@ -31,6 +30,7 @@ namespace Tgstation.Server.Host.Watchdog
}
/// <inheritdoc />
#pragma warning disable CA1502 // TODO: Decomplexify
public async Task RunAsync(bool runConfigure, string[] args, CancellationToken cancellationToken)
{
logger.LogInformation("Host watchdog starting...");
@@ -67,17 +67,18 @@ namespace Tgstation.Server.Host.Watchdog
logger.LogCritical("Unable to locate dotnet executable in PATH! Please ensure the .NET Core runtime is installed and is in your PATH!");
return;
}
logger.LogInformation("Detected dotnet executable at {0}", dotnetPath);
var rootLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var assemblyStoragePath = Path.Combine(rootLocation, "lib"); //always always next to watchdog
var assemblyStoragePath = Path.Combine(rootLocation, "lib"); // always always next to watchdog
#if DEBUG
Directory.CreateDirectory(assemblyStoragePath);
#endif
var defaultAssemblyPath = Path.GetFullPath(Path.Combine(assemblyStoragePath, "Default"));
#if DEBUG
//just copy the shit where it belongs
// just copy the shit where it belongs
Directory.Delete(assemblyStoragePath, true);
Directory.CreateDirectory(defaultAssemblyPath);
@@ -117,7 +118,7 @@ namespace Tgstation.Server.Host.Watchdog
using (var process = new Process())
{
process.StartInfo.FileName = dotnetPath;
process.StartInfo.WorkingDirectory = rootLocation; //for appsettings
process.StartInfo.WorkingDirectory = rootLocation; // for appsettings
var arguments = new List<string>
{
@@ -138,7 +139,7 @@ namespace Tgstation.Server.Host.Watchdog
process.StartInfo.Arguments = String.Join(" ", arguments);
process.StartInfo.UseShellExecute = false; //runs in the same console
process.StartInfo.UseShellExecute = false; // runs in the same console
var tcs = new TaskCompletionSource<object>();
process.Exited += (a, b) =>
@@ -172,7 +173,7 @@ namespace Tgstation.Server.Host.Watchdog
{
processCts.CancelAfter(TimeSpan.FromSeconds(10));
}
catch (ObjectDisposedException) { } //race conditions
catch (ObjectDisposedException) { } // race conditions
}))
await tcs.Task.ConfigureAwait(false);
}
@@ -204,13 +205,12 @@ namespace Tgstation.Server.Host.Watchdog
return;
case 1:
if (!cancellationToken.IsCancellationRequested)
//just a restart
logger.LogInformation("Watchdog will restart host...");
logger.LogInformation("Watchdog will restart host..."); // just a restart
else
logger.LogWarning("Host requested restart but watchdog shutdown is in progress!");
break;
case 2:
//update path is now an exception document
// update path is now an exception document
logger.LogCritical("Host crashed, propagating exception dump...");
var data = File.ReadAllText(updateDirectory);
try
@@ -221,29 +221,36 @@ namespace Tgstation.Server.Host.Watchdog
{
logger.LogWarning("Unable to delete exception dump file at {0}! Exception: {1}", updateDirectory, e);
}
#pragma warning disable CA2201 // Do not raise reserved exception types
throw new Exception(String.Format(CultureInfo.InvariantCulture, "Host propagated exception: {0}", data));
#pragma warning restore CA2201 // Do not raise reserved exception types
default:
if (killedHostProcess)
{
logger.LogWarning("Watchdog forced to kill host process!");
cancellationToken.ThrowIfCancellationRequested();
}
#pragma warning disable CA2201 // Do not raise reserved exception types
throw new Exception(String.Format(CultureInfo.InvariantCulture, "Host crashed with exit code {0}!", process.ExitCode));
#pragma warning restore CA2201 // Do not raise reserved exception types
}
}
//HEY YOU
//BE WARNED THAT IF YOU DEBUGGED THE HOST PROCESS THAT JUST LAUNCHED THE DEBUGGER WILL HOLD A LOCK ON THE DIRECTORY
//THIS MEANS THE FIRST DIRECTORY.MOVE WILL THROW
// HEY YOU
// BE WARNED THAT IF YOU DEBUGGED THE HOST PROCESS THAT JUST LAUNCHED THE DEBUGGER WILL HOLD A LOCK ON THE DIRECTORY
// THIS MEANS THE FIRST DIRECTORY.MOVE WILL THROW
if (Directory.Exists(updateDirectory))
{
logger.LogInformation("Applying server update...");
if (isWindows)
{
//windows dick sucking resource unlocking
// windows dick sucking resource unlocking
GC.Collect(Int32.MaxValue, GCCollectionMode.Default, true);
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken).ConfigureAwait(false);
}
var tempPath = Path.Combine(assemblyStoragePath, Guid.NewGuid().ToString());
try
{
@@ -293,5 +300,6 @@ namespace Tgstation.Server.Host.Watchdog
logger.LogInformation("Host watchdog exiting...");
}
}
#pragma warning restore CA1502
}
}