using Insight.Agent.Extensions; using Insight.Agent.Network; using Insight.Agent.Network.Handlers; using Insight.Agent.Services; using Insight.Domain.Constants; using Insight.Domain.Interfaces; using Insight.Domain.Network; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Vaitr.Network; using Vaitr.Network.Hosting; namespace Insight.Agent.Windows; internal class Program { public static async Task Main(string[] args) { var builder = Host.CreateDefaultBuilder(args); builder.UseWindowsService(); builder.UseSystemd(); builder.ConfigureAppConfiguration(config => { config.Defaults(); }); builder.ConfigureLogging(options => { options.ClearProviders(); options.SetMinimumLevel(LogLevel.Trace); options.AddSimpleConsole(options => { options.IncludeScopes = true; options.SingleLine = true; options.TimestampFormat = "yyyy-MM-dd HH:mm:ss.fff "; }); options.AddFile($"{Configuration.AppDirectory?.FullName}/" + "logs/agent_{Date}.log", LogLevel.Trace, fileSizeLimitBytes: 104857600, retainedFileCountLimit: 10, outputTemplate: "{Timestamp:o} [{Level:u3}] {Message} {NewLine}{Exception}"); }); builder.ConfigureServices((host, services) => { // HOST-SERVICES services.AddHostedService(); services.AddHostedService(); // SERVICES (WINDOWS) if (OperatingSystem.IsWindows()) services.AddHostedService(); if (OperatingSystem.IsWindows()) services.AddSingleton(); // AGENT NETWORKING services.UseHostedClient(options => { options.Host = host.Configuration.GetValue(Appsettings.ServerHost) ?? throw new Exception($"{Appsettings.ServerHost} value not set (appsettings)"); options.Port = host.Configuration.GetValue(Appsettings.ServerPort) ?? throw new Exception($"{Appsettings.ServerPort} value not set (appsettings)"); options.Keepalive = 10000; options.Timeout = 30000; options.Compression = true; options.Encryption = Encryption.Tls12; options.UseSerializer>(); }); services.AddSingleton, CustomHandler>(); services.AddSingleton, ProxyHandler>(); services.AddSingleton, AuthenticationHandler>(); services.AddSingleton, DriveHandler>(); services.AddSingleton, InterfaceHandler>(); services.AddSingleton, MainboardHandler>(); services.AddSingleton, MemoryHandler>(); services.AddSingleton, OperationSystemHandler>(); services.AddSingleton, PrinterHandler>(); services.AddSingleton, ProcessorHandler>(); services.AddSingleton, ServiceHandler>(); services.AddSingleton, SessionHandler>(); services.AddSingleton, SoftwareHandler>(); services.AddSingleton, StoragePoolHandler>(); services.AddSingleton, SystemInfoHandler>(); services.AddSingleton, UpdateHandler>(); services.AddSingleton, UserHandler>(); services.AddSingleton, VideocardHandler>(); services.AddSingleton, VirtualMaschineHandler>(); // GLOBAL DEPENDENCIES //services.AddSingleton(); services.AddTransient(provider => new HttpClient(new HttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual, ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true })); }); var host = builder.Build(); await host.RunAsync().ConfigureAwait(false); } }