public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Tests/GetMediaEncoderStandard")] HttpRequest req, ILogger log) #pragma warning restore CA1801 { var processorName = "Media Encoder Standard"; string processorId; try { processorId = await _mediaServicesV2RestSharp.GetLatestMediaProcessorAsync(processorName).ConfigureAwait(false); } catch (Azure.RequestFailedException e) when(e.ErrorCode == "AuthorizationPermissionMismatch") { return(new BadRequestObjectResult(new { error = $"{nameof(GetMediaEncoderStandard)} requires the identity principal to have appropriate rights.\n\n\nException.Message:\n\n{e.Message}\n\nInnerException.Message:\n{e.InnerException?.Message}" })); } catch (Exception e) { return(new BadRequestObjectResult(new { error = $"Exception.Message:\n{e.Message}\n\nInnerException.Message:\n{e.InnerException?.Message}" })); } log.LogInformation($"processorName: {processorName}, processorId: {processorId}"); return(new OkObjectResult(new { processorName, processorId })); }
/// <inheritdoc/> public async Task <string> SubmitMesJobAsync(string inputAssetId, string preset, string outputAssetName, string outputAssetStorageAccountName = null, Uri callbackEndpoint = null, IDictionary <string, string> correlationData = null) { if (string.IsNullOrWhiteSpace(inputAssetId)) { throw new ArgumentException($@"{nameof(inputAssetId)} is invalid", nameof(inputAssetId)); } if (string.IsNullOrWhiteSpace(preset)) { throw new ArgumentException($@"{nameof(preset)} is invalid", nameof(preset)); } _ = outputAssetName ?? throw new ArgumentNullException(nameof(outputAssetName)); string jobName; try { jobName = GenerateJobName(outputAssetName); } catch (Exception e) { throw new Exception($"Could not define job name from {outputAssetName}.", e); } string processorId; try { processorId = await _mediaServicesV2RestSharp.GetLatestMediaProcessorAsync("Media Encoder Standard").ConfigureAwait(false); } catch (Exception e) { _log.LogError(e, $"Could not get media processor."); throw new Exception($"Could not get media processor.", e); } string base64UrlEncodedCorrelationDataJsonString; try { var correlationDataJsonString = JsonConvert.SerializeObject(correlationData); base64UrlEncodedCorrelationDataJsonString = Base64UrlEncoder.Encode(correlationDataJsonString); if (base64UrlEncodedCorrelationDataJsonString.Length > 4000) { const string ErrorMsg = "UrlEncoded and serialized correlationData is larger than 4000"; _log.LogError(ErrorMsg); throw new ArgumentException(ErrorMsg, nameof(correlationData)); } } catch (Exception e) { _log.LogError(e, $"Could not convert correlationData."); throw new Exception($"Could not convert correlationData.", e); } string notificationEndPointId = string.Empty; if (callbackEndpoint != null) { try { notificationEndPointId = await _mediaServicesV2RestSharp.GetOrCreateNotificationEndPointAsync("AmsV2Callback", callbackEndpoint).ConfigureAwait(false); } catch (Exception e) { _log.LogError(e, callbackEndpoint.ToString()); throw new Exception($"Could not create notification endpoint for {callbackEndpoint}", e); } } string jobId; string jobParams = $"{jobName} {processorId} {inputAssetId} {preset} {outputAssetName} {outputAssetStorageAccountName} {base64UrlEncodedCorrelationDataJsonString} {notificationEndPointId}"; try { jobId = await _mediaServicesV2RestSharp.CreateJobAsync( jobName, processorId, inputAssetId, preset, outputAssetName, outputAssetStorageAccountName, correlationData : base64UrlEncodedCorrelationDataJsonString, notificationEndPointId).ConfigureAwait(false); } catch (Exception e) { _log.LogError(e, jobParams); throw new Exception($"Could not start media encoder standard job.", e); } _log.LogInformation($"Started {jobId} with {jobParams}"); return(jobId); }