using MultiTerm.Protocols.Network; namespace MultiTerm.Protocols.Helpers; internal static class NetworkProtocolHelpers { /// /// Returns the hostname of the but limited to amount of characters. /// If the hostname is longer than , '...' will be prefixed. The resulting string may also be +3 characters long. /// If the hostname cannot be read, the result will be "invalid". /// /// settings object containing hostname /// max amount of characters of the resulting string /// string with limited length (maximum amount of characters = + 3 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; } }