/// <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> /// Creates the manifest asset file asynchronously. /// </summary> /// <param name="ingestManifestAsset">The parent manifest asset.</param> /// <param name="filePath">The file path.</param> /// <param name="token"><see cref="CancellationToken"/></param> /// <returns><see cref="Task"/>of type <see cref="IIngestManifestFile"/></returns> public Task <IIngestManifestFile> CreateAsync(IIngestManifestAsset ingestManifestAsset, string filePath, CancellationToken token) { if (ingestManifestAsset == null) { throw new ArgumentNullException("ingestManifestAsset"); } if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, StringTable.ErrorCreatingIngestManifestFileEmptyFilePath)); } AssetCreationOptions options = ingestManifestAsset.Asset.Options; Task <IIngestManifestFile> rootTask = new Task <IIngestManifestFile>(() => { token.ThrowIfCancellationRequested(); IngestManifestAssetCollection.VerifyManifestAsset(ingestManifestAsset); if (!File.Exists(filePath)) { throw new FileNotFoundException(String.Format(CultureInfo.InvariantCulture, StringTable.BulkIngestProvidedFileDoesNotExist, filePath)); } FileInfo info = new FileInfo(filePath); DataServiceContext dataContext = this._cloudMediaContext.DataContextFactory.CreateDataServiceContext(); // Set a MIME type based on the extension of the file name string mimeType = AssetFileData.GetMimeType(filePath); IngestManifestFileData data = new IngestManifestFileData { Name = info.Name, MimeType = mimeType, ParentIngestManifestId = ingestManifestAsset.ParentIngestManifestId, ParentIngestManifestAssetId = ingestManifestAsset.Id, Path = filePath, }; SetEncryptionSettings(ingestManifestAsset, info, options, data); dataContext.AddObject(EntitySet, data); Task <IIngestManifestFile> task = dataContext.SaveChangesAsync(data).ContinueWith <IIngestManifestFile>(t => { t.ThrowIfFaulted(); token.ThrowIfCancellationRequested(); IngestManifestFileData ingestManifestFile = (IngestManifestFileData)t.AsyncState; return(ingestManifestFile); }); return(task.Result); }); rootTask.Start(); return(rootTask); }
/// <summary> /// Creates the manifest asset file asynchronously. /// </summary> /// <param name="ingestManifestAsset">The parent manifest asset.</param> /// <param name="filePath">The file path.</param> /// <param name="token"><see cref="CancellationToken"/></param> /// <returns><see cref="Task"/>of type <see cref="IIngestManifestFile"/></returns> public Task <IIngestManifestFile> CreateAsync(IIngestManifestAsset ingestManifestAsset, string filePath, CancellationToken token) { if (ingestManifestAsset == null) { throw new ArgumentNullException("ingestManifestAsset"); } if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, StringTable.ErrorCreatingIngestManifestFileEmptyFilePath)); } AssetCreationOptions options = ingestManifestAsset.Asset.Options; Task <IIngestManifestFile> rootTask = new Task <IIngestManifestFile>(() => { token.ThrowIfCancellationRequested(); IngestManifestAssetCollection.VerifyManifestAsset(ingestManifestAsset); IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext(); // Set a MIME type based on the extension of the file name string mimeType = AssetFileData.GetMimeType(filePath); IngestManifestFileData data = new IngestManifestFileData { Name = Path.GetFileName(filePath), MimeType = mimeType, ParentIngestManifestId = ingestManifestAsset.ParentIngestManifestId, ParentIngestManifestAssetId = ingestManifestAsset.Id, Path = filePath, }; SetEncryptionSettings(ingestManifestAsset, options, data); dataContext.AddObject(EntitySet, data); MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); Task <IIngestManifestFile> task = retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(data)) .ContinueWith <IIngestManifestFile>(t => { t.ThrowIfFaulted(); token.ThrowIfCancellationRequested(); IngestManifestFileData ingestManifestFile = (IngestManifestFileData)t.Result.AsyncState; return(ingestManifestFile); }); return(task.Result); }); rootTask.Start(); return(rootTask); }