/// <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<ILocator>.</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> /// Returns a new <see cref="ILocator"/> instance. /// </summary> /// <param name="locators">The <see cref="LocatorBaseCollection"/> instance.</param> /// <param name="locatorType">The <see cref="LocatorType"/>.</param> /// <param name="asset">The <see cref="IAsset"/> instance for the new <see cref="ILocator"/>.</param> /// <param name="permissions">The <see cref="AccessPermissions"/> of the <see cref="IAccessPolicy"/> associated with the new <see cref="ILocator"/>.</param> /// <param name="duration">The duration of the <see cref="IAccessPolicy"/> associated with the new <see cref="ILocator"/>.</param> /// <param name="startTime">The start time of the new <see cref="ILocator"/>.</param> /// <returns>A a new <see cref="ILocator"/> instance.</returns> public static ILocator Create(this LocatorBaseCollection locators, LocatorType locatorType, IAsset asset, AccessPermissions permissions, TimeSpan duration, DateTime?startTime) { using (Task <ILocator> task = locators.CreateAsync(locatorType, asset, permissions, duration, startTime)) { return(task.Result); } }
/// <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> /// Returns a <see cref="System.Threading.Tasks.Task<ILocator>"/> instance for new <see cref="ILocator"/>. /// </summary> /// <param name="locators">The <see cref="LocatorBaseCollection"/> instance.</param> /// <param name="locatorType">The <see cref="LocatorType"/>.</param> /// <param name="asset">The <see cref="IAsset"/> instance for the new <see cref="ILocator"/>.</param> /// <param name="permissions">The <see cref="AccessPermissions"/> of the <see cref="IAccessPolicy"/> associated with the new <see cref="ILocator"/>.</param> /// <param name="duration">The duration of the <see cref="IAccessPolicy"/> associated with the new <see cref="ILocator"/>.</param> /// <param name="startTime">The start time of the new <see cref="ILocator"/>.</param> /// <returns>A <see cref="System.Threading.Tasks.Task<ILocator>"/> instance for new <see cref="ILocator"/>.</returns> public static async Task <ILocator> CreateAsync(this LocatorBaseCollection locators, LocatorType locatorType, IAsset asset, AccessPermissions permissions, TimeSpan duration, DateTime?startTime) { if (locators == null) { throw new ArgumentNullException("locators", "The locators collection cannot be null."); } if (asset == null) { throw new ArgumentNullException("asset", "The asset cannot be null."); } MediaContextBase context = locators.MediaContext; var policy = await context.AccessPolicies.CreateAsync(asset.Name, duration, permissions); return(await locators.CreateLocatorAsync(locatorType, asset, policy, startTime)); }
/// <summary> /// Asynchronously updates the start time or expiration time of an Origin locator. /// </summary> /// <param name="startTime">The new start time for the origin locator.</param> /// <param name="expiryTime">The new expiration time for the origin locator.</param> /// <returns>A function delegate that returns the future result to be available through the Task<ILocator>.</returns> /// <exception cref="InvalidOperationException">When locator is not an Origin Locator.</exception> public Task UpdateAsync(DateTime?startTime, DateTime expiryTime) { LocatorBaseCollection.VerifyLocator(this); if (((ILocator)this).Type != LocatorType.OnDemandOrigin) { throw new InvalidOperationException(StringTable.InvalidOperationUpdateForNotOriginLocator); } DataServiceContext dataContext = this._cloudMediaContext.DataContextFactory.CreateDataServiceContext(); dataContext.AttachTo(LocatorBaseCollection.LocatorSet, this); this.StartTime = startTime; this.ExpirationDateTime = expiryTime; dataContext.UpdateObject(this); return(dataContext.SaveChangesAsync(this)); }
/// <summary> /// Asynchronously updates the start time or expiration time of an Origin locator. /// </summary> /// <param name="startTime">The new start time for the origin locator.</param> /// <param name="expiryTime">The new expiration time for the origin locator.</param> /// <returns>A function delegate that returns the future result to be available through the Task<ILocator>.</returns> /// <exception cref="InvalidOperationException">When locator is not an Origin Locator.</exception> public Task UpdateAsync(DateTime?startTime, DateTime expiryTime) { LocatorBaseCollection.VerifyLocator(this); if (((ILocator)this).Type != LocatorType.OnDemandOrigin) { throw new InvalidOperationException(StringTable.InvalidOperationUpdateForNotOriginLocator); } IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); dataContext.AttachTo(LocatorBaseCollection.LocatorSet, this); this.StartTime = startTime; this.ExpirationDateTime = expiryTime; dataContext.UpdateObject(this); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter); return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(this))); }
/// <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<ILocator>.</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)); }
/// <summary> /// Returns a new <see cref="ILocator"/> instance. /// </summary> /// <param name="locators">The <see cref="LocatorBaseCollection"/> instance.</param> /// <param name="locatorType">The <see cref="LocatorType"/>.</param> /// <param name="asset">The <see cref="IAsset"/> instance for the new <see cref="ILocator"/>.</param> /// <param name="permissions">The <see cref="AccessPermissions"/> of the <see cref="IAccessPolicy"/> associated with the new <see cref="ILocator"/>.</param> /// <param name="duration">The duration of the <see cref="IAccessPolicy"/> associated with the new <see cref="ILocator"/>.</param> /// <returns>A a new <see cref="ILocator"/> instance.</returns> public static ILocator Create(this LocatorBaseCollection locators, LocatorType locatorType, IAsset asset, AccessPermissions permissions, TimeSpan duration) { return(locators.Create(locatorType, asset, permissions, duration, null)); }