From 16b7f5a0e260a1463cd1a7f80b092e72613460c3 Mon Sep 17 00:00:00 2001 From: radioActive DROID Date: Wed, 26 Jan 2022 07:14:38 +0100 Subject: [PATCH] Trigger shutdown after multiple serial restart --- .../Handlers/ReaderProcess.cs | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/Frequency.Device/Handlers/ReaderProcess.cs b/src/Frequency.Device/Handlers/ReaderProcess.cs index 42ce4c1..2fee6eb 100644 --- a/src/Frequency.Device/Handlers/ReaderProcess.cs +++ b/src/Frequency.Device/Handlers/ReaderProcess.cs @@ -31,7 +31,6 @@ using Microsoft.Extensions.Logging; using Proton.Frequency.Device.Handlers.ReaderConnections; using Proton.Frequency.Device.Helpers; -using Proton.Frequency.Device.Protocols.Readers; using Proton.Frequency.Device.Protocols; namespace Proton.Frequency.Device.Handlers @@ -219,20 +218,56 @@ void OnDevTest(Object source, System.Timers.ElapsedEventArgs e) else if (!DevMode && !_serialProfile.IsOpen) { int maxRetries = _config.IOT_SERIAL_CONN_RETRY; - while (maxRetries > 0) + while (maxRetries > 1) { maxRetries--; serialOpen(); + await Task.Delay(2000); } - } - } - public void NetworkConnection() - { } + /** + String processDirectory = System.AppContext.BaseDirectory; + String processPath = System.Reflection.Assembly.GetEntryAssembly().GetName().Name; + String path = Path.Combine(processDirectory, processPath); + if (Path.IsPathFullyQualified(path)) + { + String escapedArgs = path.Replace("\"", "\\\""); + String _filename = null; + String _arguments = null; + if (System.OperatingSystem.IsWindows()) + { + _filename = "cmd.exe"; + _arguments = $"/c \"{escapedArgs}\""; + } + else + { + _filename = "/bin/bash"; + _arguments = $"-c \"{escapedArgs}\""; + } - public async Task Run() - { - await Task.CompletedTask; + var process = new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = _filename, + Arguments = _arguments, + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + + _logger.LogWarning("Restarting application..."); + process.Start(); + process.WaitForExit(); + } + */ + + _logger.LogWarning("Shutting daemon process..."); + /** System.Diagnostics.Process.Start(path); **/ + Environment.Exit(0); + + } } }