Example #1
0
        /// <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.CreateDataServiceContext();
            dataContext.AttachTo(NotificationEndPointCollection.NotificationEndPoints, this);
            dataContext.UpdateObject(this);

            MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy();

            return retryPolicy.ExecuteAsync<IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this));
        }
        /// <summary>
        /// Updates manifest asynchronously.
        /// </summary>
        /// <returns><see cref="Task"/></returns>
        public Task UpdateAsync()
        {
            IngestManifestCollection.VerifyManifest(this);
            IMediaDataServiceContext dataContext = GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext();

            dataContext.AttachTo(IngestManifestCollection.EntitySet, this);
            dataContext.UpdateObject(this);

            MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter);

            return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)));
        }
        /// <summary>
        /// Updates Filter asynchronouslly
        /// </summary>
        /// <returns></returns>
        public virtual Task <IMediaDataServiceResponse> UpdateAsync()
        {
            Validate();

            IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext();

            dataContext.AttachTo(ResourceSetName, this);
            dataContext.UpdateObject(this);

            MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter);

            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>
        /// 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(),
            });
        }
Example #6
0
        /// <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>
        /// 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;
            }));
        }
Example #9
0
        /// <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&lt;ILocator&gt;.</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)));
        }
Example #10
0
        /// <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;
            }));
        }
Example #11
0
        /// <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));
        }