From 9a964bb7eca10f095247ee96fc0ee277bc8920f2 Mon Sep 17 00:00:00 2001 From: Sean Date: Sun, 7 Sep 2025 19:27:24 -0400 Subject: [PATCH] Add Reboot to IPMonitor --- IPMonitor/Services/MainService.cs | 56 ++++++++++++++++++--- MarketData/MarketDataLib/Utility/Utility.cs | 25 +++++++++ 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/IPMonitor/Services/MainService.cs b/IPMonitor/Services/MainService.cs index ca88d3e..459d563 100755 --- a/IPMonitor/Services/MainService.cs +++ b/IPMonitor/Services/MainService.cs @@ -51,6 +51,7 @@ namespace IPMonitor force=commandArgs.Coalesce("FORCE"); MDTrace.WriteLine(LogLevel.DEBUG,$"FORCE={force}"); } + VerifyNetwork(); String ipAddress=GetPublicIPAddress(); UpdateIPAddress(ipAddress,force); } @@ -84,6 +85,47 @@ namespace IPMonitor return true; } + /// + /// Verified that we are connected to the internet.00000000 + /// Tghe method will retry for 5 minutes and then issue a reboot + /// + public static void VerifyNetwork() + { + int MAX_RETRIES=10; + int TIMEOUT_BETWEEN_ATTEMPTS=30000; + bool isNetworkAvailable=false; + + try + { + for(int index=0;index /// Retains a record of current ip address in ipaddress.txt file and updates that ip address to ZoneEdit for DNS /// @@ -135,7 +177,7 @@ namespace IPMonitor } /// - /// Retrieves the public IP Address + /// Retrieves the public IP Address. /// /// public static String GetPublicIPAddress() @@ -150,12 +192,12 @@ namespace IPMonitor for(int index=0;index + /// Restarts the computer ARM64 + /// -r = restart the computer + /// + public static void Reboot() + { + string arguments = "-r now"; + string shutdownProcess = "shutdown"; + ProcessStartInfo processStartInfo = new ProcessStartInfo(shutdownProcess, arguments) + { + CreateNoWindow = true, + UseShellExecute = false + }; + try + { + MDTrace.WriteLine(LogLevel.DEBUG,$"Executing {shutdownProcess} {arguments}"); + Process.Start(processStartInfo); + } + catch (Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"An error was encountered executing the command: {shutdownProcess} {arguments}"); + MDTrace.WriteLine(LogLevel.DEBUG,$"{exception.ToString()}"); + } + } + public static String ThreadStateToString(Thread thread) { switch(thread.ThreadState)