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.
41 lines
1.4 KiB
41 lines
1.4 KiB
using ErsatzTV.Core; |
|
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Interfaces.Scheduling; |
|
using ErsatzTV.Infrastructure.Data; |
|
using ErsatzTV.Infrastructure.Extensions; |
|
using Microsoft.EntityFrameworkCore; |
|
|
|
namespace ErsatzTV.Application.Playouts; |
|
|
|
public class TimeShiftOnDemandPlayoutHandler( |
|
IPlayoutTimeShifter playoutTimeShifter, |
|
IDbContextFactory<TvContext> dbContextFactory) |
|
: IRequestHandler<TimeShiftOnDemandPlayout, Option<BaseError>> |
|
{ |
|
public async Task<Option<BaseError>> Handle(TimeShiftOnDemandPlayout request, CancellationToken cancellationToken) |
|
{ |
|
try |
|
{ |
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
Option<Playout> maybePlayout = await dbContext.Playouts |
|
.Include(p => p.Channel) |
|
.Include(p => p.Items) |
|
.Include(p => p.Anchor) |
|
.Include(p => p.ProgramScheduleAnchors) |
|
.SelectOneAsync(p => p.Channel.Number, p => p.Channel.Number == request.ChannelNumber); |
|
|
|
foreach (Playout playout in maybePlayout) |
|
{ |
|
playoutTimeShifter.TimeShift(playout, request.Now, request.Force); |
|
await dbContext.SaveChangesAsync(cancellationToken); |
|
} |
|
|
|
return Option<BaseError>.None; |
|
} |
|
catch (Exception ex) |
|
{ |
|
return BaseError.New(ex.Message); |
|
} |
|
} |
|
}
|
|
|