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.
30 lines
1.3 KiB
30 lines
1.3 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 postfixed. 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";
|
|
|
|
if (settingsObject.Hostname != null && settingsObject.Hostname.Length >= maxLength)
|
|
{
|
|
limitedHostname = $"{settingsObject.Hostname.Substring(maxLength)}...";
|
|
}
|
|
else if (settingsObject.Hostname != null)
|
|
{
|
|
limitedHostname = $"{settingsObject.Hostname}";
|
|
}
|
|
|
|
return limitedHostname;
|
|
}
|
|
}
|
|
|