@ -28,109 +28,119 @@ public partial class GraphicsElementLoader(
List < PlayoutItemGraphicsElement > elements ,
List < PlayoutItemGraphicsElement > elements ,
CancellationToken cancellationToken )
CancellationToken cancellationToken )
{
{
// get max epg entries
try
int epgEntries = await GetMaxEpgEntries ( elements ) ;
{
// get max epg entries
int epgEntries = await GetMaxEpgEntries ( elements ) ;
// init template element variables once
// init template element variables once
Dictionary < string , object > templateVariables =
Dictionary < string , object > templateVariables =
await InitTemplateVariables ( context , epgEntries , cancellationToken ) ;
await InitTemplateVariables ( context , epgEntries , cancellationToken ) ;
// subtitles are in separate files, so they need template variables for later processing
// subtitles are in separate files, so they need template variables for later processing
context = context with { TemplateVariables = templateVariables } ;
context = context with { TemplateVariables = templateVariables } ;
// fully process references (using template variables)
// fully process references (using template variables)
foreach ( PlayoutItemGraphicsElement reference in elements )
foreach ( PlayoutItemGraphicsElement reference in elements )
{
switch ( reference . GraphicsElement . Kind )
{
{
case GraphicsElementKind . Text :
switch ( reference . GraphicsElement . Kind )
{
{
Option < TextGraphicsElement > maybeElement = await LoadText (
case GraphicsElementKind . Text :
reference . GraphicsElement . Path ,
templateVariables ) ;
if ( maybeElement . IsNone )
{
{
logger . LogWarning (
Option < TextGraphicsElement > maybeElement = await LoadText (
"Failed to load text graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ,
reference . GraphicsElement . Path ) ;
templateVariables ) ;
}
if ( maybeElement . IsNone )
{
logger . LogWarning (
"Failed to load text graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ) ;
}
foreach ( TextGraphicsElement element in maybeElement )
foreach ( TextGraphicsElement element in maybeElement )
{
{
context . Elements . Add ( new TextElementDataContext ( element ) ) ;
context . Elements . Add ( new TextElementDataContext ( element ) ) ;
}
}
break ;
break ;
}
case GraphicsElementKind . Image :
{
Option < ImageGraphicsElement > maybeElement = await LoadImage (
reference . GraphicsElement . Path ,
templateVariables ) ;
if ( maybeElement . IsNone )
{
logger . LogWarning (
"Failed to load image graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ) ;
}
}
case GraphicsElementKind . Image :
{
Option < ImageGraphicsElement > maybeElement = await LoadImage (
reference . GraphicsElement . Path ,
templateVariables ) ;
if ( maybeElement . IsNone )
{
logger . LogWarning (
"Failed to load image graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ) ;
}
context . Elements . AddRange ( maybeElement . Select ( element = > new ImageElementContext ( element ) ) ) ;
context . Elements . AddRange ( maybeElement . Select ( element = > new ImageElementContext ( element ) ) ) ;
break ;
break ;
}
case GraphicsElementKind . Motion :
{
Option < MotionGraphicsElement > maybeElement = await LoadMotion (
reference . GraphicsElement . Path ,
templateVariables ) ;
if ( maybeElement . IsNone )
{
logger . LogWarning (
"Failed to load motion graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ) ;
}
}
case GraphicsElementKind . Motion :
foreach ( MotionGraphicsElement element in maybeElement )
{
{
context . Elements . Add ( new MotionElementDataContext ( element ) ) ;
Option < MotionGraphicsElement > maybeElement = await LoadMotion (
}
reference . GraphicsElement . Path ,
templateVariables ) ;
if ( maybeElement . IsNone )
{
logger . LogWarning (
"Failed to load motion graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ) ;
}
break ;
foreach ( MotionGraphicsElement element in maybeElement )
}
{
case GraphicsElementKind . Subtitle :
context . Elements . Add ( new MotionElementDataContext ( element ) ) ;
{
}
Option < SubtitleGraphicsElement > maybeElement = await LoadSubtitle (
reference . GraphicsElement . Path ,
templateVariables ) ;
if ( maybeElement . IsNone )
{
logger . LogWarning (
"Failed to load subtitle graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ) ;
}
foreach ( SubtitleGraphicsElement element in maybeElement )
break ;
}
case GraphicsElementKind . Subtitle :
{
{
var variables = new Dictionary < string , string > ( ) ;
Option < SubtitleGraphicsElement > maybeElement = await LoadSubtitle (
if ( ! string . IsNullOrWhiteSpace ( reference . Variables ) )
reference . GraphicsElement . Path ,
templateVariables ) ;
if ( maybeElement . IsNone )
{
{
variables = JsonConvert . DeserializeObject < Dictionary < string , string > > ( reference . Variables ) ;
logger . LogWarning (
"Failed to load subtitle graphics element from file {Path}; ignoring" ,
reference . GraphicsElement . Path ) ;
}
}
context . Elements . Add ( new SubtitleElementDataContext ( element , variables ) ) ;
foreach ( SubtitleGraphicsElement element in maybeElement )
}
{
var variables = new Dictionary < string , string > ( ) ;
if ( ! string . IsNullOrWhiteSpace ( reference . Variables ) )
{
variables = JsonConvert . DeserializeObject < Dictionary < string , string > > (
reference . Variables ) ;
}
context . Elements . Add ( new SubtitleElementDataContext ( element , variables ) ) ;
}
break ;
break ;
}
default :
logger . LogInformation (
"Ignoring unsupported graphics element kind {Kind}" ,
nameof ( reference . GraphicsElement . Kind ) ) ;
break ;
}
}
default :
logger . LogInformation (
"Ignoring unsupported graphics element kind {Kind}" ,
nameof ( reference . GraphicsElement . Kind ) ) ;
break ;
}
}
return context ;
}
catch ( OperationCanceledException )
{
// do nothing
}
}
return context ;
return null ;
}
}
public async Task < Option < string > > TryLoadName ( string fileName , CancellationToken cancellationToken )
public async Task < Option < string > > TryLoadName ( string fileName , CancellationToken cancellationToken )