Exemple #1
0
        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>
        /// Updates manifest asynchronously.
        /// </summary>
        /// <returns><see cref="Task"/></returns>
        public Task UpdateAsync()
        {
            IngestManifestCollection.VerifyManifest(this);
            DataServiceContext dataContext = _cloudMediaContext.DataContextFactory.CreateDataServiceContext();

            dataContext.AttachTo(IngestManifestCollection.EntitySet, this);
            dataContext.UpdateObject(this);
            return(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)));
        }