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;
///
/// Create with given and .
///
/// let the user know which terminal is affected (e.g. 'UDP 192.168.1.1' or 'Serial COM5')
/// why the reading was stopped
public StoppedReadingUIMessage(string affectedTerminalIdentifier, string reason = "")
{
this.affectedTerminalIdentifier = affectedTerminalIdentifier;
this.reason = reason;
}
///
/// Create with given .
/// Extracts from given .
///
/// root communication protocol instance, to extract affectedTerminalIdentifier from
/// why the reading was stopped
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}";
}
}
}