Browse Source

generate fake epg data for graphics elements when troubleshooting (#2415)

pull/2417/head
Jason Dove 4 months ago committed by GitHub
parent
commit
5379a893f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 30
      ErsatzTV.Infrastructure/Data/Repositories/TemplateDataRepository.cs
  3. 13
      ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElementLoader.cs

1
CHANGELOG.md

@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix inefficient database migration that would cause database initialization to get stuck
- Classic schedules: fix scheduling behavior when a flood item is before a flexible fixed start item
- Sometimes the flood item wouldn't schedule anything
- Fix troubleshooting certain text graphics elements by generating fake EPG data
### Changed
- **BREAKING CHANGE**: change how `Scripted Schedule` system works

30
ErsatzTV.Infrastructure/Data/Repositories/TemplateDataRepository.cs

@ -33,6 +33,36 @@ public class TemplateDataRepository(ILocalFileSystem localFileSystem, IDbContext @@ -33,6 +33,36 @@ public class TemplateDataRepository(ILocalFileSystem localFileSystem, IDbContext
{
try
{
if (channelNumber.Equals(".troubleshooting", StringComparison.OrdinalIgnoreCase))
{
var now = DateTimeOffset.Now;
var topOfHour = new DateTimeOffset(now.Year, now.Month, now.Day, now.Hour, 0, 0, now.Offset);
List<EpgProgrammeTemplateData> result = [];
for (var i = 0; i < count; i++)
{
var data = new EpgProgrammeTemplateData
{
Title = $"Fake Epg Title {i}",
SubTitle = $"Fake Epg SubTitle {i}",
Description = string.Empty,
Rating = string.Empty,
Categories = [],
Date = $"Fake Epg Date {i}",
Start = topOfHour + i * TimeSpan.FromHours(1),
Stop = topOfHour + (i + 1) * TimeSpan.FromHours(1),
};
result.Add(data);
}
return new Dictionary<string, object>
{
[EpgTemplateDataKey.Epg] = result
};
}
string targetFile = Path.Combine(FileSystemLayout.ChannelGuideCacheFolder, $"{channelNumber}.xml");
if (localFileSystem.FileExists(targetFile))
{

13
ErsatzTV.Infrastructure/Streaming/Graphics/GraphicsElementLoader.cs

@ -143,13 +143,13 @@ public partial class GraphicsElementLoader( @@ -143,13 +143,13 @@ public partial class GraphicsElementLoader(
}
private Task<Option<ImageGraphicsElement>> LoadImage(string fileName, Dictionary<string, object> variables) =>
GetTemplatedYaml(fileName, variables).Map(FromYaml<ImageGraphicsElement>);
GetTemplatedYaml(fileName, variables).BindT(FromYaml<ImageGraphicsElement>);
private Task<Option<TextGraphicsElement>> LoadText(string fileName, Dictionary<string, object> variables) =>
GetTemplatedYaml(fileName, variables).Map(FromYaml<TextGraphicsElement>);
GetTemplatedYaml(fileName, variables).BindT(FromYaml<TextGraphicsElement>);
private Task<Option<SubtitleGraphicsElement>> LoadSubtitle(string fileName, Dictionary<string, object> variables) =>
GetTemplatedYaml(fileName, variables).Map(FromYaml<SubtitleGraphicsElement>);
GetTemplatedYaml(fileName, variables).BindT(FromYaml<SubtitleGraphicsElement>);
private async Task<Dictionary<string, object>> InitTemplateVariables(
GraphicsEngineContext context,
@ -189,7 +189,7 @@ public partial class GraphicsElementLoader( @@ -189,7 +189,7 @@ public partial class GraphicsElementLoader(
return result;
}
private async Task<string> GetTemplatedYaml(string fileName, Dictionary<string, object> variables)
private async Task<Option<string>> GetTemplatedYaml(string fileName, Dictionary<string, object> variables)
{
string yaml = await localFileSystem.ReadAllText(fileName);
try
@ -203,9 +203,10 @@ public partial class GraphicsElementLoader( @@ -203,9 +203,10 @@ public partial class GraphicsElementLoader(
context.PushGlobal(scriptObject);
return await Template.Parse(yaml).RenderAsync(context);
}
catch (Exception)
catch (Exception ex)
{
return yaml;
logger.LogWarning(ex, "Failed to load process graphics element YAML definition as template");
return Option<string>.None;
}
}

Loading…
Cancel
Save