add print-job-arrived hook system
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Inspectron.Epson;
|
||||
using Inspectron.Epson.PrintServer;
|
||||
using Inspectron.Epson.PrintServer.ConfigurationSources;
|
||||
using Inspectron.Epson.PrintServer.Hooks;
|
||||
using Inspectron.Epson.PrintServer.JobSources;
|
||||
using Inspectron.Epson.PrintServer.JobStatusReporters;
|
||||
using Inspectron.Epson.PrintServer.PrinterAssinment;
|
||||
@@ -17,6 +18,7 @@ public class PrintServerBootstrapper
|
||||
{
|
||||
private readonly EpsonPrintServiceConfiguration _config;
|
||||
private readonly CancellationTokenSource _cts;
|
||||
private readonly List<PrintJobArrivedHandler> _arrivedHandlers = new();
|
||||
private StandardKernel? _kernel;
|
||||
|
||||
public bool IsRunning { get; private set; }
|
||||
@@ -27,6 +29,17 @@ public class PrintServerBootstrapper
|
||||
_cts = cts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a handler that fires once per print job as it arrives from the job source,
|
||||
/// before it's enqueued on the printer queue. Register all handlers before calling <see cref="StartAsync"/>.
|
||||
/// Handler exceptions are logged and swallowed; they never block a print.
|
||||
/// </summary>
|
||||
public void OnPrintJobArrived(PrintJobArrivedHandler handler)
|
||||
{
|
||||
if (IsRunning) throw new InvalidOperationException("Register hooks before StartAsync().");
|
||||
_arrivedHandlers.Add(handler);
|
||||
}
|
||||
|
||||
public async Task StartAsync()
|
||||
{
|
||||
_kernel = new StandardKernel();
|
||||
@@ -80,6 +93,10 @@ public class PrintServerBootstrapper
|
||||
_kernel.Bind<IReceiptConverterFactory>().To<ReceiptConverterFactory>().InSingletonScope();
|
||||
_kernel.Bind<IJobStatusReporter>().To<JamesStatusReporter>();
|
||||
_kernel.Bind<PrintServer>().ToSelf().InSingletonScope();
|
||||
foreach (var handler in _arrivedHandlers)
|
||||
{
|
||||
_kernel.Bind<PrintJobArrivedHandler>().ToConstant(handler);
|
||||
}
|
||||
_kernel.Bind<IDiscoveredPrintersReceiver>().To<JamesDiscoveredPrintersReceiver>().InSingletonScope();
|
||||
_kernel.Bind<PrinterDiscoveryBackgroundTask>().ToSelf().InSingletonScope();
|
||||
_kernel.Bind<HeartbeatBackgroundTask>().ToSelf().InSingletonScope();
|
||||
|
||||
Reference in New Issue
Block a user