Translate returns a success/error code
This commit is contained in:
@@ -19,8 +19,9 @@ namespace Translate
|
||||
/// <summary>
|
||||
/// This is essentially the starting point where we bootstrap the legacy entry point
|
||||
/// </summary>
|
||||
public void Execute()
|
||||
{ _mainService.RunService(_commandArgs.GetArgs(), _configuration);
|
||||
public int Execute()
|
||||
{
|
||||
return _mainService.RunService(_commandArgs.GetArgs(), _configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ namespace Translate.Interface
|
||||
{
|
||||
public interface IMainService
|
||||
{
|
||||
public void RunService(String[] args,IConfiguration configuration);
|
||||
public int RunService(String[] args,IConfiguration configuration);
|
||||
}
|
||||
}
|
||||
@@ -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<IConfigurationRoot>(configurationRoot);
|
||||
services.AddSingleton<IMainService,MainService>();
|
||||
services.AddSingleton<Executor,Executor>();
|
||||
services.BuildServiceProvider().GetService<Executor>().Execute();
|
||||
return services.BuildServiceProvider().GetService<Executor>().Execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,17 +14,18 @@ namespace Translate.Services
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user