Files
C4IT-F4SD-Client/FasdDesktopUi/Basics/Services/Models/TicketOverviewCommunicationSource.cs
2026-02-13 09:06:36 +01:00

67 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using C4IT.FASD.Cockpit.Communication;
#if isDemo
using FasdCockpitCommunicationDemo;
#endif
namespace FasdDesktopUi.Basics.Services.Models
{
internal interface ITicketOverviewCommunication
{
bool IsDemo();
Task<Dictionary<string, int>> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope);
#if isDemo
void RegisterGeneratedTicket(DemoTicketRecord record);
#endif
}
internal interface ITicketOverviewCommunicationSource
{
ITicketOverviewCommunication Resolve();
}
internal sealed class TicketOverviewCommunicationSource : ITicketOverviewCommunicationSource
{
public ITicketOverviewCommunication Resolve()
{
var communication = cFasdCockpitCommunicationBase.Instance;
return communication == null ? null : new TicketOverviewCommunicationAdapter(communication);
}
}
internal sealed class TicketOverviewCommunicationAdapter : ITicketOverviewCommunication
{
private readonly cFasdCockpitCommunicationBase _communication;
internal TicketOverviewCommunicationAdapter(cFasdCockpitCommunicationBase communication)
{
_communication = communication ?? throw new ArgumentNullException(nameof(communication));
}
public bool IsDemo()
{
return _communication.IsDemo();
}
public async Task<Dictionary<string, int>> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope)
{
var rawCounts = await _communication.GetTicketOverviewCounts(overviewKeys, useRoleScope).ConfigureAwait(false);
return rawCounts == null
? new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
: new Dictionary<string, int>(rawCounts, StringComparer.OrdinalIgnoreCase);
}
#if isDemo
public void RegisterGeneratedTicket(DemoTicketRecord record)
{
var demoCommunication = _communication as cFasdCockpitCommunicationDemo;
demoCommunication?.RegisterGeneratedTicket(record);
}
#endif
}
}