// Copyright (c) 2023 schick Informatik // Description: some helpers // using BreCalClient.misc.Model; using System; using System.ComponentModel; namespace BreCalClient { public static class Extensions { #region Enum /// /// Copied from models clunky I know /// [Flags] public enum ParticipantType { [Description("not assigned")] NONE = 0, [Description("BSMD")] BSMD = 1, [Description("Terminal")] TERMINAL = 2, [Description("Lotsen")] PILOT = 4, [Description("Agentur")] AGENCY = 8, [Description("Festmacher")] MOORING = 16, [Description("Hafenamt")] PORT_ADMINISTRATION = 32, [Description("Schlepper")] TUG = 64, } /// /// Custom participant flags /// [Flags] public enum ParticipantFlag { [Description("allow BSMD initial info")] ALLOW_BSMD = 1, } /// /// Should actually be defined in yaml /// public enum TypeEnum { Incoming = 1, Outgoing = 2, Shifting = 3 } public enum SortOrder { SHIP_NAME, ETA_ETD, MODIFIED } #endregion #region public helper public static bool IsTypeFlagSet(this Participant participant, ParticipantType flag) { return (participant.Type & (uint)flag) != 0; } public static bool IsFlagSet(this Participant participant, ParticipantFlag flag) { return (participant.Flags & (uint)flag) != 0; } public static string Truncate(this string value, int maxLength) { if (string.IsNullOrEmpty(value)) return value; return value.Length <= maxLength ? value : value.Substring(0, maxLength); } public static string TruncateDots(this string value, int maxLength) { if(string.IsNullOrEmpty(value)) return value; if (value.Length <= maxLength) return value; if (value.Length > (maxLength + 1)) return $"{value.Substring(0, maxLength)}.."; return value.Substring(0, maxLength); } #endregion } }