Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions FirstClassErrors/PrimaryPortInnerErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,7 @@ public PrimaryPortInnerErrors Add(PrimaryPortError error) {
/// It determines the transience based on the <see cref="InfrastructureError.Transience" /> property.
/// </remarks>
public Transience ComputeTransience() {
IEnumerable<InfrastructureError> infraErrors = _errors.OfType<InfrastructureError>();

bool hasTransient = false;

foreach (InfrastructureError? error in infraErrors) {
switch (error.Transience) {
case Transience.NonTransient: return Transience.NonTransient;
case Transience.Transient: hasTransient = true; break;
}
}

return hasTransient
? Transience.Transient
: Transience.Unknown;
return TransienceCalculator.Compute(_errors);
}

internal IReadOnlyList<Error> ToList() {
Expand Down
15 changes: 1 addition & 14 deletions FirstClassErrors/SecondaryPortInnerErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,7 @@ internal IReadOnlyList<Error> ToList() {
/// <see cref="InfrastructureError.Transience" /> property of each error.
/// </remarks>
public Transience ComputeTransience() {
IEnumerable<InfrastructureError> infraErrors = _errors.OfType<InfrastructureError>();

bool hasTransient = false;

foreach (InfrastructureError? error in infraErrors) {
switch (error.Transience) {
case Transience.NonTransient: return Transience.NonTransient;
case Transience.Transient: hasTransient = true; break;
}
}

return hasTransient
? Transience.Transient
: Transience.Unknown;
return TransienceCalculator.Compute(_errors);
}

/// <inheritdoc />
Expand Down
59 changes: 59 additions & 0 deletions FirstClassErrors/TransienceCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace FirstClassErrors;

/// <summary>
/// Computes the overall <see cref="Transience" /> of a collection of errors.
/// </summary>
/// <remarks>
/// This helper centralizes the transience resolution rules so that the various inner-error collections
/// (for instance <see cref="PrimaryPortInnerErrors" /> and <see cref="SecondaryPortInnerErrors" />) share a
/// single, authoritative implementation rather than duplicating the logic.
/// </remarks>
internal static class TransienceCalculator {

#region Statics members declarations

/// <summary>
/// Computes the overall transience of the specified errors.
/// </summary>
/// <param name="errors">The errors to evaluate.</param>
/// <returns>
/// A <see cref="Transience" /> value indicating the overall transience of the errors:
/// <list type="bullet">
/// <item>
/// <description><see cref="Transience.NonTransient" /> if any error is explicitly non-transient.</description>
/// </item>
/// <item>
/// <description>
/// <see cref="Transience.Transient" /> if at least one error is transient and none are
/// non-transient.
/// </description>
/// </item>
/// <item>
/// <description><see cref="Transience.Unknown" /> if no errors are classified as transient or non-transient.</description>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// Only errors of type <see cref="InfrastructureError" /> are taken into account; the transience is determined
/// based on their <see cref="InfrastructureError.Transience" /> property.
/// </remarks>
public static Transience Compute(IEnumerable<Error> errors) {
IEnumerable<InfrastructureError> infraErrors = errors.OfType<InfrastructureError>();

bool hasTransient = false;

foreach (InfrastructureError error in infraErrors) {
switch (error.Transience) {
case Transience.NonTransient: return Transience.NonTransient;
case Transience.Transient: hasTransient = true; break;
}
}

return hasTransient
? Transience.Transient
: Transience.Unknown;
}

#endregion

}
Loading