diff --git a/ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContextHandler.cs b/ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContextHandler.cs index 86b2694fc..94343df34 100644 --- a/ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContextHandler.cs +++ b/ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContextHandler.cs @@ -5,7 +5,6 @@ using ErsatzTV.Core.Domain.Filler; using ErsatzTV.Core.Scheduling; using ErsatzTV.Infrastructure.Data; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; using JsonSerializer = System.Text.Json.JsonSerializer; namespace ErsatzTV.Application.ProgramSchedules; @@ -22,21 +21,29 @@ public class ProcessSchedulingContextHandler(IDbContextFactory dbCont public async Task> Handle(ProcessSchedulingContext request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request.SerializedContext)) + try { - return Option.None; - } - - var classicContext = JsonConvert.DeserializeObject(request.SerializedContext); - if (classicContext is not null && classicContext.ScheduleId > 0) - { - return await GetClassicDetails(classicContext, cancellationToken); + using JsonDocument doc = JsonDocument.Parse(request.SerializedContext); + if (doc.RootElement.TryGetProperty(nameof(ClassicSchedulingContext.ScheduleId), out _)) + { + var classicContext = JsonSerializer.Deserialize(request.SerializedContext, Options); + if (classicContext is not null && classicContext.ScheduleId > 0) + { + return await GetClassicDetails(classicContext, cancellationToken); + } + } + else if (doc.RootElement.TryGetProperty(nameof(BlockSchedulingContext.BlockId), out _)) + { + var blockContext = JsonSerializer.Deserialize(request.SerializedContext, Options); + if (blockContext is not null && blockContext.BlockId > 0) + { + return await GetBlockDetails(blockContext, cancellationToken); + } + } } - - var blockContext = JsonConvert.DeserializeObject(request.SerializedContext); - if (blockContext is not null && blockContext.BlockId > 0) + catch (JsonException) { - return await GetBlockDetails(blockContext, cancellationToken); + // not a valid json string, or not a context we can process } return request.SerializedContext;