|
|
|
@ -27,55 +27,114 @@ public class ProcessSchedulingContextHandler(IDbContextFactory<TvContext> dbCont |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var classicContext = JsonConvert.DeserializeObject<ClassicSchedulingContext>(request.SerializedContext); |
|
|
|
var classicContext = JsonConvert.DeserializeObject<ClassicSchedulingContext>(request.SerializedContext); |
|
|
|
if (classicContext is not null) |
|
|
|
if (classicContext is not null && classicContext.ScheduleId > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
return await GetClassicDetails(classicContext, cancellationToken); |
|
|
|
|
|
|
|
} |
|
|
|
string scheduleName = await dbContext.ProgramSchedules |
|
|
|
|
|
|
|
.Where(s => s.Id == classicContext.ScheduleId) |
|
|
|
var blockContext = JsonConvert.DeserializeObject<BlockSchedulingContext>(request.SerializedContext); |
|
|
|
.Select(s => s.Name) |
|
|
|
if (blockContext is not null && blockContext.BlockId > 0) |
|
|
|
.SingleOrDefaultAsync(cancellationToken); |
|
|
|
{ |
|
|
|
|
|
|
|
return await GetBlockDetails(blockContext, cancellationToken); |
|
|
|
var scheduleItem = await dbContext.ProgramScheduleItems |
|
|
|
} |
|
|
|
.AsNoTracking() |
|
|
|
|
|
|
|
.AsSplitQuery() |
|
|
|
return request.SerializedContext; |
|
|
|
.Include(si => si.SmartCollection) |
|
|
|
} |
|
|
|
.Include(si => si.Collection) |
|
|
|
|
|
|
|
.Include(si => si.MultiCollection) |
|
|
|
private async Task<Option<string>> GetClassicDetails( |
|
|
|
.Include(si => si.RerunCollection) |
|
|
|
ClassicSchedulingContext classicContext, |
|
|
|
.Include(si => si.Playlist) |
|
|
|
CancellationToken cancellationToken) |
|
|
|
.SingleOrDefaultAsync(s => s.Id == classicContext.ItemId, cancellationToken); |
|
|
|
{ |
|
|
|
|
|
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
ClassicContextScheduleItem item; |
|
|
|
|
|
|
|
if (scheduleItem is not null) |
|
|
|
string scheduleName = await dbContext.ProgramSchedules |
|
|
|
{ |
|
|
|
.Where(s => s.Id == classicContext.ScheduleId) |
|
|
|
string collectionName = scheduleItem.CollectionType switch |
|
|
|
.Select(s => s.Name) |
|
|
|
{ |
|
|
|
.SingleOrDefaultAsync(cancellationToken); |
|
|
|
CollectionType.SmartCollection => scheduleItem.SmartCollection.Name, |
|
|
|
|
|
|
|
CollectionType.Collection => scheduleItem.Collection.Name, |
|
|
|
var scheduleItem = await dbContext.ProgramScheduleItems |
|
|
|
CollectionType.MultiCollection => scheduleItem.MultiCollection.Name, |
|
|
|
.AsNoTracking() |
|
|
|
CollectionType.RerunRerun or CollectionType.RerunFirstRun => scheduleItem.RerunCollection.Name, |
|
|
|
.AsSplitQuery() |
|
|
|
CollectionType.Playlist => scheduleItem.Playlist.Name, |
|
|
|
.Include(si => si.Collection) |
|
|
|
_ => null |
|
|
|
.Include(si => si.MultiCollection) |
|
|
|
}; |
|
|
|
.Include(si => si.Playlist) |
|
|
|
|
|
|
|
.Include(si => si.RerunCollection) |
|
|
|
item = new ClassicContextScheduleItem(scheduleItem.Id, scheduleItem.CollectionType, collectionName); |
|
|
|
.Include(si => si.SmartCollection) |
|
|
|
} |
|
|
|
.SingleOrDefaultAsync(s => s.Id == classicContext.ItemId, cancellationToken); |
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
ClassicContextScheduleItem item; |
|
|
|
|
|
|
|
if (scheduleItem is not null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string collectionName = scheduleItem.CollectionType switch |
|
|
|
{ |
|
|
|
{ |
|
|
|
item = new ClassicContextScheduleItem(classicContext.ItemId, null, null); |
|
|
|
CollectionType.Collection => scheduleItem.Collection.Name, |
|
|
|
} |
|
|
|
CollectionType.MultiCollection => scheduleItem.MultiCollection.Name, |
|
|
|
|
|
|
|
CollectionType.Playlist => scheduleItem.Playlist.Name, |
|
|
|
|
|
|
|
CollectionType.RerunRerun or CollectionType.RerunFirstRun => scheduleItem.RerunCollection.Name, |
|
|
|
|
|
|
|
CollectionType.SmartCollection => scheduleItem.SmartCollection.Name, |
|
|
|
|
|
|
|
_ => null |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item = new ClassicContextScheduleItem(scheduleItem.Id, scheduleItem.CollectionType, collectionName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
item = new ClassicContextScheduleItem(classicContext.ItemId, null, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var context = new ClassicContext( |
|
|
|
var context = new ClassicContext( |
|
|
|
new ContextScheduler("Classic", classicContext.Scheduler), |
|
|
|
new ContextScheduler("Classic", classicContext.Scheduler), |
|
|
|
new ClassicContextSchedule(classicContext.ScheduleId, scheduleName ?? string.Empty), |
|
|
|
new ClassicContextSchedule(classicContext.ScheduleId, scheduleName ?? string.Empty), |
|
|
|
item, |
|
|
|
item, |
|
|
|
new ContextEnumerator(classicContext.Enumerator, classicContext.Seed, classicContext.Index)); |
|
|
|
new ContextEnumerator(classicContext.Enumerator, classicContext.Seed, classicContext.Index)); |
|
|
|
|
|
|
|
|
|
|
|
return JsonSerializer.Serialize(context, Options); |
|
|
|
return JsonSerializer.Serialize(context, Options); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Option<string>> GetBlockDetails(BlockSchedulingContext blockContext, CancellationToken cancellationToken) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var block = await dbContext.Blocks |
|
|
|
|
|
|
|
.Include(b => b.BlockGroup) |
|
|
|
|
|
|
|
.SingleOrDefaultAsync(s => s.Id == blockContext.BlockId, cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var blockItem = await dbContext.BlockItems |
|
|
|
|
|
|
|
.AsNoTracking() |
|
|
|
|
|
|
|
.AsSplitQuery() |
|
|
|
|
|
|
|
.Include(si => si.Collection) |
|
|
|
|
|
|
|
.Include(si => si.MultiCollection) |
|
|
|
|
|
|
|
.Include(si => si.SmartCollection) |
|
|
|
|
|
|
|
.SingleOrDefaultAsync(s => s.Id == blockContext.BlockItemId, cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BlockContextBlockItem item; |
|
|
|
|
|
|
|
if (blockItem is not null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string collectionName = blockItem.CollectionType switch |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CollectionType.Collection => blockItem.Collection.Name, |
|
|
|
|
|
|
|
CollectionType.MultiCollection => blockItem.MultiCollection.Name, |
|
|
|
|
|
|
|
CollectionType.SmartCollection => blockItem.SmartCollection.Name, |
|
|
|
|
|
|
|
_ => null |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item = new BlockContextBlockItem(blockItem.Id, blockItem.CollectionType, collectionName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
item = new BlockContextBlockItem(blockContext.BlockItemId, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return request.SerializedContext; |
|
|
|
var context = new BlockContext( |
|
|
|
|
|
|
|
new ContextScheduler("Block", null), |
|
|
|
|
|
|
|
new BlockContextBlock( |
|
|
|
|
|
|
|
blockContext.BlockId, |
|
|
|
|
|
|
|
block?.BlockGroup?.Name ?? string.Empty, |
|
|
|
|
|
|
|
block?.Name ?? string.Empty), |
|
|
|
|
|
|
|
item, |
|
|
|
|
|
|
|
new ContextEnumerator(blockContext.Enumerator, blockContext.Seed, blockContext.Index)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JsonSerializer.Serialize(context, Options); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private sealed record ClassicContext( |
|
|
|
private sealed record ClassicContext( |
|
|
|
@ -91,4 +150,14 @@ public class ProcessSchedulingContextHandler(IDbContextFactory<TvContext> dbCont |
|
|
|
private sealed record ClassicContextScheduleItem(int Id, CollectionType? CollectionType, string CollectionName); |
|
|
|
private sealed record ClassicContextScheduleItem(int Id, CollectionType? CollectionType, string CollectionName); |
|
|
|
|
|
|
|
|
|
|
|
private sealed record ContextEnumerator(string Name, int Seed, int Index); |
|
|
|
private sealed record ContextEnumerator(string Name, int Seed, int Index); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private sealed record BlockContext( |
|
|
|
|
|
|
|
ContextScheduler Scheduler, |
|
|
|
|
|
|
|
BlockContextBlock Block, |
|
|
|
|
|
|
|
BlockContextBlockItem BlockItem, |
|
|
|
|
|
|
|
ContextEnumerator Enumerator); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private sealed record BlockContextBlock(int Id, string Group, string Name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private sealed record BlockContextBlockItem(int Id, CollectionType? CollectionType, string CollectionName); |
|
|
|
} |
|
|
|
} |
|
|
|
|