using Inspectron.Epson; using Microsoft.AspNetCore.SignalR.Client; using Microsoft.Extensions.Logging; using Ninject; using System.Text.Json; using System.Text.Json.Serialization; 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; StandardKernel kernel = new StandardKernel(); var configPath = ConfigurationPaths.GetConfigPath(); Console.WriteLine($"Loading configuration from: {configPath}"); var config = JsonSerializer.Deserialize( File.ReadAllText(configPath)); kernel.Bind().To().InSingletonScope(); 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().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"); await printLoop.StartAsync(); 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); try { await Task.Delay(Timeout.Infinite, cts.Token); } catch (TaskCanceledException) { // Expected when Ctrl+C is pressed }