Add project files.
This commit is contained in:
66
EpsonPrintService/Program.cs
Normal file
66
EpsonPrintService/Program.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
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;
|
||||
|
||||
StandardKernel kernel = new StandardKernel();
|
||||
|
||||
//var config = new EpsonPrintServiceConfiguration()
|
||||
//{
|
||||
// GroupId = "67e534f8e86e816689323023",
|
||||
// RestaurantId = "63e37295bd6f26dbd36164c0"
|
||||
//};
|
||||
//File.WriteAllText("config.json",JsonSerializer.Serialize(config,new JsonSerializerOptions(){WriteIndented = true}));
|
||||
var config = JsonSerializer.Deserialize<EpsonPrintServiceConfiguration>(
|
||||
File.ReadAllText("config.json"));
|
||||
kernel.Bind<EpsonPrintServiceConfiguration>().ToConstant(config);
|
||||
|
||||
kernel.Bind<IPrintJobSource, SignalRPrintJobSource>().To<SignalRPrintJobSource>().InSingletonScope();
|
||||
kernel.Bind<IPrintService>().To<Inspectron.Epson.PrintServer.PrintServices.EpsonPrintService>();
|
||||
kernel.Bind<ILogger>().ToMethod(ctx =>
|
||||
{
|
||||
var loggerFactory = LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder.AddConsole();
|
||||
});
|
||||
return loggerFactory.CreateLogger("EpsonPrintService");
|
||||
});
|
||||
kernel.Bind<IAssignedPrinterRepository>().ToConstant(config);
|
||||
kernel.Bind<IPrinterFactory>().To<PrinterFactory>().InSingletonScope();
|
||||
kernel.Bind<IPrinterConfigurationSource>().To<FixedConfigurationSource>();
|
||||
kernel.Bind<PrintServer>().ToSelf().InSingletonScope();
|
||||
var printLoop = kernel.Get<PrintLoop>();
|
||||
var printServer = kernel.Get<PrintServer>();
|
||||
|
||||
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();
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(Timeout.Infinite, cts.Token);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
// Expected when Ctrl+C is pressed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user