using Inspectron.Epson; using Microsoft.AspNetCore.SignalR.Client; using Microsoft.Extensions.Logging; using Ninject; using System.Threading.Channels; using Inspectron.Epson.PrintServer; using Inspectron.Epson.PrintServer.ConfigurationSources; using Inspectron.Epson.PrintServer.JobSources; using Inspectron.Epson.PrintServer.PrinterAssinment; using Inspectron.Epson.PrintServer.Printers; using Inspectron.Epson.PrintServer.Printers.Utils; using Inspectron.Epson.PrintServer.PrintServices; using EpsonPrintService; using Inspectron.Epson.PrintServer.JobStatusReporters; using Inspectron.Epson.Queue; StandardKernel kernel = new StandardKernel(); var configPath = ConfigurationPaths.GetConfigPath(); Console.WriteLine($"Loading configuration from: {configPath}"); var base64Line = File.ReadAllText(configPath).Trim(); var decodedConfig = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(base64Line)); var configParts = decodedConfig.Split(';'); if (configParts.Length != 3) throw new InvalidOperationException($"Invalid configuration format. Expected 'apiUrl;restaurantId;apiKey', got {configParts.Length} parts."); var config = new EpsonPrintServiceConfiguration { ApiUrl = configParts[0], RestaurantId = configParts[1], ApiKey = configParts[2] }; Console.WriteLine($"Restaurant: {config.RestaurantId}"); Console.WriteLine($"API URL: {config.ApiUrl}"); kernel.Bind().To().InSingletonScope(); //var discovery = new PreconfiguredDiscoveryService(); //discovery.AddPrinter("192.168.50.176", "TM-T30III", port: 9100); //discovery.AddPrinter("192.168.50.60", "TM-T30III", port: 9100); //discovery.AddPrinter("192.168.50.61", "TM-T30III", port: 9100); //discovery.AddPrinter("192.168.50.80", "TM-U220II", port: 9100); //kernel.Bind().ToConstant(discovery); kernel.Bind().ToConstant(new HttpClient { Timeout = TimeSpan.FromSeconds(30) }).InSingletonScope(); kernel.Bind().ToConstant(config); //kernel.Bind().ToMethod(sp=>new HtmlPrinterFactory("TM-U220II.html", paperWidth: 258,type:0x0d, logger:sp.Kernel.Get())); //kernel.Bind().ToMethod(sp=>new HtmlPrinterFactory("TM-T30III.html",logger:sp.Kernel.Get())); kernel.Bind().To(); kernel.Bind().To().InSingletonScope(); kernel.Bind().To(); kernel.Bind().ToMethod(ctx => { var loggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); builder.SetMinimumLevel(LogLevel.Trace); }); return loggerFactory.CreateLogger("EpsonPrintService"); }); kernel.Bind().To().InSingletonScope(); kernel.Bind().To(); kernel.Bind().To().InSingletonScope(); kernel.Bind().To(); kernel.Bind().ToSelf().InSingletonScope(); kernel.Bind().To().InSingletonScope(); kernel.Bind().ToSelf().InSingletonScope(); kernel.Bind().ToSelf().InSingletonScope(); var printLoop = kernel.Get(); var printServer = kernel.Get(); var discoveryTask = kernel.Get(); var heartbeatTask = kernel.Get(); //printServer.RegisterPrinter("10.0.20.12"); var cts = new CancellationTokenSource(); Console.CancelKeyPress += (sender, e) => { Console.WriteLine("\nShutting down..."); e.Cancel = true; cts.Cancel(); }; // Start background tasks _ = discoveryTask.StartAsync(cts.Token); _ = heartbeatTask.StartAsync(cts.Token); // delay for a moment to allow discovery to find printers Console.WriteLine("Waiting for printer discovery..."); await Task.Delay(3000); await printLoop.StartAsync(); try { await Task.Delay(Timeout.Infinite, cts.Token); } catch (TaskCanceledException) { // Expected when Ctrl+C is pressed }