Inheritance: ILocator, ICloudMediaContextInit
Exemple #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>
        /// 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));
        }
Exemple #3
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));
        }
        /// <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));
        }