mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
using ErsatzTV.Core.Scheduling.YamlScheduling.Models; |
|
using Microsoft.Extensions.Logging; |
|
|
|
namespace ErsatzTV.Core.Scheduling.YamlScheduling.Handlers; |
|
|
|
public class YamlPlayoutGraphicsOffHandler(IGraphicsElementRepository graphicsElementRepository) : IYamlPlayoutHandler |
|
{ |
|
private readonly Dictionary<string, Option<GraphicsElement>> _graphicsElementCache = new(); |
|
|
|
public bool Reset => false; |
|
|
|
public async Task<bool> Handle( |
|
YamlPlayoutContext context, |
|
YamlPlayoutInstruction instruction, |
|
PlayoutBuildMode mode, |
|
Func<string, Task> executeSequence, |
|
ILogger<YamlPlayoutBuilder> logger, |
|
CancellationToken cancellationToken) |
|
{ |
|
if (instruction is not YamlPlayoutGraphicsOffInstruction graphicsOff) |
|
{ |
|
return false; |
|
} |
|
|
|
if (string.IsNullOrWhiteSpace(graphicsOff.GraphicsOff)) |
|
{ |
|
context.ClearGraphicsElements(); |
|
} |
|
else |
|
{ |
|
foreach (var ge in await GetGraphicsElementByPath(graphicsOff.GraphicsOff)) |
|
{ |
|
context.RemoveGraphicsElement(ge.Id); |
|
} |
|
} |
|
|
|
return true; |
|
} |
|
|
|
private async Task<Option<GraphicsElement>> GetGraphicsElementByPath(string path) |
|
{ |
|
if (_graphicsElementCache.TryGetValue(path, out var cachedGraphicsElement)) |
|
{ |
|
foreach (GraphicsElement graphicsElement in cachedGraphicsElement) |
|
{ |
|
return graphicsElement; |
|
} |
|
} |
|
else |
|
{ |
|
Option<GraphicsElement> maybeGraphicsElement = |
|
await graphicsElementRepository.GetGraphicsElementByPath(path); |
|
_graphicsElementCache.Add(path, maybeGraphicsElement); |
|
foreach (GraphicsElement graphicsElement in maybeGraphicsElement) |
|
{ |
|
return graphicsElement; |
|
} |
|
} |
|
|
|
return Option<GraphicsElement>.None; |
|
} |
|
} |