Пример #1
0
        /// <summary>
        /// Deletes this instance.
        /// </summary>
        /// <returns>A function delegate that returns the future result to be available through the Task.</returns>
        public Task DeleteAsync()
        {
            AccessPolicyBaseCollection.VerifyAccessPolicy(this);

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

            dataContext.AttachTo(AccessPolicyBaseCollection.AccessPolicySet, this);
            dataContext.DeleteObject(this);

            return(dataContext.SaveChangesAsync(this));
        }
        /// <summary>
        /// Deletes this instance.
        /// </summary>
        /// <returns>A function delegate that returns the future result to be available through the Task.</returns>
        public Task DeleteAsync()
        {
            AccessPolicyBaseCollection.VerifyAccessPolicy(this);

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

            dataContext.AttachTo(AccessPolicyBaseCollection.AccessPolicySet, this);
            dataContext.DeleteObject(this);

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

            return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this)));
        }
        /// <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&lt;ILocator&gt;.</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));
        }
Пример #4
0
        /// <summary>
        /// Creates the locator async.
        /// </summary>
        /// <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>
        /// <returns>A function delegate that returns the future result to be available through the Task&lt;ILocator&gt;.</returns>
        public Task <ILocator> CreateLocatorAsync(LocatorType locatorType, IAsset asset, IAccessPolicy accessPolicy, DateTime?startTime)
        {
            AccessPolicyBaseCollection.VerifyAccessPolicy(accessPolicy);
            AssetCollection.VerifyAsset(asset);

            AssetData assetData = (AssetData)asset;

            LocatorData locator = new LocatorData
            {
                AccessPolicy = (AccessPolicyData)accessPolicy,
                Asset        = assetData,
                Type         = (int)locatorType,
                StartTime    = startTime,
            };

            locator.InitCloudMediaContext(this._cloudMediaContext);

            DataServiceContext dataContext = this.DataContextFactory.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);

            return(dataContext
                   .SaveChangesAsync(locator)
                   .ContinueWith <ILocator>(
                       t =>
            {
                t.ThrowIfFaulted();

                assetData.InvalidateLocatorsCollection();

                return (LocatorData)t.AsyncState;
            },
                       TaskContinuationOptions.ExecuteSynchronously));
        }