Multiprocotol Terminalprogram (BAT)
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.
MultiTerm/MultiTerm.Protocols/Helpers/NetworkProtocolHelpers.cs

31 lines
1.4 KiB

using MultiTerm.Protocols.Network;
namespace MultiTerm.Protocols.Helpers;
internal static class NetworkProtocolHelpers
{
/// <summary>
/// Returns the hostname of the <paramref name="settingsObject"/> but limited to <paramref name="maxLength"/> amount of characters.
/// If the hostname is longer than <paramref name="maxLength"/>, '...' will be prefixed. The resulting string may also be <paramref name="maxLength"/>+3 characters long.
/// If the hostname cannot be read, the result will be "invalid".
/// </summary>
/// <param name="settingsObject">settings object containing hostname</param>
/// <param name="maxLength">max amount of characters of the resulting string</param>
/// <returns>string with limited length (maximum amount of characters = <paramref name="maxLength"/> + 3</returns>
public static string GetLimitedLengthHostname(INetworkProtocolSettings settingsObject, int maxLength = 20)
{
string limitedHostname = "invalid";
string prefix = "...";
if (settingsObject.Hostname != null && settingsObject.Hostname.Length >= maxLength)
{
limitedHostname = $"{prefix}{settingsObject.Hostname.Substring(settingsObject.Hostname.Length - maxLength, maxLength)}";
}
else if (settingsObject.Hostname != null)
{
limitedHostname = $"{settingsObject.Hostname}";
}
return limitedHostname;
}
}