/// <summary> /// Asynchronously creates an <see cref="IAssetDeliveryPolicy"/>. /// </summary> /// <param name="name">Friendly name for the policy.</param> /// <param name="policyType">Type of the policy.</param> /// <param name="deliveryProtocol">Delivery protocol.</param> /// <param name="configuration">Configuration.</param> /// <returns>An <see cref="IAssetDeliveryPolicy"/>.</returns> public Task <IAssetDeliveryPolicy> CreateAsync( string name, AssetDeliveryPolicyType policyType, AssetDeliveryProtocol deliveryProtocol, Dictionary <AssetDeliveryPolicyConfigurationKey, string> configuration) { IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); var policy = new AssetDeliveryPolicyData { Name = name, }; ((IAssetDeliveryPolicy)policy).AssetDeliveryPolicyType = policyType; ((IAssetDeliveryPolicy)policy).AssetDeliveryProtocol = deliveryProtocol; ((IAssetDeliveryPolicy)policy).AssetDeliveryConfiguration = configuration; policy.SetMediaContext(this.MediaContext); dataContext.AddObject(DeliveryPolicySet, policy); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(policy)) .ContinueWith <IAssetDeliveryPolicy>( t => { t.ThrowIfFaulted(); return (AssetDeliveryPolicyData)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Asynchronously creates an <see cref="IContentKeyAuthorizationPolicyOption"/> with the provided name and permissions, valid for the provided duration. /// </summary> /// <param name="name">Specifies a friendly name for the PolicyOption.</param> /// <param name="deliveryType">Delivery method of the content key to the client.</param> /// <param name="restrictions">Authorization restrictions.</param> /// <param name="keyDeliveryConfiguration">Xml data, specific to the key delivery type that defines how the key is delivered to the client.</param> /// <returns>A function delegate that returns the future result to be available through the Task<IContentKeyAuthorizationPolicyOption>.</returns> public Task <IContentKeyAuthorizationPolicyOption> CreateAsync( string name, ContentKeyDeliveryType deliveryType, List <ContentKeyAuthorizationPolicyRestriction> restrictions, string keyDeliveryConfiguration) { IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); var policyOption = new ContentKeyAuthorizationPolicyOptionData { Name = name, Restrictions = restrictions, KeyDeliveryConfiguration = keyDeliveryConfiguration }; ((IContentKeyAuthorizationPolicyOption)policyOption).KeyDeliveryType = deliveryType; policyOption.SetMediaContext(this.MediaContext); dataContext.AddObject(ContentKeyAuthorizationPolicyOptionSet, policyOption); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(policyOption)) .ContinueWith <IContentKeyAuthorizationPolicyOption>( t => { t.ThrowIfFaulted(); return (ContentKeyAuthorizationPolicyOptionData)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Submits asynchronously. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task <IJob> SubmitAsync() { if (!string.IsNullOrWhiteSpace(this.Id)) { // The job was already submitted. throw new InvalidOperationException(StringTable.InvalidOperationSubmitForSubmittedJob); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); this.InnerSubmit(dataContext); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(SaveChangesOptions.Batch, this)) .ContinueWith( t => { t.ThrowIfFaulted(); JobData data = (JobData)t.Result.AsyncState; data.Refresh(); return (IJob)data; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Asynchronously creates new StreamingFilter. /// </summary> /// <param name="name">filter name</param> /// <param name="timeRange">filter boundaries</param> /// <param name="trackConditions">filter track conditions</param> /// <returns>The task to create the filter.</returns> public Task <IStreamingAssetFilter> CreateAsync(string name, PresentationTimeRange timeRange, IList <FilterTrackSelectStatement> trackConditions) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } AssetFilterData filter = new AssetFilterData(_parentAsset.Id, name, timeRange, trackConditions); filter.SetMediaContext(MediaContext); IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AddObject(AssetFilterSet, filter); MediaRetryPolicy retryPolicy = MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(filter)) .ContinueWith <IStreamingAssetFilter>( t => { t.ThrowIfFaulted(); return (AssetFilterData)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Asynchronously revokes the specified Locator, denying any access it provided. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task<ILocator>.</returns> public Task DeleteAsync() { LocatorBaseCollection.VerifyLocator(this); IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(LocatorBaseCollection.LocatorSet, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)) .ContinueWith( t => { t.ThrowIfFaulted(); LocatorData data = (LocatorData)t.Result.AsyncState; if (GetMediaContext() != null) { var cloudContextAsset = (AssetData)GetMediaContext().Assets.Where(c => c.Id == data.AssetId).FirstOrDefault(); if (cloudContextAsset != null) { cloudContextAsset.InvalidateLocatorsCollection(); } } if (data.Asset != null) { data.Asset.InvalidateLocatorsCollection(); } }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <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> /// Asynchronously saves this <see cref="IJobTemplate"/> when created from a copy of an existing <see cref="IJobTemplate"/>. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task SaveAsync() { if (!string.IsNullOrWhiteSpace(this.Id)) { // The job template was already saved, and there is no current support to update it. throw new InvalidOperationException(StringTable.InvalidOperationSaveForSavedJobTemplate); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); this.InnerSave(dataContext); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(SaveChangesOptions.Batch, this)) .ContinueWith( t => { t.ThrowIfFaulted(); JobTemplateData data = (JobTemplateData)t.Result.AsyncState; LoadProperty(dataContext, data, TaskTemplatesPropertyName); })); }
/// <summary> /// Creates the manifest async. /// </summary> /// <param name="name">The name.</param> /// <param name="storageAccountName">The name of storage account </param> /// <returns><see cref="Task"/> of type <see cref="IIngestManifest"/></returns> public Task <IIngestManifest> CreateAsync(string name, string storageAccountName) { if (name == null) { throw new ArgumentNullException("name"); } if (storageAccountName == null) { throw new ArgumentNullException("storageAccountName"); } IngestManifestData ingestManifestData = new IngestManifestData { Name = name, StorageAccountName = storageAccountName }; ingestManifestData.SetMediaContext(this.MediaContext); IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AddObject(EntitySet, ingestManifestData); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(ingestManifestData)) .ContinueWith <IIngestManifest>( t => { t.ThrowIfFaulted(); IngestManifestData data = (IngestManifestData)t.Result.AsyncState; return data; })); }
/// <summary> /// Delete this instance of notification endpoint object in asynchronous mode. /// </summary> /// <returns>Task of deleting the notification endpoint.</returns> public Task DeleteAsync() { IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(NotificationEndPointCollection.NotificationEndPoints, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(); return retryPolicy.ExecuteAsync<IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)); }
/// <summary> /// Deletes the manifest asset file asynchronously. /// </summary> /// <returns><see cref="Task"/></returns> public Task DeleteAsync() { IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(IngestManifestFileCollection.EntitySet, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <summary> /// Asynchronously deletes this instance. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task <IMediaDataServiceResponse> DeleteAsync() { IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(ContentKeyAuthorizationPolicyOptionCollection.ContentKeyAuthorizationPolicyOptionSet, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <summary> /// Asynchronously deletes this instance. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task DeleteAsync() { IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(FileSet, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <summary> /// Update the notification endpoint object in asynchronous mode. /// </summary> /// <returns>Task of updating the notification endpoint.</returns> public Task UpdateAsync() { IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateCustomDataServiceContext(); dataContext.AttachTo(NotificationEndPointCollectionV212.NotificationEndPoints, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <summary> /// Deletes this instance asynchronously. /// </summary> public virtual Task <IMediaDataServiceResponse> DeleteAsync() { Validate(); IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(ResourceSetName, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(this))); }
/// <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)); }
/// <summary> /// Asynchronously creates a content key with the specifies key identifier and value. /// </summary> /// <param name="keyId">The key identifier.</param> /// <param name="contentKey">The value of the content key.</param> /// <param name="name">A friendly name for the content key.</param> /// <param name="contentKeyType">Type of content key to create.</param> /// <returns> /// A function delegate that returns the future result to be available through the Task<IContentKey>. /// </returns> public override Task <IContentKey> CreateAsync(Guid keyId, byte[] contentKey, string name, ContentKeyType contentKeyType) { if ((contentKeyType != ContentKeyType.CommonEncryption) && (contentKeyType != ContentKeyType.EnvelopeEncryption)) { throw new ArgumentException(StringTable.ErrorUnsupportedContentKeyType, "contentKey"); } if (keyId == Guid.Empty) { throw new ArgumentException(StringTable.ErrorCreateKey_EmptyGuidNotAllowed, "keyId"); } if (contentKey == null) { throw new ArgumentNullException("contentKey"); } if (contentKey.Length != EncryptionUtils.KeySizeInBytesForAes128) { throw new ArgumentException(StringTable.ErrorCommonEncryptionKeySize, "contentKey"); } IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); X509Certificate2 certToUse = GetCertificateToEncryptContentKey(MediaContext, ContentKeyType.CommonEncryption); ContentKeyData contentKeyData = null; if (contentKeyType == ContentKeyType.CommonEncryption) { contentKeyData = InitializeCommonContentKey(keyId, contentKey, name, certToUse); } else if (contentKeyType == ContentKeyType.EnvelopeEncryption) { contentKeyData = InitializeEnvelopeContentKey(keyId, contentKey, name, certToUse); } dataContext.AddObject(ContentKeySet, contentKeyData); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(contentKeyData)) .ContinueWith <IContentKey>( t => { t.ThrowIfFaulted(); return (ContentKeyData)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Asynchronously updates this instance. /// </summary> /// <returns> /// Task to wait on for operation completion. /// </returns> public Task <IContentKeyAuthorizationPolicy> UpdateAsync() { IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(ContentKeyAuthorizationPolicyCollection.ContentKeyAuthorizationPolicySet, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)) .ContinueWith <IContentKeyAuthorizationPolicy>(t => { return (ContentKeyAuthorizationPolicyData)t.Result.AsyncState; })); }
/// <summary> /// Asynchronously deletes this asset instance. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task DeleteAsync() { AssetCollection.VerifyAsset(this); IMediaDataServiceContext dataContext = this._mediaContextBase.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(AssetCollection.AssetSet, this); this.InvalidateContentKeysCollection(); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this._mediaContextBase.MediaServicesClassFactory.GetSaveChangesRetryPolicy(); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <summary> /// Asynchronously deletes this asset instance. /// </summary> /// <param name="keepAzureStorageContainer">if set to <c>true</c> underlying storage asset container is preserved during the delete operation.</param> /// <returns>Task of type <see cref="IMediaDataServiceResponse"/></returns> public Task <IMediaDataServiceResponse> DeleteAsync(bool keepAzureStorageContainer) { AssetCollection.VerifyAsset(this); AssetDeleteOptionsRequestAdapter deleteRequestAdapter = new AssetDeleteOptionsRequestAdapter(keepAzureStorageContainer); IMediaDataServiceContext dataContext = this._mediaContextBase.MediaServicesClassFactory.CreateDataServiceContext(new[] { deleteRequestAdapter }); dataContext.AttachTo(AssetCollection.AssetSet, this); this.InvalidateContentKeysCollection(); this.InvalidateDeliveryPoliciesCollection(); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this._mediaContextBase.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <summary> /// Deletes this instance asynchronously. /// </summary> public virtual Task DeleteAsync() { if (string.IsNullOrWhiteSpace(Id)) { throw new InvalidOperationException(Resources.ErrorEntityWithoutId); } IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(EntitySetName, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(this))); }
private Task <IMediaDataServiceResponse> CreateChannelAsync(ChannelCreationOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (string.IsNullOrEmpty(options.Name)) { throw new ArgumentException(Resources.ErrorEmptyChannelName); } if (options.Input == null || options.Input.AccessControl == null || options.Input.AccessControl.IPAllowList == null) { throw new ArgumentException(Resources.ErrorEmptyChannelInputIPAllowList); } var channelData = new ChannelData { Name = options.Name, Description = options.Description, CrossSiteAccessPolicies = options.CrossSiteAccessPolicies, Slate = options.Slate, }; IChannel channel = channelData; channel.Input = options.Input; channel.Preview = options.Preview; channel.Output = options.Output; channel.EncodingType = options.EncodingType; channel.Encoding = options.Encoding; channelData.ValidateSettings(); channelData.SetMediaContext(MediaContext); IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AddObject(ChannelSet, channel); MediaRetryPolicy retryPolicy = MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(channel))); }
/// <summary> /// Creates the locator async. /// </summary> /// <param name="locatorId">The locator Id.</param> /// <param name="locatorType">Type of the locator.</param> /// <param name="asset">The asset.</param> /// <param name="accessPolicy">The access policy.</param> /// <param name="startTime">The start time.</param> /// <param name="name">The name.</param> /// <returns>A function delegate that returns the future result to be available through the Task<ILocator>.</returns> public Task <ILocator> CreateLocatorAsync(string locatorId, LocatorType locatorType, IAsset asset, IAccessPolicy accessPolicy, DateTime?startTime, string name = null) { AccessPolicyBaseCollection.VerifyAccessPolicy(accessPolicy); AssetCollection.VerifyAsset(asset); AssetData assetData = (AssetData)asset; LocatorData locator = new LocatorData { AccessPolicy = (AccessPolicyData)accessPolicy, Asset = assetData, Type = (int)locatorType, StartTime = startTime, Name = name }; if (locatorId != null) { locator.Id = LocatorData.NormalizeLocatorId(locatorId); } locator.SetMediaContext(this.MediaContext); IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(AssetCollection.AssetSet, asset); dataContext.AttachTo(AccessPolicyBaseCollection.AccessPolicySet, accessPolicy); dataContext.AddObject(LocatorSet, locator); dataContext.SetLink(locator, AccessPolicyPropertyName, accessPolicy); dataContext.SetLink(locator, AssetPropertyName, asset); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(locator)) .ContinueWith <ILocator>( t => { t.ThrowIfFaulted(); assetData.InvalidateLocatorsCollection(); return (LocatorData)t.Result.AsyncState; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Asynchronously deletes this <see cref="IJobTemplate"/>. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task DeleteAsync() { if (string.IsNullOrWhiteSpace(this.Id)) { // The job template was not saved. throw new InvalidOperationException(StringTable.InvalidOperationDeleteForNotSavedJobTemplate); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(JobTemplateBaseCollection.JobTemplateSet, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
private Task <IJobTemplate> CreateJobTemplate(string templateName, JobTemplateType templateType, params ITaskTemplate[] taskTemplates) { X509Certificate2 certToUse = null; IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); JobTemplateData jobTemplateData = new JobTemplateData { Name = templateName, TemplateType = (int)templateType }; jobTemplateData.SetMediaContext(this.GetMediaContext()); dataContext.AddObject(JobTemplateBaseCollection.JobTemplateSet, jobTemplateData); foreach (ITaskTemplate taskTemplate in taskTemplates) { Verify(taskTemplate); dataContext.AddRelatedObject(jobTemplateData, TaskTemplatesPropertyName, taskTemplate); if (taskTemplate.Options.HasFlag(TaskOptions.ProtectedConfiguration) && string.IsNullOrWhiteSpace(this.Id)) { ProtectTaskConfiguration((TaskTemplateData)taskTemplate, ref certToUse, dataContext); } } AssetNamingSchemeResolver <AssetData, OutputAsset> assetIdMap = new AssetNamingSchemeResolver <AssetData, OutputAsset>(); jobTemplateData.JobTemplateBody = CreateJobTemplateBody(assetIdMap, taskTemplates); jobTemplateData.NumberofInputAssets = string.IsNullOrWhiteSpace(this.Id) ? assetIdMap.Inputs.Count : ((IJob)this).InputMediaAssets.Count; MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(SaveChangesOptions.Batch, jobTemplateData)) .ContinueWith <IJobTemplate>( t => { t.ThrowIfFaulted(); JobTemplateData data = (JobTemplateData)t.Result.AsyncState; IJobTemplate jobTemplateToReturn = this.GetMediaContext().JobTemplates.Where(c => c.Id == data.Id).First(); return jobTemplateToReturn; })); }
/// <summary> /// Updates this instance asynchronously. /// </summary> /// <returns></returns> public Task <IContentKey> UpdateAsync() { IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(ContentKeyBaseCollection.ContentKeySet, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)) .ContinueWith <IContentKey>( t => { var data = (ContentKeyData)t.Result.AsyncState; return data; })); }
/// <summary> /// Asynchronously updates this instance. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task <IAssetDeliveryPolicy> UpdateAsync() { IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(AssetDeliveryPolicyCollection.DeliveryPolicySet, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)) .ContinueWith <IAssetDeliveryPolicy>( t => { t.ThrowIfFaulted(); var data = (AssetDeliveryPolicyData)t.Result.AsyncState; return data; })); }
/// <summary> /// Deletes the channel asynchronously. /// </summary> /// <returns>Task to wait on for operation completion.</returns> public override Task DeleteAsync() { if (string.IsNullOrWhiteSpace(Id)) { throw new InvalidOperationException(Resources.ErrorEntityWithoutId); } IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(EntitySetName, this); dataContext.DeleteObject(this); MediaRetryPolicy retryPolicy = GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(this)) .ContinueWith(t => { t.ThrowIfFaulted(); string operationId = t.Result.Single().Headers[StreamingConstants.OperationIdHeader]; IOperation operation = AsyncHelper.WaitOperationCompletion( GetMediaContext(), operationId, StreamingConstants.DeleteChannelPollInterval); string messageFormat = Resources.ErrorDeleteChannelFailedFormat; string message; switch (operation.State) { case OperationState.Succeeded: return; case OperationState.Failed: message = string.Format(CultureInfo.CurrentCulture, messageFormat, Resources.Failed, operationId, operation.ErrorMessage); throw new InvalidOperationException(message); default: // can never happen unless state enum is extended message = string.Format(CultureInfo.CurrentCulture, messageFormat, Resources.InInvalidState, operationId, operation.State); throw new InvalidOperationException(message); } })); }
/// <summary> /// Asynchronously creates new Program. /// </summary> /// <param name="options">Program creation options.</param> /// <returns>The task to create the program.</returns> public Task <IProgram> CreateAsync(ProgramCreationOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (string.IsNullOrEmpty(options.Name)) { throw new ArgumentException(Resources.ErrorEmptyProgramName); } if (_parentChannel == null) { throw new InvalidOperationException(Resources.ErrorOrphanProgram); } var program = new ProgramData { Name = options.Name, Description = options.Description, ChannelId = _parentChannel.Id, AssetId = options.AssetId, ArchiveWindowLength = options.ArchiveWindowLength, ManifestName = options.ManifestName }; program.SetMediaContext(MediaContext); IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AddObject(ProgramSet, program); MediaRetryPolicy retryPolicy = MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(program)) .ContinueWith <IProgram>(t => { t.ThrowIfFaulted(); return (ProgramData)t.Result.AsyncState; })); }
/// <summary> /// Asynchronously updates this asset instance. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task UpdateAsync() { AssetCollection.VerifyAsset(this); IMediaDataServiceContext dataContext = this._mediaContextBase.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(AssetCollection.AssetSet, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this._mediaContextBase.MediaServicesClassFactory.GetSaveChangesRetryPolicy(); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)) .ContinueWith <IAsset>( t => { t.ThrowIfFaulted(); AssetData data = (AssetData)t.Result.AsyncState; return data; })); }
private Task <IMediaDataServiceResponse> CreateStreamingEndpointAsync(StreamingEndpointCreationOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (string.IsNullOrEmpty(options.Name)) { throw new ArgumentException(Resources.ErrorEmptyStreamingEndpointName); } var streamingEndpoint = new StreamingEndpointData { Name = options.Name, Description = options.Description, ScaleUnits = options.ScaleUnits, CrossSiteAccessPolicies = options.CrossSiteAccessPolicies }; if (options.CustomHostNames != null) { streamingEndpoint.CustomHostNames = (options.CustomHostNames as IList <string>) ?? options.CustomHostNames.ToList(); } ((IStreamingEndpoint)streamingEndpoint).AccessControl = options.AccessControl; ((IStreamingEndpoint)streamingEndpoint).CacheControl = options.CacheControl; streamingEndpoint.ValidateSettings(); streamingEndpoint.SetMediaContext(MediaContext); IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AddObject(StreamingEndpointSet, streamingEndpoint); MediaRetryPolicy retryPolicy = MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync(() => dataContext.SaveChangesAsync(streamingEndpoint))); }