bind IInsinTelemetry in DI and emit service.started
This commit is contained in:
@@ -8,9 +8,11 @@ using Inspectron.Epson.PrintServer.PrinterAssinment;
|
|||||||
using Inspectron.Epson.PrintServer.Printers;
|
using Inspectron.Epson.PrintServer.Printers;
|
||||||
using Inspectron.Epson.PrintServer.Printers.Utils;
|
using Inspectron.Epson.PrintServer.Printers.Utils;
|
||||||
using Inspectron.Epson.PrintServer.PrintServices;
|
using Inspectron.Epson.PrintServer.PrintServices;
|
||||||
|
using Inspectron.Epson.PrintServer.Telemetry;
|
||||||
using Inspectron.Epson.Queue;
|
using Inspectron.Epson.Queue;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace EpsonPrintService;
|
namespace EpsonPrintService;
|
||||||
|
|
||||||
@@ -45,6 +47,10 @@ public class PrintServerBootstrapper
|
|||||||
_kernel = new StandardKernel();
|
_kernel = new StandardKernel();
|
||||||
|
|
||||||
_kernel.Bind<HttpClient>().ToConstant(new HttpClient { Timeout = TimeSpan.FromSeconds(30) }).InSingletonScope();
|
_kernel.Bind<HttpClient>().ToConstant(new HttpClient { Timeout = TimeSpan.FromSeconds(30) }).InSingletonScope();
|
||||||
|
if (_config.EmulationMode)
|
||||||
|
_kernel.Bind<IInsinTelemetry>().To<NullInsinTelemetry>().InSingletonScope();
|
||||||
|
else
|
||||||
|
_kernel.Bind<IInsinTelemetry>().To<LoopbackInsinTelemetry>().InSingletonScope();
|
||||||
_kernel.Bind<EpsonPrintServiceConfiguration>().ToConstant(_config);
|
_kernel.Bind<EpsonPrintServiceConfiguration>().ToConstant(_config);
|
||||||
|
|
||||||
if (_config.EmulationMode)
|
if (_config.EmulationMode)
|
||||||
@@ -97,7 +103,12 @@ public class PrintServerBootstrapper
|
|||||||
{
|
{
|
||||||
_kernel.Bind<PrintJobArrivedHandler>().ToConstant(handler);
|
_kernel.Bind<PrintJobArrivedHandler>().ToConstant(handler);
|
||||||
}
|
}
|
||||||
_kernel.Bind<IDiscoveredPrintersReceiver>().To<JamesDiscoveredPrintersReceiver>().InSingletonScope();
|
_kernel.Bind<JamesDiscoveredPrintersReceiver>().ToSelf().InSingletonScope();
|
||||||
|
_kernel.Bind<IDiscoveredPrintersReceiver>().ToMethod(ctx =>
|
||||||
|
new InsinTelemetryDiscoveredPrintersReceiver(
|
||||||
|
ctx.Kernel.Get<JamesDiscoveredPrintersReceiver>(),
|
||||||
|
ctx.Kernel.Get<IInsinTelemetry>()))
|
||||||
|
.InSingletonScope();
|
||||||
_kernel.Bind<PrinterDiscoveryBackgroundTask>().ToSelf().InSingletonScope();
|
_kernel.Bind<PrinterDiscoveryBackgroundTask>().ToSelf().InSingletonScope();
|
||||||
_kernel.Bind<HeartbeatBackgroundTask>().ToSelf().InSingletonScope();
|
_kernel.Bind<HeartbeatBackgroundTask>().ToSelf().InSingletonScope();
|
||||||
|
|
||||||
@@ -120,5 +131,15 @@ public class PrintServerBootstrapper
|
|||||||
|
|
||||||
IsRunning = true;
|
IsRunning = true;
|
||||||
Console.WriteLine("Print server started.");
|
Console.WriteLine("Print server started.");
|
||||||
|
|
||||||
|
var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
|
||||||
|
var telemetry = _kernel.Get<IInsinTelemetry>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
telemetry.Emit(InsinEventKinds.ServiceStarted, InsinMessageFormatter.Format(
|
||||||
|
("version", version),
|
||||||
|
("restaurantId", _config.RestaurantId)));
|
||||||
|
}
|
||||||
|
catch { /* telemetry must never fail startup */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user