99 lines
2.6 KiB
C#
99 lines
2.6 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Container model for shipcall related info
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
|
|
/// <summary>
|
|
/// Container model to aggregate separate models for the Shipcall control data binding
|
|
/// </summary>
|
|
public class ShipcallControlModel
|
|
{
|
|
|
|
public enum TrafficLightMode
|
|
{
|
|
OFF,
|
|
GREEN,
|
|
YELLOW,
|
|
RED,
|
|
RED_YELLOW,
|
|
ALL
|
|
};
|
|
|
|
[Flags]
|
|
public enum StatusFlags
|
|
{
|
|
RED,
|
|
GREEN,
|
|
YELLOW,
|
|
BLINK_1,
|
|
BLINK_2
|
|
};
|
|
|
|
public Shipcall? Shipcall { get; set; }
|
|
public Ship? Ship { get; set; }
|
|
|
|
public string? Agency { get; set; }
|
|
|
|
public string? Berth { get; set; }
|
|
|
|
public Dictionary<int, Participant> AssignedParticipants { get; } = new();
|
|
|
|
public void AssignParticipants(List<Participant> participants)
|
|
{
|
|
this.AssignedParticipants.Clear();
|
|
if (Shipcall != null)
|
|
{
|
|
foreach (int participantId in Shipcall.Participants)
|
|
{
|
|
foreach(Participant participant in participants)
|
|
{
|
|
if(participant.Id == participantId)
|
|
AssignedParticipants[participant.Type] = participant;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public TrafficLightMode LightMode
|
|
{
|
|
get
|
|
{
|
|
if(IsFlagSet(StatusFlags.RED))
|
|
{
|
|
if(IsFlagSet((StatusFlags)StatusFlags.YELLOW))
|
|
{
|
|
if(IsFlagSet(StatusFlags.GREEN))
|
|
{
|
|
return TrafficLightMode.ALL;
|
|
}
|
|
return TrafficLightMode.RED_YELLOW;
|
|
}
|
|
return TrafficLightMode.RED;
|
|
}
|
|
if(IsFlagSet(StatusFlags.YELLOW))
|
|
return TrafficLightMode.YELLOW;
|
|
if(IsFlagSet(StatusFlags.GREEN))
|
|
return TrafficLightMode.GREEN;
|
|
return TrafficLightMode.OFF;
|
|
}
|
|
}
|
|
|
|
#region private helper
|
|
|
|
private bool IsFlagSet(StatusFlags flag)
|
|
{
|
|
if(this.Shipcall == null) return false;
|
|
return (this.Shipcall.Flags & (int) flag) != 0;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|