using System.ComponentModel; using Titano.Server.Configuration; using Titano.Server.Hosting; using Titano.Server.Hosting.Windows; using Titano.Server.Storage; var command = ServerCommandLine.Parse(args); if (command.Error is not null) { await Console.Error.WriteLineAsync(command.Error); return 2; } switch (command.Command) { case ServerCommand.Help: Console.WriteLine(ServerCommandLine.Usage); return 0; case ServerCommand.HealthCheck: return await HealthProbe.RunAsync(); case ServerCommand.Service or ServerCommand.InstallService or ServerCommand.UninstallService when !OperatingSystem.IsWindows(): await Console.Error.WriteLineAsync("Windows services are available on Windows only."); return 2; case ServerCommand.InstallService when OperatingSystem.IsWindows(): return ServiceAction(ServiceInstaller.Install, $"Installed the {WindowsServiceHost.ServiceName} service."); case ServerCommand.UninstallService when OperatingSystem.IsWindows(): return ServiceAction(ServiceInstaller.Uninstall, $"Removed the {WindowsServiceHost.ServiceName} service."); case ServerCommand.Service when OperatingSystem.IsWindows(): if (WindowsServiceHost.Run(() => ServerHost.Build(ServerOptions.Load(), [.. command.HostArguments], RegisterModules))) return 0; await Console.Error.WriteLineAsync("--service is used by the Service Control Manager; start the service with 'sc start TitanoServer'."); return 1; default: var app = ServerHost.Build(ServerOptions.Load(), [.. command.HostArguments], RegisterModules); await app.RunAsync(); return 0; } // The archive engine, then analysis and managed rendering over it. static void RegisterModules(IServiceCollection services) { ArchiveModule.Register(services); ProcessingModule.Register(services); } static int ServiceAction(Action action, string done) { try { action(); Console.WriteLine(done); return 0; } catch (Win32Exception ex) { Console.Error.WriteLine(ex.Message); return 1; } } /// Entry point type, visible to the in-process test host. public partial class Program;