64 lines
2.7 KiB
C#
64 lines
2.7 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Phares.Shared;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using View_by_Distance.Move.By.Id.Models;
|
|
using View_by_Distance.Shared.Models.Stateless.Methods;
|
|
|
|
namespace View_by_Distance.Move.By.Id;
|
|
|
|
public class Program
|
|
{
|
|
|
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
|
{
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
|
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
|
.AddEnvironmentVariables()
|
|
.AddUserSecrets<Program>();
|
|
IConfigurationRoot configurationRoot = configurationBuilder.Build();
|
|
AppSettings appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
|
if (appSettings.MaxDegreeOfParallelism > Environment.ProcessorCount)
|
|
throw new Exception("MaxDegreeOfParallelism must be =< Environment.ProcessorCount!");
|
|
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
|
throw new Exception("Working directory name must have a value!");
|
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
|
int silentIndex = args.IndexOf("s");
|
|
if (silentIndex > -1)
|
|
args.RemoveAt(silentIndex);
|
|
try
|
|
{
|
|
if (args is null)
|
|
throw new Exception("args is null!");
|
|
Shared.Models.Console console = new();
|
|
_ = new MoveById(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.LogError(ex, "Error!");
|
|
}
|
|
if (silentIndex > -1)
|
|
logger?.LogDebug("Done. Bye");
|
|
else
|
|
{
|
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
|
_ = Console.ReadLine();
|
|
}
|
|
}
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
|
if (args is not null)
|
|
Secondary(logger, args.ToList());
|
|
else
|
|
Secondary(logger, new List<string>());
|
|
}
|
|
|
|
} |