From f59bc5e0a85d9cb015f75ad0fd4a7b621a8e6baf Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 17 Apr 2025 19:11:44 -0400 Subject: [PATCH] Translate returns a success/error code --- Translate/Translate/Executor.cs | 5 +++-- Translate/Translate/Interface/IMainService.cs | 2 +- Translate/Translate/Program.cs | 4 ++-- Translate/Translate/Services/MainService.cs | 14 ++++++++------ Translate/translate.sh | 9 +++++++-- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Translate/Translate/Executor.cs b/Translate/Translate/Executor.cs index fa53ab0..37282a7 100644 --- a/Translate/Translate/Executor.cs +++ b/Translate/Translate/Executor.cs @@ -19,8 +19,9 @@ namespace Translate /// /// This is essentially the starting point where we bootstrap the legacy entry point /// - public void Execute() - { _mainService.RunService(_commandArgs.GetArgs(), _configuration); + public int Execute() + { + return _mainService.RunService(_commandArgs.GetArgs(), _configuration); } } } diff --git a/Translate/Translate/Interface/IMainService.cs b/Translate/Translate/Interface/IMainService.cs index a54e1c3..e9e3a37 100644 --- a/Translate/Translate/Interface/IMainService.cs +++ b/Translate/Translate/Interface/IMainService.cs @@ -4,6 +4,6 @@ namespace Translate.Interface { public interface IMainService { - public void RunService(String[] args,IConfiguration configuration); + public int RunService(String[] args,IConfiguration configuration); } } \ No newline at end of file diff --git a/Translate/Translate/Program.cs b/Translate/Translate/Program.cs index a4c86c4..ad5af5f 100644 --- a/Translate/Translate/Program.cs +++ b/Translate/Translate/Program.cs @@ -7,7 +7,7 @@ namespace Translate { class Program { - static void Main(string[] args) + static int Main(string[] args) { IConfigurationBuilder builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); @@ -18,7 +18,7 @@ namespace Translate services.AddSingleton(configurationRoot); services.AddSingleton(); services.AddSingleton(); - services.BuildServiceProvider().GetService().Execute(); + return services.BuildServiceProvider().GetService().Execute(); } } diff --git a/Translate/Translate/Services/MainService.cs b/Translate/Translate/Services/MainService.cs index f5bab9d..114c125 100644 --- a/Translate/Translate/Services/MainService.cs +++ b/Translate/Translate/Services/MainService.cs @@ -14,17 +14,18 @@ namespace Translate.Services /// public class MainService : IMainService { - public void RunService(String[] args,IConfiguration configuration) + public int RunService(String[] args,IConfiguration configuration) { Profiler profiler = new Profiler(); try { - Translate(args, configuration); + return Translate(args, configuration); } catch(Exception exception) { Console.WriteLine($"{exception.ToString()}"); + return 1; } finally { @@ -32,7 +33,7 @@ namespace Translate.Services } } - private void Translate(String[] args,IConfiguration configuration) + private int Translate(String[] args,IConfiguration configuration) { bool includeInserts = true; bool useMaxLines = false; @@ -45,14 +46,14 @@ namespace Translate.Services if(2!=args.Length) { Console.WriteLine("Incorrect number of arguments. ./translate input_file output_file"); - return; + return 1; } Console.WriteLine($"Replacing {strTargetItem} with {strReplacementItem}"); Console.WriteLine("Input: {0}, Output:{1}, correct Y/N?",args[0],args[1]); String response = Console.ReadLine(); - if(!"YES".Equals(response,StringComparison.InvariantCultureIgnoreCase))return; + if(!"YES".Equals(response,StringComparison.InvariantCultureIgnoreCase))return 1; String pathInput = args[0]; String pathOutput=args[1]; @@ -61,7 +62,7 @@ namespace Translate.Services if(!File.Exists(pathInput)) { Console.WriteLine("Input file not found."); - return; + return 1; } if(File.Exists(pathOutput)) @@ -148,6 +149,7 @@ namespace Translate.Services streamWriter.Flush(); streamWriter.Close(); streamWriter.Dispose(); + return 0; } } } \ No newline at end of file diff --git a/Translate/translate.sh b/Translate/translate.sh index fefc2ca..699a15d 100755 --- a/Translate/translate.sh +++ b/Translate/translate.sh @@ -2,6 +2,11 @@ #date "+%Y-%m-%d %H:%M:%S" cd /home/pi/ARM64/Translate/Translate/bin/Debug/net8.0 ./translate /mnt/mariadb/backupdb.sql /mnt/mariadb/backupdb2.sql -cd /mnt/mariadb -./restoredb.sh +exit_code=$? +if [ $exit_code -eq 0 ]; then + cd /mnt/mariadb + ./restoredb.sh +else + echo "translate.sh returned failure: $exit_code" +fi #date "+%Y-%m-%d %H:%M:%S"