Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CloudMediaContext"/> class.
        /// </summary>
        /// <param name="apiServer">A <see cref="Uri"/> representing a the API endpoint.</param>
        /// <param name="accountName">The Microsoft WindowsAzure Media Services account name to authenticate with.</param>
        /// <param name="accountKey">The Microsoft WindowsAzure Media Services account key to authenticate with.</param>
        /// <param name="scope">The scope of authorization.</param>
        /// <param name="acsBaseAddress">The access control endpoint to authenticate against.</param>
        public CloudMediaContext(Uri apiServer, string accountName, string accountKey, string scope, string acsBaseAddress)
        {
            this.ParallelTransferThreadCount = 10;
            this.NumberOfConcurrentTransfers = 2;

            OAuthDataServiceAdapter dataServiceAdapter =
                new OAuthDataServiceAdapter(accountName, accountKey, scope, acsBaseAddress, NimbusRestApiCertificateThumbprint, NimbusRestApiCertificateSubject);
            ServiceVersionAdapter versionAdapter = new ServiceVersionAdapter(KnownApiVersions.Current);

            this._dataContextFactory = new AzureMediaServicesDataServiceContextFactory(apiServer, dataServiceAdapter, versionAdapter, this);

            this._jobs                  = new JobBaseCollection(this);
            this._jobTemplates          = new JobTemplateBaseCollection(this);
            this._assets                = new AssetCollection(this);
            this._files                 = new AssetFileCollection(this);
            this._accessPolicies        = new AccessPolicyBaseCollection(this);
            this._contentKeys           = new ContentKeyCollection(this);
            this._notificationEndPoints = new NotificationEndPointCollection(this);
            this._mediaProcessors       = new MediaProcessorBaseCollection(this);
            this._locators              = new LocatorBaseCollection(this);
            this._ingestManifests       = new IngestManifestCollection(this);
            this._ingestManifestAssets  = new IngestManifestAssetCollection(this, null);
            this._ingestManifestFiles   = new IngestManifestFileCollection(this, null);
            this._storageAccounts       = new StorageAccountBaseCollection(this);
        }
        /// <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)));
        }