/// <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)); }
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> /// 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> /// 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> /// 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> /// 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> /// 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> /// 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> /// 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> /// 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> /// 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 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> /// 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))); }
/// <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> /// 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))); }
/// <summary> /// Sends update request 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 SendUpdateOperation() { ValidateSettings(); IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(EntitySetName, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); var response = retryPolicy.ExecuteAction(() => dataContext.SaveChanges()).Single(); 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(new OperationData { ErrorCode = null, ErrorMessage = null, State = OperationState.Succeeded.ToString(), Id = null }); } string operationId = response.Headers[StreamingConstants.OperationIdHeader]; return(new OperationData { ErrorCode = null, ErrorMessage = null, Id = operationId, State = OperationState.InProgress.ToString(), }); }
/// <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 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; })); }
/// <summary> /// Asynchronously updates the start time or expiration time of an Origin locator. /// </summary> /// <param name="startTime">The new start time for the origin locator.</param> /// <param name="expiryTime">The new expiration time for the origin locator.</param> /// <returns>A function delegate that returns the future result to be available through the Task<ILocator>.</returns> /// <exception cref="InvalidOperationException">When locator is not an Origin Locator.</exception> public Task UpdateAsync(DateTime?startTime, DateTime expiryTime) { LocatorBaseCollection.VerifyLocator(this); if (((ILocator)this).Type != LocatorType.OnDemandOrigin) { throw new InvalidOperationException(StringTable.InvalidOperationUpdateForNotOriginLocator); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(LocatorBaseCollection.LocatorSet, this); this.StartTime = startTime; this.ExpirationDateTime = expiryTime; dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <summary> /// Asynchronously saves this instance. /// </summary> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> public Task UpdateAsync() { if (this.Asset.State != AssetState.Initialized) { throw new NotSupportedException(StringTable.NotSupportedFileInfoSave); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(FileSet, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)) .ContinueWith <IAssetFile>( t => { t.ThrowIfFaulted(); AssetFileData data = (AssetFileData)t.Result.AsyncState; return data; })); }
/// <summary> /// Asynchronously updates this job instance. /// </summary> /// <returns></returns> public Task <IJob> UpdateAsync() { if (string.IsNullOrWhiteSpace(this.Id)) { // The job has not been submitted yet throw new InvalidOperationException(StringTable.InvalidOperationUpdateForNotSubmittedJob); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(JobBaseCollection.JobSet, this); dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)) .ContinueWith <IJob>( t => { t.ThrowIfFaulted(); JobData data = (JobData)t.Result.AsyncState; return data; }, TaskContinuationOptions.ExecuteSynchronously)); }
private void InnerSubmit(IMediaDataServiceContext dataContext) { if (!string.IsNullOrWhiteSpace(this.TemplateId)) { dataContext.AddObject(JobBaseCollection.JobSet, this); foreach (IAsset asset in this.InputMediaAssets) { AssetData target = asset as AssetData; if (target == null) { throw new ArgumentException(StringTable.ErrorInputTypeNotSupported); } dataContext.AttachTo(AssetCollection.AssetSet, asset); dataContext.AddLink(this, InputMediaAssetsPropertyName, target); } } else { X509Certificate2 certToUse = null; Verify(this); dataContext.AddObject(JobBaseCollection.JobSet, this); List <AssetData> inputAssets = new List <AssetData>(); AssetNamingSchemeResolver <AssetData, OutputAsset> assetNamingSchemeResolver = new AssetNamingSchemeResolver <AssetData, OutputAsset>(inputAssets); foreach (ITask task in ((IJob)this).Tasks) { Verify(task); TaskData taskData = (TaskData)task; if (task.Options.HasFlag(TaskOptions.ProtectedConfiguration)) { ProtectTaskConfiguration(taskData, ref certToUse, dataContext); } taskData.TaskBody = CreateTaskBody(assetNamingSchemeResolver, task.InputAssets.ToArray(), task.OutputAssets.ToArray()); taskData.InputMediaAssets.AddRange(task.InputAssets.OfType <AssetData>().ToArray()); taskData.OutputMediaAssets.AddRange( task.OutputAssets .OfType <OutputAsset>() .Select( c => { AssetData assetData = new AssetData { Name = c.Name, Options = (int)c.Options, AlternateId = c.AlternateId }; assetData.SetMediaContext(this.GetMediaContext()); return(assetData); }) .ToArray()); dataContext.AddRelatedObject(this, TasksPropertyName, taskData); } foreach (IAsset asset in inputAssets) { dataContext.AttachTo(AssetCollection.AssetSet, asset); dataContext.AddLink(this, InputMediaAssetsPropertyName, asset); } } }