/// <summary> /// Publishes the provided event to a topic. Topic configuration will be fetched from the application settings using this object's /// <see cref="ISettingsProvider"/>. /// </summary> /// <param name="eventToPublish">The event to be published.</param> /// <returns>A boolean indicating if the operation was run successfully.</returns> /// <exception cref="ArgumentException">If the configuration for the topic cannot be found in the settings.</exception> public async Task <bool> PublishEventToTopic(EventGridEvent eventToPublish) { _ = eventToPublish ?? throw new ArgumentNullException(nameof(eventToPublish)); var eventInfo = new { eventToPublish.Id, eventToPublish.EventType, eventToPublish.DataVersion }; try { var topicKey = _settingsProvider.GetAppSettingsValue(Publishing.TopicOutboundKeySettingName); _ = topicKey ?? throw new ArgumentException($"No topic key was found for topic with name {Publishing.TopicOutbound}"); var topicEndPointString = _settingsProvider.GetAppSettingsValue(Publishing.TopicOutboundEndpointSettingName); _ = topicEndPointString ?? throw new ArgumentException($"No topic endpoint was found for topic with name {Publishing.TopicOutbound}"); Uri.TryCreate(topicEndPointString, UriKind.Absolute, out Uri topicEndPoint); _ = topicEndPoint ?? throw new ArgumentException($"Failed to parse Uri for topic with name {Publishing.TopicOutbound}"); var eventGridClient = _eventGridClientProvider.GetEventGridClientForTopic(Publishing.TopicOutbound, topicKey); _logger.LogEventObject(LogEventIds.AboutToAttemptPublishOfEventWithId, eventInfo); await eventGridClient.PublishEventsAsync(topicEndPoint.Host, new List <EventGridEvent>() { eventToPublish }).ConfigureAwait(false); _logger.LogEventObject(LogEventIds.PublishedEvent, eventInfo); return(true); } catch (Exception e) { _logger.LogExceptionObject(LogEventIds.ExceptionPublishingEvent, e, eventInfo); return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="MediaServicesV3SdkWrapper"/> class. /// </summary> /// <param name="log">Logging object.</param> /// <param name="settingsProvider">Settings object.</param> public MediaServicesV3SdkWrapper(ISettingsProvider settingsProvider) { _settingsProvider = settingsProvider ?? throw new ArgumentNullException(nameof(settingsProvider)); _amsResourceGroup = settingsProvider.GetAppSettingsValue("AmsResourceGroup"); _amsAccountName = settingsProvider.GetAppSettingsValue("AmsAccountName"); _amsAadClientId = _settingsProvider.GetAppSettingsValue("AmsAadClientId"); _amsAadClientSecret = _settingsProvider.GetAppSettingsValue("AmsAadClientSecret"); _amsAadTenantId = _settingsProvider.GetAppSettingsValue("AmsAadTenantId"); _amsArmEndpoint = _settingsProvider.GetAppSettingsValue("AmsArmEndpoint"); _amsSubscriptionId = _settingsProvider.GetAppSettingsValue("AmsSubscriptionId"); }
/// <summary> /// Initializes a new instance of the <see cref="MediaServicesV2RestWrapper"/> class. /// </summary> /// <param name="log">log.</param> /// <param name="settingsProvider">settingsProvider.</param> /// <param name="tokenCredential">TokenCredential.</param> public MediaServicesV2RestWrapper( IObjectLogger <MediaServicesV2RestWrapper> log, ISettingsProvider settingsProvider, TokenCredential tokenCredential) { _log = log ?? throw new ArgumentNullException(nameof(log)); _settingsProvider = settingsProvider ?? throw new ArgumentNullException(nameof(settingsProvider)); _tokenCredential = tokenCredential; var amsAccountName = _settingsProvider.GetAppSettingsValue("AmsAccountName"); var amsLocation = _settingsProvider.GetAppSettingsValue("AmsLocation"); var baseUrl = $"https://{amsAccountName}.restv2.{amsLocation}.media.azure.net/api/"; _restClient = new RestClient(baseUrl); }
private void InitializeSDKs() { var apiKey = _settingsProvider.GetAppSettingsValue(EnvKey); if (string.IsNullOrWhiteSpace(apiKey)) { var message = $"{EnvKey}: is null or empty"; _log.LogEvent(LogEventIds.CloudPortApiError, message); throw new ArgumentNullException(LogEventIds.CloudPortApiError.Name, message); } Telestream.Cloud.Stores.Client.Configuration storesConfiguration = new Telestream.Cloud.Stores.Client.Configuration(); storesConfiguration.ApiKey.Add("X-Api-Key", apiKey); CloudPortStoresApi = new StoresApi(storesConfiguration); // Notifications are not being used just yet, but we include them now for future possibilies. Telestream.Cloud.Notifications.Client.Configuration notificationsConfiguration = new Telestream.Cloud.Notifications.Client.Configuration(); notificationsConfiguration.ApiKey.Add("X-Api-Key", apiKey); CloudPortNotificationsApi = new NotificationsApi(notificationsConfiguration); Telestream.Cloud.VantageCloudPort.Client.Configuration cloudPortConfiguration = new Telestream.Cloud.VantageCloudPort.Client.Configuration(); cloudPortConfiguration.ApiKey.Add("X-Api-Key", apiKey); CloudPortApi = new Telestream.Cloud.VantageCloudPort.Api.VantageCloudPortApi(cloudPortConfiguration); Telestream.Cloud.Flip.Client.Configuration flipConfiguration = new Telestream.Cloud.Flip.Client.Configuration(); flipConfiguration.ApiKey.Add("X-Api-Key", apiKey); FlipApi = new FlipApi(flipConfiguration); }
/// <summary> /// Initializes a new instance of the <see cref="MediaServicesV3PublicationService"/> class. /// </summary> /// <param name="mediaServicesV3ContentKeyPolicyService">Content key policy service.</param> /// <param name="mediaServicesV3StreamingPolicyService">Streaming policy service.</param> /// <param name="mediaServicesV3SdkWrapper">Media Services V3 Wrapper object.</param> /// <param name="storageService">Storage service.</param> /// <param name="settingsProvider">Settings Provider service.</param> /// <param name="log">Logger.</param> public MediaServicesV3PublicationService( IMediaServicesV3ContentKeyPolicyService mediaServicesV3ContentKeyPolicyService, IMediaServicesV3CustomStreamingPolicyService mediaServicesV3StreamingPolicyService, IMediaServicesV3SdkWrapper mediaServicesV3SdkWrapper, IStorageService storageService, ISettingsProvider settingsProvider, IObjectLogger <MediaServicesV3BaseService> log) : base(mediaServicesV3SdkWrapper, log) { _mediaServicesV3ContentKeyPolicyService = mediaServicesV3ContentKeyPolicyService; _mediaServicesV3StreamingPolicyService = mediaServicesV3StreamingPolicyService; _settingsProvider = settingsProvider; _storageService = storageService; environmentType = _settingsProvider?.GetAppSettingsValue(EnvironmentTypeConstants.EnvironmentTypeSettingName); enableContentKeyPolicyAutomaticUpdate = _settingsProvider?.GetAppSettingsValue("AmsDrmEnableContentKeyPolicyUpdate")?.ToUpperInvariant() == "TRUE"; }
/// <summary> /// Initializes a new instance of the <see cref="MediaServicesV3ContentKeyPolicyService"/> class. /// </summary> /// <param name="settingsProvider">Settings provider.</param> /// <param name="log">Log provider.</param> /// <param name="identity">Identity provider.</param> public MediaServicesV3ContentKeyPolicyService(ISettingsProvider settingsProvider, IObjectLogger <MediaServicesV3ContentKeyPolicyService> log) { _log = log ?? throw new ArgumentNullException(nameof(log)); _ = settingsProvider ?? throw new ArgumentNullException(nameof(settingsProvider)); _amsDrmOpenIdConnectDiscoveryDocument = settingsProvider.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument"); _amsDrmFairPlayPfxPassword = settingsProvider.GetAppSettingsValue("AmsDrmFairPlayPfxPassword"); _amsDrmFairPlayAskHex = settingsProvider.GetAppSettingsValue("AmsDrmFairPlayAskHex"); _amsDrmFairPlayCertificateB64 = settingsProvider.GetAppSettingsValue("AmsDrmFairPlayCertificateB64"); if (string.IsNullOrEmpty(_amsDrmOpenIdConnectDiscoveryDocument)) { const string Message = "AmsDrmOpenIdConnectDiscoveryDocument is null or empty."; _log.LogEvent(LogEventIds.MediaServicesV3ConfigurationError, Message); throw new ArgumentException(Message); } if (string.IsNullOrEmpty(_amsDrmFairPlayPfxPassword)) { const string Message = "AmsDrmFairPlayPfxPassword is null or empty."; _log.LogEvent(LogEventIds.MediaServicesV3ConfigurationError, Message); throw new ArgumentException(Message); } if (string.IsNullOrEmpty(_amsDrmFairPlayAskHex)) { const string Message = "AmsDrmFairPlayAskHex is null or empty."; _log.LogEvent(LogEventIds.MediaServicesV3ConfigurationError, Message); throw new ArgumentException(Message); } if (string.IsNullOrEmpty(_amsDrmFairPlayCertificateB64)) { const string Message = "AmsDrmFairPlayCertificateB64 is null or empty."; _log.LogEvent(LogEventIds.MediaServicesV3ConfigurationError, Message); throw new ArgumentException(Message); } }
/// <summary> /// EncodeAsync does the heavy lifting to encode and process a video asset. /// </summary> /// <param name="encodeCreateDTO">encodeCreateDTO.</param> /// <returns>Returns true if encode request was successful, otherwise false.</returns> public async Task <ServiceOperationResultEncodeDispatched> EncodeCreateAsync(RequestMediaServicesV2EncodeCreateDTO encodeCreateDTO) { _ = encodeCreateDTO ?? throw new ArgumentNullException(nameof(encodeCreateDTO)); List <Uri> sourceUris = new List <Uri>(); try { sourceUris = encodeCreateDTO.Inputs.ToList().Select(u => new Uri(u.BlobUri)).ToList(); } catch (Exception e) { throw new GridwichEncodeCreateJobException($"Failed to parse Inputs", encodeCreateDTO.OperationContext, e, LogEventIds.MediaServicesV2InputError); } string inputAssetId = await _mediaServicesV2Service.CopyFilesIntoNewAsset(sourceUris).ConfigureAwait(false); var presetName = encodeCreateDTO.PresetName; TimeSpan?thumbnailTimeSpan; if (encodeCreateDTO.ThumbnailTimeSeconds == 0) { thumbnailTimeSpan = null; } else { if (encodeCreateDTO.ThumbnailTimeSeconds < 0) { throw new GridwichTimeParameterException(nameof(encodeCreateDTO.ThumbnailTimeSeconds), encodeCreateDTO.ThumbnailTimeSeconds, "Must be above zero."); } thumbnailTimeSpan = TimeSpan.FromSeconds(encodeCreateDTO.ThumbnailTimeSeconds); } var preset = _mediaServicesPreset.GetPresetForPresetName(presetName, thumbnailTimeSpan); if (string.IsNullOrEmpty(preset)) { throw new GridwichEncodeCreateJobException($"Failed for PresetName {presetName}", encodeCreateDTO.OperationContext, null, LogEventIds.MediaServicesV2PresetError); } string jobId; try { Uri callbackEndpoint = new Uri(_settingsProvider.GetAppSettingsValue("AmsV2CallbackEndpoint")); var outputContainer = new Uri(encodeCreateDTO.OutputContainer); var correlationData = new Dictionary <string, string>() { { "outputAssetContainer", outputContainer.ToString() }, { "operationContext", encodeCreateDTO.OperationContext.ToString() }, }; jobId = await _mediaServicesV2Service.SubmitMesJobAsync( inputAssetId, preset, outputContainer, callbackEndpoint, correlationData).ConfigureAwait(false); } catch (Exception e) { throw new GridwichEncodeCreateJobException($"Failed to create job.", encodeCreateDTO.OperationContext, e, LogEventIds.MediaServicesV2CreateJobError); } _log.LogEvent(LogEventIds.MediaServicesV2JobSubmitCalled, jobId); return(new ServiceOperationResultEncodeDispatched( workflowJobName: jobId, null, encodeCreateDTO.OperationContext)); }
/// <inheritdoc/> public override Uri CreateUrl(string query) { var urlEncodedB64string = CompressAppInsightsQuery(query); // Compose the URL var result = $@"https://portal.azure.com/#blade/Microsoft_Azure_Monitoring_Logs/LogsBlade/resourceId/{_settings.GetAppSettingsValue(@"AppInsights_ResourceId")}/source/LogsBlade.AnalyticsShareLinkToQuery/q/{urlEncodedB64string}"; return(new Uri(result)); }