Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/Notifier.cs
T
Joseph Doherty 5a878b78d4 docs(xml): fill missing XML doc comments + strip task-tracking refs across src (fixdocs)
Add missing <summary>/<param>/<returns>/<typeparam> tags and switch
interface implementations to <inheritdoc/> across 106 files; strip
project bookkeeping identifiers (Task NN, #05-TNN, PLAN-04, StoreAndForward-0NN)
from shipped code comments while preserving the descriptive rationale.
Comment-only: zero code-logic lines changed; solution builds 0/0.

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
2026-07-10 08:23:56 -04:00

58 lines
2.5 KiB
C#

namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier;
/// <summary>Final outcome of the notify operation, mapped 1:1 to the YES/NO + exit-code contract.</summary>
internal sealed record NotifyResult(bool Ok, string Reason);
/// <summary>
/// Connect-failure-only failover loop: tries each base URL in order. A node that responds at all is
/// authoritative — its answer is final (success, business rejection, or HTTP error alike). Only a
/// failure to connect rolls over to the next URL; if every URL fails to connect the last error is reported.
/// </summary>
internal static class Notifier
{
/// <summary>
/// Runs the connect-failure-only failover loop across <paramref name="baseUrls"/>,
/// sending <paramref name="payload"/> via <paramref name="sender"/> until a node
/// responds (connects) or every URL fails to connect.
/// </summary>
/// <param name="baseUrls">Base URLs to try in order.</param>
/// <param name="payload">The recipe-download payload to send.</param>
/// <param name="sender">The sender used to POST the payload to each base URL.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>A task that resolves to the final notify outcome.</returns>
public static async Task<NotifyResult> RunAsync(
string[] baseUrls, RecipeDownload payload, IRecipeSender sender, CancellationToken ct)
{
var lastError = "no base URLs configured";
foreach (var baseUrl in baseUrls)
{
var outcome = await sender.SendAsync(baseUrl, payload, ct);
if (outcome.Kind == AttemptKind.ConnectFailed)
{
lastError = outcome.Error ?? "connection failed";
continue; // unreachable node → try the next
}
// Connected — this node's answer is authoritative; never fail over past it.
if (IsSuccessStatus(outcome.StatusCode))
{
if (outcome.Body is { Result: true })
{
return new NotifyResult(true, outcome.Body.ResultText ?? string.Empty);
}
var reason = outcome.Body?.ResultText;
return new NotifyResult(false, string.IsNullOrEmpty(reason) ? "request rejected" : reason);
}
return new NotifyResult(false, $"HTTP {outcome.StatusCode}");
}
return new NotifyResult(false, $"all URLs unreachable: {lastError}");
}
private static bool IsSuccessStatus(int status) => status is >= 200 and < 300;
}