From c27467badeb678697f9109c7beb6a1266e95a3cf Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 28 Nov 2018 16:52:01 -0500 Subject: [PATCH] Finish remaining stylecop issues --- .../Tgstation.Server.Client.csproj | 2 +- src/Tgstation.Server.Host.Console/Program.cs | 1 + .../GlobalSuppressions.cs | Bin 2588 -> 1284 bytes src/Tgstation.Server.Host.Service/Program.cs | 33 +++++++++-------- .../ServerService.cs | 3 +- .../Tgstation.Server.Host.Service.csproj | 3 +- .../Watchdog.cs | 34 +++++++++++------- 7 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj index db9df23a8e..b6bb7947ea 100644 --- a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj +++ b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj @@ -25,7 +25,7 @@ true - + D:\tgstation-server\src\Tgstation.Server.Client\Tgstation.Server.Client.xml 1701;1702 diff --git a/src/Tgstation.Server.Host.Console/Program.cs b/src/Tgstation.Server.Host.Console/Program.cs index 3e9b566774..9437569d9f 100644 --- a/src/Tgstation.Server.Host.Console/Program.cs +++ b/src/Tgstation.Server.Host.Console/Program.cs @@ -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(); diff --git a/src/Tgstation.Server.Host.Service/GlobalSuppressions.cs b/src/Tgstation.Server.Host.Service/GlobalSuppressions.cs index 47f7930b2a164fa8d872b6d46cf75d67298e52a5..dfc5c7f3e33f5b0271aaee89d88c7f717670f142 100644 GIT binary patch delta 95 zcmbOu(!w>NZ}K(PB6}SM1qLsMQifuN5{68MG$2l9NCdO<8S;Q~wm_`J;Kz^;q*H)o o9)mhiR*6BAA(nxcforliTl?fIY|l3DVV7Z?e2b%HasuZL02(BL*d92V`Pu@ z+p$MNHj3U7)-u|U?W4Rb75~%@h2x86-$Xp6X2$YNl!d&$)a*R&$?SoBu)B80{-*Ok z*BL6^0$i5%O=GJO?0q(NY$z^K->@j~`+9pY~8u8y9VVTJihoG0&v*zsN1 z!He%{uA{Bq*-^B9q8-_qI^GK7LaUWsD$2l~>8X}Ko>zVBY2|BF2RC*p9jxli?+R}- z-Tt4i-4?-~)Y9q)vyGJC?2g4vB^C>v(a#AdWCcvR%|uMqQNu9qRujFGE8T6OfA*ln zTIW5KUo5(Lv|s4`mDVfm_Zt}4Jv$br1F=-d0+eJ62>*4xlD*@|?o@g?Q+?T_jbm9P z%_klHzn9zA(brO&SK5Bvpo$Ll-xc$y__M9%O_#R^(jZmyO8Tr~cDM3~b*oxSmgY9m z6V*Le=6CAcwr%AFYxIGjdoERV$S8kbYS!z{iM)qj9VFc7Awf~7ZgWMTA`p|2-t@cP z5@J<%9AqTtD3!yWOJL#*tWXs>0VBPNn(Np+GIov{{ww>W)v5LkdJ#N-)5=ynD_MUo zugw}xujC*o38=SoLmu##3gH0dj4lg9k}gl`8FPSguwcfBQa^t)BXg|*t{ zS(X^?W9?96b` sealed class Program { +#pragma warning disable SA1401 // Fields should be private + /// + /// The for the + /// + internal static IWatchdogFactory WatchdogFactory = new WatchdogFactory(); +#pragma warning restore SA1401 // Fields should be private + /// /// The --uninstall or -u option /// @@ -50,8 +57,6 @@ namespace Tgstation.Server.Host.Service [Option(ShortName = "d")] public bool Debug { get; set; } - static readonly IWatchdogFactory watchdogFactory = new WatchdogFactory(); - /// /// Check if the running user is a system administrator /// @@ -63,9 +68,15 @@ namespace Tgstation.Server.Host.Service return principal.IsInRole(WindowsBuiltInRole.Administrator); } + /// + /// Entrypoint for the application + /// + static Task Main(string[] args) => CommandLineApplication.ExecuteAsync(args); + /// /// Command line handler, always runs /// + /// A representing the running operation 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(), default).ConfigureAwait(false); + await WatchdogFactory.CreateWatchdog(loggerFactory).RunAsync(true, Array.Empty(), 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)); } } - - /// - /// Entrypoint for the application - /// - static Task Main(string[] args) => CommandLineApplication.ExecuteAsync(args); } } diff --git a/src/Tgstation.Server.Host.Service/ServerService.cs b/src/Tgstation.Server.Host.Service/ServerService.cs index 0758c021a3..f92e3c3375 100644 --- a/src/Tgstation.Server.Host.Service/ServerService.cs +++ b/src/Tgstation.Server.Host.Service/ServerService.cs @@ -88,11 +88,12 @@ namespace Tgstation.Server.Host.Service EventLog.WriteEntry(String.Format(CultureInfo.InvariantCulture, "Error stopping service! Exception: {0}", e)); } } + StopServiceAsync(); } /// - [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(); diff --git a/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj b/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj index eb704ca548..cae21d786c 100644 --- a/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj +++ b/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj @@ -40,7 +40,7 @@ DEBUG;TRACE prompt - SA1652 + SA1101;SA1121;SA1200;SA1202;SA1208;SA1400;SA1413;SA1501;SA1503;SA1519;SA1520;SA1623;SA1629;SA1633;SA1642 pdbonly @@ -51,6 +51,7 @@ true bin\Release\Tgstation.Server.Host.Service.xml + SA1101;SA1121;SA1200;SA1202;SA1208;SA1400;SA1413;SA1501;SA1503;SA1519;SA1520;SA1623;SA1629;SA1633;SA1642 Tgstation.Server.Host.Service.Program diff --git a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs index 9dce48ac35..9fce44bfbf 100644 --- a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs @@ -15,7 +15,6 @@ namespace Tgstation.Server.Host.Watchdog /// sealed class Watchdog : IWatchdog { - /// /// The for the /// @@ -31,6 +30,7 @@ namespace Tgstation.Server.Host.Watchdog } /// + #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 { @@ -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(); 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 } }