public NotificationEndPoint(string id, string name, NotificationEndPointType endPointType, string endPointAddress) { Id = id; Name = name; EndPointType = (int)endPointType; EndPointAddress = endPointAddress; }
public NotificationEndPoint(string name, NotificationEndPointType endPointType, string endPointAddress) { _id = string.Empty; Name = name; EndPointType = (int)endPointType; EndPointAddress = endPointAddress; }
/// <summary> /// Creates a notification endpoint asynchronously /// </summary> /// <param name="name">Name of notification endpoint</param> /// <param name="endPointType">Notification endpoint type</param> /// <param name="endPointAddress">Notification endpoint address</param> /// <returns>Task of creating notification endpoint.</returns> public Task <INotificationEndPoint> CreateAsync(string name, NotificationEndPointType endPointType, string endPointAddress) { NotificationEndPoint notificationEndPoint = new NotificationEndPoint { Name = name, EndPointType = (int)endPointType, EndPointAddress = endPointAddress }; notificationEndPoint.SetMediaContext(MediaContext); IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AddObject(NotificationEndPoints, notificationEndPoint); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>( () => dataContext.SaveChangesAsync(notificationEndPoint)) .ContinueWith <INotificationEndPoint>( t => { t.ThrowIfFaulted(); return (NotificationEndPoint)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Create a notification endpoint object in asynchronous mode. /// </summary> /// <param name="name">Name of notification endpoint</param> /// <param name="endPointType">Notification endpoint type</param> /// <param name="endPointAddress">Notification endpoint address</param> /// <returns>Task of creating notification endpoint.</returns> public Task <INotificationEndPoint> CreateAsync(string name, NotificationEndPointType endPointType, string endPointAddress) { NotificationEndPoint notificationEndPoint = new NotificationEndPoint { Name = name, EndPointType = (int)endPointType, EndPointAddress = endPointAddress }; notificationEndPoint.InitCloudMediaContext(_cloudMediaContext); DataServiceContext dataContext = DataContextFactory.CreateDataServiceContext(); dataContext.AddObject(NotificationEndPoints, notificationEndPoint); return(dataContext .SaveChangesAsync(notificationEndPoint) .ContinueWith <INotificationEndPoint>( t => { t.ThrowIfFaulted(); return (NotificationEndPoint)t.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Create a notification endpoint object. /// </summary> /// <param name="name">Name of notification endpoint</param> /// <param name="endPointType">Notification endpoint type</param> /// <param name="endPointAddress">Notification endpoint address</param> /// <returns>Notification endpoint object</returns> public INotificationEndPoint Create(string name, NotificationEndPointType endPointType, string endPointAddress) { try { Task <INotificationEndPoint> task = CreateAsync(name, endPointType, endPointAddress); task.Wait(); return(task.Result); } catch (AggregateException exception) { throw exception.InnerException; } }
/// <summary> /// Create a notification endpoint object in asynchronous mode. /// </summary> /// <param name="name">Name of notification endpoint</param> /// <param name="endPointType">Notification endpoint type</param> /// <param name="endPointAddress">Notification endpoint address</param> /// <param name="credential"></param> /// <returns>Task of creating notification endpoint.</returns> public Task <INotificationEndPoint> CreateAsync(string name, NotificationEndPointType endPointType, string endPointAddress, byte[] credential) { if (credential == null || credential.Length == 0) { throw new ArgumentNullException("credential"); } if (endPointType != NotificationEndPointType.WebHook) { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, StringTable.SupportWebHookWithCredentialOnly, "endPointType")); } IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); string protectionKeyId = ContentKeyBaseCollection.GetProtectionKeyIdForContentKey(MediaContext, ContentKeyType.ConfigurationEncryption); X509Certificate2 certToUse = ContentKeyBaseCollection.GetCertificateForProtectionKeyId(MediaContext, protectionKeyId); byte[] encryptedContentKey = EncryptionUtils.EncryptSymmetricKeyData(certToUse, credential); NotificationEndPoint notificationEndPoint = new NotificationEndPoint { Name = name, EndPointType = (int)endPointType, EndPointAddress = endPointAddress, CredentialType = (int)NotificationEndPointCredentialType.SigningKey, EncryptedEndPointCredential = Convert.ToBase64String(encryptedContentKey), ProtectionKeyType = (int)ProtectionKeyType.X509CertificateThumbprint, ProtectionKeyId = protectionKeyId }; notificationEndPoint.SetMediaContext(MediaContext); dataContext.AddObject(NotificationEndPoints, notificationEndPoint); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>( () => dataContext.SaveChangesAsync(notificationEndPoint)) .ContinueWith <INotificationEndPoint>( t => { t.ThrowIfFaulted(); return (NotificationEndPoint)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
private INotificationEndPoint GetNotificationEndpoint() { string endpointName = Constant.Media.JobNotification.EndpointName; INotificationEndPoint notificationEndpoint = GetEntityByName(MediaEntity.NotificationEndpoint, endpointName) as INotificationEndPoint; if (notificationEndpoint == null) { NotificationEndPointType endpointType = NotificationEndPointType.WebHook; string settingKey = Constant.AppSettingKey.MediaPublishContentUrl; string endpointAddress = AppSetting.GetValue(settingKey); notificationEndpoint = _media.NotificationEndPoints.Create(endpointName, endpointType, endpointAddress); } return(notificationEndpoint); }
private INotificationEndPoint GetNotificationEndpoint(NotificationEndPointType endpointType) { string endpointName = Constants.Media.JobNotification.EndpointNameStorageQueue; string settingKey = Constants.AppSettingKey.MediaJobNotificationStorageQueueName; string endpointAddress = AppSetting.GetValue(settingKey); if (endpointType == NotificationEndPointType.WebHook) { endpointName = Constants.Media.JobNotification.EndpointNameWebHook; settingKey = Constants.AppSettingKey.MediaJobNotificationWebHookUrl; endpointAddress = AppSetting.GetValue(settingKey); } INotificationEndPoint notificationEndpoint = null; if (!string.IsNullOrEmpty(endpointAddress)) { notificationEndpoint = GetEntityByName(MediaEntity.NotificationEndpoint, endpointName, true) as INotificationEndPoint; if (notificationEndpoint == null) { notificationEndpoint = _media.NotificationEndPoints.Create(endpointName, endpointType, endpointAddress); } } return(notificationEndpoint); }