namespace LanDesktopPLONDS.Installer.Services;
///
/// 记录单个下载源探测失败信息,用于诊断聚合。
///
internal sealed record InstallerSourceProbeFailure(
string SourceId,
string ManifestUrl,
string ErrorMessage);
///
/// 聚合所有下载源探测失败信息,当所有源均不可用时生成中文诊断摘要。
///
internal sealed class InstallerSourceProbeReport
{
private readonly List _failures = [];
/// 所有记录的失败信息。
public IReadOnlyList Failures => _failures;
/// 是否至少记录了一个失败。
public bool HasFailures => _failures.Count > 0;
/// 记录一次源探测失败。
public void AddFailure(string sourceId, string manifestUrl, Exception exception)
{
_failures.Add(new InstallerSourceProbeFailure(sourceId, manifestUrl, exception.Message));
}
/// 记录一次源探测失败(字符串消息)。
public void AddFailure(string sourceId, string manifestUrl, string errorMessage)
{
_failures.Add(new InstallerSourceProbeFailure(sourceId, manifestUrl, errorMessage));
}
///
/// 生成中文诊断摘要,列出每个失败的源 ID 和错误信息。
/// 用于抛出 InvalidOperationException 时的 message 参数。
///
public string FormatChineseSummary()
{
if (_failures.Count == 0)
{
return "所有下载源均不可用。";
}
var lines = _failures.Select(f => $"- {f.SourceId}: {f.ErrorMessage}");
return $"所有下载源均不可用:\n{string.Join("\n", lines)}";
}
}