While doing so, I have also refactored the shipcall processing logic in the main window. All changes now go through the filter and sorting stage before all controls are removed and only the controls matching to the sorted list are added to the stack panel.
103 lines
2.6 KiB
C#
103 lines
2.6 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: some helpers
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
internal static class Extensions
|
|
{
|
|
|
|
#region Enum
|
|
|
|
/// <summary>
|
|
/// Copied from models clunky I know
|
|
/// </summary>
|
|
[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,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom participant flags
|
|
/// </summary>
|
|
[Flags]
|
|
public enum ParticipantFlag
|
|
{
|
|
[Description("allow BSMD initial info")]
|
|
ALLOW_BSMD = 1,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Should actually be defined in yaml
|
|
/// </summary>
|
|
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
|
|
|
|
}
|
|
}
|