Files
amkovkov 72ae26eee7 comprehensive update
1) remove unused components: camera view (due it causes segmentation faults), compute resources and all related, illuminator controller (due in useless without camera view), image storage service, temperature and humidity service
2) database schema - reduce tables references, features storing in records themselves in compressed form, add records creation and editing date and time, add separator comment column
3) analysis - rework of pipeline and ui, now database storing only raw data and all display values calculated from it
4) lights service - add reconnection if disconnected
5) add width and height command line arguments
6) fix some typos and other issues
2026-06-29 15:13:29 +03:00

104 lines
3.7 KiB
C#

namespace GSS2;
public partial class Program
{
// Аргументы командной строки
private static List<string> _args = new List<string>();
public static string[] Args => _args.ToArray();
/// <summary>
/// Точка входа
/// </summary>
[STAThread]
public static int Main(string[] args)
{
_args = args.ToList();
#if DEBUG
WaitDebuggerIfNeeded();
#endif
// Создаём обработчик аргументов командной строки
var rootCommand = Commands.UI.GetCommand();
Commands.CameraTuning.RegisterCommand(rootCommand);
Commands.Capture.RegisterCommand(rootCommand);
// Обрабатываем аргументы
var parseResult = rootCommand?.Parse(_args);
// Обрабатываем ошибки
if (parseResult is null)
{
Console.Error.WriteLine("Неизвестная ошибка при обработке аргументов командной строки.");
Environment.Exit(1);
}
if (parseResult.Errors.Count() != 0)
{
Console.Error.WriteLine(
(parseResult.Errors.Count() == 1 ? "Ошибка" : "Ошибки") +
" при обработке аргументов командной строки:"
);
foreach (var parseError in parseResult.Errors)
Console.Error.WriteLine(parseError.Message);
Environment.Exit(1);
}
// Исполняем команду
Console.WriteLine("Нажмите Ctrl+C для выхода.");
try
{
return parseResult.Invoke();
}
catch (Exception ex)
{
Console.Error.WriteLine("Ошибка при выполнении программы:");
Console.Error.WriteLine(ex.Message);
if (ex.InnerException is not null)
Console.Error.WriteLine($"Внутреннее исключение: {ex.InnerException}");
Console.Error.WriteLine(ex.StackTrace);
Environment.Exit(1);
return 1;
}
}
/// <summary>
/// Если в <see cref="_args"/> присутствует аргумент <i>--debug</i>,
/// то удаляет <i>--debug</i> из <see cref="_args"/>, выводит информацию о процессе в консоль и ожидает подключения отладчика
/// </summary>
private static void WaitDebuggerIfNeeded()
{
if (System.Diagnostics.Debugger.IsAttached)
return;
if (!_args.Contains("--debug"))
return;
_args.Remove("--debug");
bool keepWaiting = true;
void CancelWait(object? _, ConsoleCancelEventArgs ea)
{
ea.Cancel = true;
keepWaiting = false;
Console.WriteLine("\nОперация отменена пользователем.");
Environment.Exit(0);
}
Console.CancelKeyPress += CancelWait;
Console.WriteLine("Ожидание подключения отладчика.");
Console.WriteLine($"Имя процесса: {Environment.ProcessPath}");
Console.WriteLine($"Id процесса: {Environment.ProcessId}");
Console.WriteLine($"Id потока: {Environment.CurrentManagedThreadId}");
Console.WriteLine("Нажмите Ctrl+C для выхода.");
while (!System.Diagnostics.Debugger.IsAttached && keepWaiting)
Thread.Sleep(100);
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
Console.CancelKeyPress -= CancelWait;
}
}