You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.9 KiB
46 lines
1.9 KiB
using Common.Messaging;
|
|
|
|
namespace MultiTerm.Protocols.Types;
|
|
|
|
public sealed class StoppedReadingUIMessage : IUserInterfaceMessage
|
|
{
|
|
private readonly string affectedTerminalIdentifier;
|
|
private readonly string reason;
|
|
|
|
public MessageImportance Importance => MessageImportance.Medium;
|
|
|
|
/// <summary>
|
|
/// Create <see cref="StoppedReadingUIMessage"/> with given <paramref name="affectedTerminalIdentifier"/> and <paramref name="reason"/>.
|
|
/// </summary>
|
|
/// <param name="affectedTerminalIdentifier">let the user know which terminal is affected (e.g. 'UDP 192.168.1.1' or 'Serial COM5')</param>
|
|
/// <param name="reason">why the reading was stopped</param>
|
|
public StoppedReadingUIMessage(string affectedTerminalIdentifier, string reason = "")
|
|
{
|
|
this.affectedTerminalIdentifier = affectedTerminalIdentifier;
|
|
this.reason = reason;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create <see cref="StoppedReadingUIMessage"/> with given <paramref name="reason"/>.
|
|
/// Extracts <see cref="affectedTerminalIdentifier"/> from given <paramref name="communicationProtocol"/>.
|
|
/// </summary>
|
|
/// <param name="communicationProtocol">root communication protocol instance, to extract affectedTerminalIdentifier from</param>
|
|
/// <param name="reason">why the reading was stopped</param>
|
|
public StoppedReadingUIMessage(CommunicationProtocol communicationProtocol, string reason = "")
|
|
{
|
|
this.affectedTerminalIdentifier = communicationProtocol.GetProtocolAndInstanceIdentifier();
|
|
this.reason = reason;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
if (string.IsNullOrEmpty(this.reason))
|
|
{
|
|
return $"Stopped Reading from '{this.affectedTerminalIdentifier}' because of unknown issue. Please check logfile.";
|
|
}
|
|
else
|
|
{
|
|
return $"Stopped Reading from '{this.affectedTerminalIdentifier}': {this.reason}";
|
|
}
|
|
}
|
|
}
|
|
|