using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Transport;
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager;
///
/// backed by the deployment flattening pipeline.
/// Re-flattens an instance through and returns
/// the computed revision hash — the exact same value
/// DeploymentService.GetDeploymentComparisonAsync compares against the
/// deployed snapshot to decide staleness. Hosted in DeploymentManager so the
/// Transport component (which references only Commons + TemplateEngine) can probe
/// staleness without taking a DeploymentManager project reference.
///
public sealed class StaleInstanceProbe : IStaleInstanceProbe
{
private readonly IFlatteningPipeline _flatteningPipeline;
/// Initializes a new .
/// The deployment flattening pipeline used to recompute the current revision hash.
public StaleInstanceProbe(IFlatteningPipeline flatteningPipeline)
{
_flatteningPipeline = flatteningPipeline ?? throw new ArgumentNullException(nameof(flatteningPipeline));
}
///
public async Task GetCurrentRevisionHashAsync(int instanceId, CancellationToken cancellationToken = default)
{
// The pipeline returns a Result; a flatten failure (e.g. unresolvable
// template chain mid-import) yields null so the caller treats the
// instance as "staleness indeterminate" and skips it. Flattening reuses
// the scoped ITemplateEngineRepository, so it observes template rows the
// in-flight import has staged on the shared change tracker.
var result = await _flatteningPipeline
.FlattenAndValidateAsync(instanceId, cancellationToken)
.ConfigureAwait(false);
return result.IsSuccess ? result.Value.RevisionHash : null;
}
}