private async ValueTask SynchronizePlayoutAsync( int channelId, int scheduleId, CancellationToken cancellationToken) { var playoutApi = new PlayoutApi(_serverUrl); Option <PlayoutViewModel> maybeExisting = await playoutApi.ApiPlayoutsGetAsync(cancellationToken) .Map(list => list.SingleOrDefault(p => p.Channel.Id == channelId)); await maybeExisting.Match( existing => { var data = new UpdatePlayout(existing.Id, channelId, scheduleId, ProgramSchedulePlayoutType.Flood); if (existing.Channel.Id != data.ChannelId || existing.ProgramSchedule.Id != data.ProgramScheduleId || existing.ProgramSchedulePlayoutType != data.ProgramSchedulePlayoutType) { return(playoutApi.ApiPlayoutsPatchAsync(data, cancellationToken)); } return(Task.CompletedTask); }, () => { var data = new CreatePlayout(channelId, scheduleId, ProgramSchedulePlayoutType.Flood); return(playoutApi.ApiPlayoutsPostAsync(data, cancellationToken)); }); _logger.LogInformation("Successfully built playout for schedule {Schedule}", ScheduleName); }
public async Task <Either <BaseError, CreatePlayoutResponse> > Handle( CreatePlayout request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Playout> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, playout => PersistPlayout(dbContext, playout))); }
private async Task <Validation <BaseError, Playout> > Validate(CreatePlayout request) => (await ChannelMustExist(request), await ProgramScheduleMustExist(request), ValidatePlayoutType(request))
public Task <Either <BaseError, PlayoutViewModel> > Handle( CreatePlayout request, CancellationToken cancellationToken) => Validate(request) .MapT(PersistPlayout) .Bind(v => v.ToEitherAsync());
private async Task <Validation <BaseError, Playout> > Validate(TvContext dbContext, CreatePlayout request) => (await ValidateChannel(dbContext, request), await ValidateProgramSchedule(dbContext, request),
/// <summary> /// /// </summary> /// <exception cref="ErsatzTV.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="createPlayout"></param> /// <returns>ApiResponse of PlayoutViewModel</returns> public ErsatzTV.Api.Sdk.Client.ApiResponse <PlayoutViewModel> ApiPlayoutsPostWithHttpInfo(CreatePlayout createPlayout) { // verify the required parameter 'createPlayout' is set if (createPlayout == null) { throw new ErsatzTV.Api.Sdk.Client.ApiException(400, "Missing required parameter 'createPlayout' when calling PlayoutApi->ApiPlayoutsPost"); } ErsatzTV.Api.Sdk.Client.RequestOptions localVarRequestOptions = new ErsatzTV.Api.Sdk.Client.RequestOptions(); String[] _contentTypes = new String[] { "application/json-patch+json", "application/json", "text/json", "application/_*+json" }; // to determine the Accept header String[] _accepts = new String[] { "application/json" }; var localVarContentType = ErsatzTV.Api.Sdk.Client.ClientUtils.SelectHeaderContentType(_contentTypes); if (localVarContentType != null) { localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); } var localVarAccept = ErsatzTV.Api.Sdk.Client.ClientUtils.SelectHeaderAccept(_accepts); if (localVarAccept != null) { localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); } localVarRequestOptions.Data = createPlayout; // make the HTTP request var localVarResponse = this.Client.Post <PlayoutViewModel>("/api/playouts", localVarRequestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception _exception = this.ExceptionFactory("ApiPlayoutsPost", localVarResponse); if (_exception != null) { throw _exception; } } return(localVarResponse); }
/// <summary> /// /// </summary> /// <exception cref="ErsatzTV.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="createPlayout"></param> /// <returns>PlayoutViewModel</returns> public PlayoutViewModel ApiPlayoutsPost(CreatePlayout createPlayout) { ErsatzTV.Api.Sdk.Client.ApiResponse <PlayoutViewModel> localVarResponse = ApiPlayoutsPostWithHttpInfo(createPlayout); return(localVarResponse.Data); }
/// <summary> /// /// </summary> /// <exception cref="ErsatzTV.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="createPlayout"></param> /// <param name="cancellationToken">Cancellation Token to cancel the request.</param> /// <returns>Task of PlayoutViewModel</returns> public async System.Threading.Tasks.Task <PlayoutViewModel> ApiPlayoutsPostAsync(CreatePlayout createPlayout, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { ErsatzTV.Api.Sdk.Client.ApiResponse <PlayoutViewModel> localVarResponse = await ApiPlayoutsPostWithHttpInfoAsync(createPlayout, cancellationToken).ConfigureAwait(false); return(localVarResponse.Data); }