31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using MxGateway.Contracts.Proto;
|
|
|
|
namespace MxGateway.Client;
|
|
|
|
/// <summary>Extension methods for MxStatusProxy values.</summary>
|
|
public static class MxStatusProxyExtensions
|
|
{
|
|
/// <summary>Returns whether the status indicates success (success flag set and category is Ok).</summary>
|
|
/// <param name="status">The status to check.</param>
|
|
public static bool IsSuccess(this MxStatusProxy status)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(status);
|
|
|
|
return status.Success != 0
|
|
&& status.Category is MxStatusCategory.Ok;
|
|
}
|
|
|
|
/// <summary>Returns a formatted summary of the status for diagnostic output.</summary>
|
|
/// <param name="status">The status to summarize.</param>
|
|
public static string ToDiagnosticSummary(this MxStatusProxy status)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(status);
|
|
|
|
string diagnosticText = string.IsNullOrWhiteSpace(status.DiagnosticText)
|
|
? "no diagnostic text"
|
|
: status.DiagnosticText;
|
|
|
|
return $"{status.Category} by {status.DetectedBy}; detail={status.Detail}; {diagnosticText}";
|
|
}
|
|
}
|