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); }
private async Task <PlayoutViewModel> ApplyUpdateRequest(Playout p, UpdatePlayout update) { p.ChannelId = update.ChannelId; p.ProgramScheduleId = update.ProgramScheduleId; p.ProgramSchedulePlayoutType = update.ProgramSchedulePlayoutType; await _playoutRepository.Update(p); await _channel.WriteAsync(new BuildPlayout(p.Id)); return(ProjectToViewModel(p)); }
private async Task <Validation <BaseError, Playout> > Validate(UpdatePlayout request) => (await PlayoutMustExist(request), await ChannelMustExist(request), await ProgramScheduleMustExist(request),
public Task <Either <BaseError, PlayoutViewModel> > Handle( UpdatePlayout request, CancellationToken cancellationToken) => Validate(request) .MapT(c => ApplyUpdateRequest(c, request)) .Bind(v => v.ToEitherAsync());
/// <summary> /// /// </summary> /// <exception cref="ErsatzTV.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="updatePlayout"></param> /// <param name="cancellationToken">Cancellation Token to cancel the request.</param> /// <returns>Task of ApiResponse (PlayoutViewModel)</returns> public async System.Threading.Tasks.Task <ErsatzTV.Api.Sdk.Client.ApiResponse <PlayoutViewModel> > ApiPlayoutsPatchWithHttpInfoAsync(UpdatePlayout updatePlayout, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { // verify the required parameter 'updatePlayout' is set if (updatePlayout == null) { throw new ErsatzTV.Api.Sdk.Client.ApiException(400, "Missing required parameter 'updatePlayout' when calling PlayoutApi->ApiPlayoutsPatch"); } 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 = updatePlayout; // make the HTTP request var localVarResponse = await this.AsynchronousClient.PatchAsync <PlayoutViewModel>("/api/playouts", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false); if (this.ExceptionFactory != null) { Exception _exception = this.ExceptionFactory("ApiPlayoutsPatch", 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="updatePlayout"></param> /// <param name="cancellationToken">Cancellation Token to cancel the request.</param> /// <returns>Task of PlayoutViewModel</returns> public async System.Threading.Tasks.Task <PlayoutViewModel> ApiPlayoutsPatchAsync(UpdatePlayout updatePlayout, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { ErsatzTV.Api.Sdk.Client.ApiResponse <PlayoutViewModel> localVarResponse = await ApiPlayoutsPatchWithHttpInfoAsync(updatePlayout, cancellationToken).ConfigureAwait(false); return(localVarResponse.Data); }
/// <summary> /// /// </summary> /// <exception cref="ErsatzTV.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="updatePlayout"></param> /// <returns>PlayoutViewModel</returns> public PlayoutViewModel ApiPlayoutsPatch(UpdatePlayout updatePlayout) { ErsatzTV.Api.Sdk.Client.ApiResponse <PlayoutViewModel> localVarResponse = ApiPlayoutsPatchWithHttpInfo(updatePlayout); return(localVarResponse.Data); }