예제 #1
0
        /// <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&lt;ILocator&gt;.</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 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);
            }

            DataServiceContext dataContext = this._cloudMediaContext.DataContextFactory.CreateDataServiceContext();

            dataContext.AttachTo(LocatorBaseCollection.LocatorSet, this);

            this.StartTime          = startTime;
            this.ExpirationDateTime = expiryTime;

            dataContext.UpdateObject(this);

            return(dataContext.SaveChangesAsync(this));
        }
예제 #3
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)));
        }
        /// <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&lt;ILocator&gt;.</returns>
        public Task DeleteAsync()
        {
            LocatorBaseCollection.VerifyLocator(this);

            DataServiceContext dataContext = this._cloudMediaContext.DataContextFactory.CreateDataServiceContext();

            dataContext.AttachTo(LocatorBaseCollection.LocatorSet, this);
            dataContext.DeleteObject(this);
            var cloudContext = this._cloudMediaContext;

            return(dataContext
                   .SaveChangesAsync(this)
                   .ContinueWith(
                       t =>
            {
                t.ThrowIfFaulted();

                LocatorData data = (LocatorData)t.AsyncState;

                if (cloudContext != null)
                {
                    var cloudContextAsset = (AssetData)cloudContext.Assets.Where(c => c.Id == data.AssetId).FirstOrDefault();
                    if (cloudContextAsset != null)
                    {
                        cloudContextAsset.InvalidateLocatorsCollection();
                    }
                }


                if (data.Asset != null)
                {
                    data.Asset.InvalidateLocatorsCollection();
                }
            },
                       TaskContinuationOptions.ExecuteSynchronously));
        }