private void InnerSave(IMediaDataServiceContext dataContext) { X509Certificate2 certToUse = null; dataContext.AddObject(JobTemplateBaseCollection.JobTemplateSet, this); foreach (TaskTemplateData taskTemplate in this.TaskTemplates) { dataContext.AddRelatedObject(this, TaskTemplatesPropertyName, taskTemplate); if (((ITaskTemplate)taskTemplate).Options.HasFlag(TaskOptions.ProtectedConfiguration) && (taskTemplate.Configuration != taskTemplate.ConfigurationCopied)) { ProtectTaskConfiguration((TaskTemplateData)taskTemplate, ref certToUse, dataContext); } } MatchCollection matches = Regex.Matches(this.JobTemplateBodyCopied, @"taskTemplateId=""nb:ttid:UUID:([a-zA-Z0-9\-]+)"""); this.JobTemplateBody = this.JobTemplateBodyCopied; for (int i = 0; i < matches.Count; i++) { string taskTemplateId = Guid.NewGuid().ToString(); this.TaskTemplates[i].Id = string.Concat("nb:ttid:UUID:", taskTemplateId); this.JobTemplateBody = this.JobTemplateBody.Replace(matches[i].Groups[1].Value, taskTemplateId); } }
/// <summary> /// Gets the certificate for protection key id. /// </summary> /// <param name="mediaContext">The media context.</param> /// <param name="protectionKeyId">The protection key id.</param> /// <returns>The content key.</returns> internal static X509Certificate2 GetCertificateForProtectionKeyId(MediaContextBase mediaContext, string protectionKeyId) { // First check to see if we have the cert in our store already. X509Certificate2 certToUse = EncryptionUtils.GetCertificateFromStore(protectionKeyId); IMediaDataServiceContext dataContext = mediaContext.MediaServicesClassFactory.CreateDataServiceContext(); if ((certToUse == null) && (dataContext != null)) { // If not, download it from Nimbus to use. Uri uriGetProtectionKey = new Uri(String.Format(CultureInfo.InvariantCulture, "/GetProtectionKey?protectionKeyId='{0}'", protectionKeyId), UriKind.Relative); MediaRetryPolicy retryPolicy = mediaContext.MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter); IEnumerable <string> results2 = retryPolicy.ExecuteAction <IEnumerable <string> >(() => dataContext.Execute <string>(uriGetProtectionKey)); string certString = results2.Single(); byte[] certBytes = Convert.FromBase64String(certString); certToUse = new X509Certificate2(certBytes); try { // Finally save it for next time. EncryptionUtils.SaveCertificateToStore(certToUse); } catch { // Azure Web Sites does not allow writing access to the local certificate store (it is blocked by the security model used to isolate each web site). // Swallow the exception and continue executing. } } return(certToUse); }
/// <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> /// 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)); }
private Task <IIngestManifestAsset> CreateAsync(IIngestManifest ingestManifest, IAsset asset, CancellationToken token, Action <IngestManifestAssetData> continueWith) { IngestManifestCollection.VerifyManifest(ingestManifest); IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); var data = new IngestManifestAssetData { ParentIngestManifestId = ingestManifest.Id }; dataContext.AddObject(IngestManifestAssetCollection.EntitySet, data); dataContext.AttachTo(AssetCollection.AssetSet, asset); dataContext.SetLink(data, "Asset", asset); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(); Task <IIngestManifestAsset> task = retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(data)) .ContinueWith <IIngestManifestAsset>(t => { t.ThrowIfFaulted(); token.ThrowIfCancellationRequested(); IngestManifestAssetData ingestManifestAsset = (IngestManifestAssetData)t.Result.AsyncState; continueWith(ingestManifestAsset); return(ingestManifestAsset); }, TaskContinuationOptions.ExecuteSynchronously); return(task); }
/// <summary> /// Waits for REST Nimbus Streaming operation completion /// </summary> /// <param name="context">The <seealso cref="CloudMediaContext"/> instance.</param> /// <param name="operationId">Id of the operation.</param> /// <param name="pollInterval">Poll interval.</param> /// <returns>Operation.</returns> public static IOperation WaitOperationCompletion(MediaContextBase context, string operationId, TimeSpan pollInterval) { IOperation operation; do { Thread.Sleep(pollInterval); IMediaDataServiceContext dataContext = context.MediaServicesClassFactory.CreateDataServiceContext(); Uri uri = new Uri(string.Format(CultureInfo.InvariantCulture, "/Operations('{0}')", operationId), UriKind.Relative); MediaRetryPolicy retryPolicy = context.MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter); try { operation = retryPolicy.ExecuteAction <IEnumerable <OperationData> >(() => dataContext.Execute <OperationData>(uri)).SingleOrDefault(); } catch (Exception e) { e.Data.Add("OperationId", operationId); throw; } if (operation == null) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Resources.ErrorOperationNotFoundFormat, operationId)); } }while (operation.State == OperationState.InProgress); return(operation); }
/// <summary> /// Cancels the async. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task CancelAsync() { if (string.IsNullOrWhiteSpace(this.Id)) { // The job was not submitted yet. throw new InvalidOperationException(StringTable.InvalidOperationCancelForNotSubmittedJob); } Uri uri = new Uri( string.Format(CultureInfo.InvariantCulture, "/CancelJob?jobid='{0}'", HttpUtility.UrlEncode(Id)), UriKind.Relative); IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.IgnoreResourceNotFoundException = false; dataContext.AttachTo(JobBaseCollection.JobSet, this); return(dataContext .ExecuteAsync <string>(uri, this) .ContinueWith( t => { t.ThrowIfFaulted(); JobData data = (JobData)t.AsyncState; data.Refresh(); })); }
/// <summary> /// Initializes a new instance of the <see cref="LinkCollection<TInterface, TType>"/> class. /// </summary> /// <param name="dataContext">The data context.</param> /// <param name="parent">The parent.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="items">The items.</param> public LinkCollection(IMediaDataServiceContext dataContext, BaseEntity parent, string propertyName, IEnumerable <TInterface> items) : base(items) { this._dataContext = dataContext; this._propertyName = propertyName; this._parent = parent; }
/// <summary> /// Gets the encrypted key value. /// </summary> /// <param name="certToEncryptTo">The cert to use.</param> /// <returns>A function delegate that returns the future result to be available through the Task<byte[]>.</returns> public Task <byte[]> GetEncryptedKeyValueAsync(X509Certificate2 certToEncryptTo) { if (certToEncryptTo == null) { throw new ArgumentNullException("certToEncryptTo"); } // Start a new task here because the ExecutAsync on the DataContext returns a Task<string> return(Task.Factory.StartNew <byte[]>(() => { byte[] returnValue = null; if (this.GetMediaContext() != null) { string certToSend = Convert.ToBase64String(certToEncryptTo.Export(X509ContentType.Cert)); certToSend = HttpUtility.UrlEncode(certToSend); Uri uriRebindContentKey = new Uri(string.Format(CultureInfo.InvariantCulture, "/RebindContentKey?id='{0}'&x509Certificate='{1}'", this.Id, certToSend), UriKind.Relative); IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter); IEnumerable <string> results = retryPolicy.ExecuteAction <IEnumerable <string> >(() => dataContext.Execute <string>(uriRebindContentKey)); string reboundContentKey = results.Single(); returnValue = Convert.FromBase64String(reboundContentKey); } return returnValue; })); }
/// <summary> /// Gets the certificate for protection key id. /// </summary> /// <param name="mediaContext">The media context.</param> /// <param name="protectionKeyId">The protection key id.</param> /// <returns>The content key.</returns> internal static X509Certificate2 GetCertificateForProtectionKeyId(MediaContextBase mediaContext, string protectionKeyId) { // First check to see if we have the cert in our store already. X509Certificate2 certToUse = EncryptionUtils.GetCertificateFromStore(protectionKeyId); IMediaDataServiceContext dataContext = mediaContext.MediaServicesClassFactory.CreateDataServiceContext(); if ((certToUse == null) && (dataContext != null)) { // If not, download it from Nimbus to use. Uri uriGetProtectionKey = new Uri(String.Format(CultureInfo.InvariantCulture, "/GetProtectionKey?protectionKeyId='{0}'", protectionKeyId), UriKind.Relative); MediaRetryPolicy retryPolicy = mediaContext.MediaServicesClassFactory.GetQueryRetryPolicy(); IEnumerable <string> results2 = retryPolicy.ExecuteAction <IEnumerable <string> >(() => dataContext.Execute <string>(uriGetProtectionKey)); string certString = results2.Single(); byte[] certBytes = Convert.FromBase64String(certString); certToUse = new X509Certificate2(certBytes); // Finally save it for next time. EncryptionUtils.SaveCertificateToStore(certToUse); } return(certToUse); }
/// <summary> /// Sends delete operation to the service and returns. Use Operations collection to get operation's status. /// </summary> /// <returns>Operation info that can be used to track the operation.</returns> public IOperation SendDeleteOperation() { 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); var response = retryPolicy.ExecuteAction(() => dataContext.SaveChanges()); string operationId = response.Single().Headers[StreamingConstants.OperationIdHeader]; var result = new OperationData { ErrorCode = null, ErrorMessage = null, Id = operationId, State = OperationState.InProgress.ToString(), }; return(result); }
/// <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> /// 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> /// 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> /// Gets the execution progress of the task. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task GetExecutionProgressTask(CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(this.Id)) { // The job was not submitted yet. throw new InvalidOperationException(StringTable.InvalidOperationGetExecutionProgressTaskForNotSubmittedJob); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(JobBaseCollection.JobSet, this); return(Task.Factory.StartNew( t => { JobData data = (JobData)t; while (!IsFinalJobState(GetExposedState(data.State))) { Thread.Sleep(JobInterval); cancellationToken.ThrowIfCancellationRequested(); JobState previousState = GetExposedState(data.State); data.Refresh(); if (previousState != GetExposedState(data.State)) { this.OnStateChanged(new JobStateChangedEventArgs(previousState, GetExposedState(data.State))); } } }, this, cancellationToken)); }
/// <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 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> /// 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)); }
public static Uri GetBaseUri(this IMediaDataServiceContext mediaDataServiceContext) { var dataContext = mediaDataServiceContext.GetType() .GetField("_dataContext", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(mediaDataServiceContext) as DataServiceContext; return(dataContext.BaseUri); }
protected Task ExecuteActionAsync(Uri uri, TimeSpan pollInterval, params OperationParameter[] operationParameters) { return(Task.Factory.StartNew(() => { if (GetMediaContext() != null) { IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); MediaRetryPolicy retryPolicy = GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); var response = retryPolicy.ExecuteAction(() => dataContext.Execute(uri, "POST", operationParameters)); if (response.StatusCode == (int)HttpStatusCode.NotFound) { throw new InvalidOperationException("Entity not found"); } if (response.StatusCode >= 400) { var code = (HttpStatusCode)response.StatusCode; throw new InvalidOperationException(code.ToString()); } if (response.StatusCode != (int)HttpStatusCode.Accepted) // synchronous complete { Refresh(); return; } string operationId = response.Headers[StreamingConstants.OperationIdHeader]; var operation = AsyncHelper.WaitOperationCompletion( GetMediaContext(), operationId, pollInterval); Refresh(); string messageFormat = Resources.ErrorOperationFailedFormat; switch (operation.State) { case OperationState.Succeeded: return; case OperationState.Failed: throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, messageFormat, uri.OriginalString, Resources.Failed, operationId)); default: throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, messageFormat, uri.OriginalString, operation.State, operationId)); } } })); }
/// <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> /// Creates the manifest asset file asynchronously. /// </summary> /// <param name="ingestManifestAsset">The parent manifest asset.</param> /// <param name="filePath">The file path.</param> /// <param name="token"><see cref="CancellationToken"/></param> /// <returns><see cref="Task"/>of type <see cref="IIngestManifestFile"/></returns> public Task <IIngestManifestFile> CreateAsync(IIngestManifestAsset ingestManifestAsset, string filePath, CancellationToken token) { if (ingestManifestAsset == null) { throw new ArgumentNullException("ingestManifestAsset"); } if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, StringTable.ErrorCreatingIngestManifestFileEmptyFilePath)); } AssetCreationOptions options = ingestManifestAsset.Asset.Options; Task <IIngestManifestFile> rootTask = new Task <IIngestManifestFile>(() => { token.ThrowIfCancellationRequested(); IngestManifestAssetCollection.VerifyManifestAsset(ingestManifestAsset); IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); // Set a MIME type based on the extension of the file name string mimeType = AssetFileData.GetMimeType(filePath); IngestManifestFileData data = new IngestManifestFileData { Name = Path.GetFileName(filePath), MimeType = mimeType, ParentIngestManifestId = ingestManifestAsset.ParentIngestManifestId, ParentIngestManifestAssetId = ingestManifestAsset.Id, Path = filePath, }; SetEncryptionSettings(ingestManifestAsset, options, data); dataContext.AddObject(EntitySet, data); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); Task <IIngestManifestFile> task = retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(data)) .ContinueWith <IIngestManifestFile>(t => { t.ThrowIfFaulted(); token.ThrowIfCancellationRequested(); IngestManifestFileData ingestManifestFile = (IngestManifestFileData)t.Result.AsyncState; return(ingestManifestFile); }); return(task.Result); }); rootTask.Start(); return(rootTask); }
/// <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> /// Retrieves an operation by its Id. /// </summary> /// <param name="id">Id of the operation.</param> /// <returns>Operation.</returns> public IOperation GetOperation(string id) { Uri uri = new Uri(string.Format(CultureInfo.InvariantCulture, "/{0}('{1}')", OperationSet, id), UriKind.Relative); IMediaDataServiceContext dataContext = this._cloudMediaContext.MediaServicesClassFactory.CreateDataServiceContext(); MediaRetryPolicy retryPolicy = _cloudMediaContext.MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter); IOperation operation = retryPolicy.ExecuteAction <IEnumerable <OperationData> >(() => dataContext.Execute <OperationData>(uri)).SingleOrDefault(); return(operation); }
/// <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))); }
internal virtual void Refresh() { Uri uri = new Uri(string.Format(CultureInfo.InvariantCulture, "/{0}('{1}')", EntitySetName, Id), UriKind.Relative); IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(EntitySetName, this, Guid.NewGuid().ToString()); MediaRetryPolicy retryPolicy = GetMediaContext().MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed retryPolicy.ExecuteAction(() => dataContext.Execute <T>(uri)).Single(); }
/// <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> /// Gets the protection key id for content key. /// </summary> /// <param name="dataContext">The data context.</param> /// <param name="contentKeyType">Type of the content key.</param> /// <returns>The content key.</returns> internal static string GetProtectionKeyIdForContentKey(MediaContextBase mediaContext, ContentKeyType contentKeyType) { // First query Nimbus to find out what certificate to encrypt the content key with. string uriString = String.Format(CultureInfo.InvariantCulture, "/GetProtectionKeyId?contentKeyType={0}", Convert.ToInt32(contentKeyType, CultureInfo.InvariantCulture)); Uri uriGetProtectionKeyId = new Uri(uriString, UriKind.Relative); IMediaDataServiceContext dataContext = mediaContext.MediaServicesClassFactory.CreateDataServiceContext(); MediaRetryPolicy retryPolicy = mediaContext.MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter); IEnumerable <string> results = retryPolicy.ExecuteAction <IEnumerable <string> >(() => dataContext.Execute <string>(uriGetProtectionKeyId)); return(results.Single()); }
protected void LoadProperty(IMediaDataServiceContext dataContext, BaseEntity entity, string propertyName) { MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); retryPolicy.ExecuteAction(() => dataContext.LoadProperty(entity, propertyName)); }
protected void LoadProperty(IMediaDataServiceContext dataContext, string propertyName) { LoadProperty(dataContext, this, propertyName); }
private ContentKeyData CreateStorageContentKey(AssetData tempAsset, NullableFileEncryption fileEncryption, IMediaDataServiceContext dataContext) { // Create the content key. fileEncryption.Init(); // Encrypt it for delivery to Nimbus. X509Certificate2 certToUse = ContentKeyCollection.GetCertificateToEncryptContentKey(dataContext, ContentKeyType.StorageEncryption); ContentKeyData contentKeyData = ContentKeyBaseCollection.CreateStorageContentKey(fileEncryption.FileEncryption, certToUse); dataContext.AddObject(ContentKeyCollection.ContentKeySet, contentKeyData); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(); retryPolicy.ExecuteAction<IMediaDataServiceResponse>(() => dataContext.SaveChanges()); // Associate it with the asset. ((IAsset) tempAsset).ContentKeys.Add(contentKeyData); return contentKeyData; }
public TestMediaServicesClassFactoryForCustomRetryPolicy(IMediaDataServiceContext dataContext) : base(dataContext) { _dataContext = dataContext; }
public TestMediaServicesClassFactory(IMediaDataServiceContext dataContext) { _dataContext = dataContext; }