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.PrintServices; using EpsonPrintService; StandardKernel kernel = new StandardKernel(); var config = JsonSerializer.Deserialize( File.ReadAllText("config.json")); kernel.Bind().To().InSingletonScope(); kernel.Bind().ToConstant(config); kernel.Bind().To().InSingletonScope(); kernel.Bind().To(); kernel.Bind().ToMethod(ctx => { var loggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); }); return loggerFactory.CreateLogger("EpsonPrintService"); }); kernel.Bind().ToConstant(config); kernel.Bind().To().InSingletonScope(); kernel.Bind().To(); kernel.Bind().ToSelf().InSingletonScope(); kernel.Bind().To().InSingletonScope(); kernel.Bind().ToSelf().InSingletonScope(); var printLoop = kernel.Get(); var printServer = kernel.Get(); var discoveryTask = kernel.Get(); printServer.RegisterPrinter("127.0.0.1"); await printLoop.StartAsync(); var cts = new CancellationTokenSource(); Console.CancelKeyPress += (sender, e) => { Console.WriteLine("\nShutting down..."); e.Cancel = true; cts.Cancel(); }; // Start the printer discovery background task _ = discoveryTask.StartAsync(cts.Token); try { await Task.Delay(Timeout.Infinite, cts.Token); } catch (TaskCanceledException) { // Expected when Ctrl+C is pressed }