using Akka.Actor;
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Health;
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;
using ZB.MOM.WW.ScadaBridge.Host.Actors;
namespace ZB.MOM.WW.ScadaBridge.Host;
///
/// Sends SiteHealthReport to the local SiteCommunicationActor via Akka ActorSelection.
/// The SiteCommunicationActor forwards it to central.
///
public class AkkaHealthReportTransport : IHealthReportTransport
{
private readonly AkkaHostedService _akkaService;
///
/// Initializes a new backed by the given Akka hosted service.
///
/// The Akka hosted service used to access the running actor system.
public AkkaHealthReportTransport(AkkaHostedService akkaService)
{
_akkaService = akkaService;
}
///
public void Send(SiteHealthReport report)
{
var actorSystem = _akkaService.ActorSystem;
if (actorSystem == null) return;
var siteComm = actorSystem.ActorSelection("/user/site-communication");
siteComm.Tell(report, ActorRefs.NoSender);
}
}