feat(client-cli): add ack/confirm/shelve alarm commands with service layer
Adds ConfirmAlarmAsync and ShelveAlarmAsync to IOpcUaClientService and OpcUaClientService (mirroring the AcknowledgeAlarmAsync pattern: same CallMethodAsync/ServiceResultException/StatusCode contract). Adds ShelveKind enum (OneShot/Timed/Unshelve). Adds three new CLI commands — ack, confirm, shelve — with hex EventId input and per-command argument validation. Updates both fakes (CLI + UI) to implement the new interface members and record calls. Adds 16 unit tests covering argument mapping, invalid-input CommandException paths, bad-status output, and disconnect-in-finally.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Infrastructure;
|
||||
using Opc.Ua;
|
||||
using ZB.MOM.WW.OtOpcUa.Client.Shared;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Commands;
|
||||
|
||||
[Command("confirm", Description = "Confirm an acknowledged alarm condition (OPC UA Part 9 two-stage acknowledgment)")]
|
||||
public class ConfirmCommand : CommandBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the confirm command used to confirm an acknowledged OPC UA condition from the terminal.
|
||||
/// </summary>
|
||||
/// <param name="factory">The factory that creates the shared client service for the command run.</param>
|
||||
public ConfirmCommand(IOpcUaClientServiceFactory factory) : base(factory)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the condition node ID of the alarm event to confirm.
|
||||
/// </summary>
|
||||
[CommandOption("node", 'n', Description = "Condition node ID of the alarm to confirm", IsRequired = true)]
|
||||
public string NodeId { get; init; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the event ID (hex-encoded) returned by the server in the alarm notification.
|
||||
/// </summary>
|
||||
[CommandOption("event-id", 'e', Description = "EventId from the alarm notification (hex-encoded byte array)", IsRequired = true)]
|
||||
public string EventId { get; init; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the operator comment to include with the confirmation.
|
||||
/// </summary>
|
||||
[CommandOption("comment", 'c', Description = "Operator comment for the confirmation")]
|
||||
public string Comment { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the server and confirms the specified acknowledged alarm condition.
|
||||
/// </summary>
|
||||
/// <param name="console">The CLI console used for output and cancellation handling.</param>
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
ConfigureLogging();
|
||||
|
||||
byte[] eventId;
|
||||
try
|
||||
{
|
||||
eventId = Convert.FromHexString(EventId);
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
throw new CommandException($"Invalid --event-id value: {ex.Message} (expected hex-encoded bytes, e.g. 0A1B2C)");
|
||||
}
|
||||
|
||||
IOpcUaClientService? service = null;
|
||||
try
|
||||
{
|
||||
var ct = console.RegisterCancellationHandler();
|
||||
(service, _) = await CreateServiceAndConnectAsync(ct);
|
||||
|
||||
var statusCode = await service.ConfirmAlarmAsync(NodeId, eventId, Comment, ct);
|
||||
|
||||
if (StatusCode.IsGood(statusCode))
|
||||
await console.Output.WriteLineAsync($"Confirm successful: {NodeId}");
|
||||
else
|
||||
await console.Output.WriteLineAsync($"Confirm failed: {statusCode}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (service != null)
|
||||
{
|
||||
await service.DisconnectAsync();
|
||||
service.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user