private async Task <Either <Error, Unit> > EnsureScheduleExistsAsync(CancellationToken cancellationToken)
        {
            var programScheduleApi = new ProgramScheduleApi(_serverUrl);

            Option <ProgramScheduleViewModel> maybeExisting = await programScheduleApi
                                                              .ApiSchedulesGetAsync(cancellationToken)
                                                              .Map(list => list.SingleOrDefault(schedule => schedule.Name == Name));

            await maybeExisting.Match(
                existing =>
            {
                // TODO: update playback order if changed?
                _logger.LogInformation("Schedule {Schedule} is already present", Name);

                if (Reset)
                {
                    return(programScheduleApi
                           .ApiSchedulesProgramScheduleIdItemsDeleteAsync(existing.Id, cancellationToken)
                           .Iter(_ => _logger.LogInformation("Successfully reset schedule {Schedule}", Name)));
                }

                return(Task.CompletedTask);
            },
                () =>
            {
                var data = new CreateProgramSchedule(Name, Order);
                return(programScheduleApi.ApiSchedulesPostAsync(data, cancellationToken)
                       .Iter(_ => _logger.LogInformation("Successfully created schedule {Schedule}", Name)));
            });

            return(unit);
        }
示例#2
0
        private async Task <Option <ProgramScheduleViewModel> > GetSchedule(CancellationToken cancellationToken)
        {
            var programScheduleApi = new ProgramScheduleApi(_serverUrl);

            return(await programScheduleApi.ApiSchedulesGetAsync(cancellationToken)
                   .Map(list => list.SingleOrDefault(schedule => schedule.Name == ScheduleName)));
        }
示例#3
0
        private async ValueTask BuildPlayout(CancellationToken cancellationToken, ChannelViewModel channel)
        {
            var programScheduleApi = new ProgramScheduleApi(_serverUrl);
            Option <ProgramScheduleViewModel> maybeSchedule = await programScheduleApi
                                                              .ApiSchedulesGetAsync(cancellationToken)
                                                              .Map(list => list.SingleOrDefault(s => s.Name == ScheduleName));

            await maybeSchedule.Match(
                schedule => SynchronizePlayoutAsync(channel.Id, schedule.Id, cancellationToken),
                () =>
            {
                _logger.LogError("Unable to locate schedule {Schedule}", ScheduleName);
                return(ValueTask.CompletedTask);
            });
        }