/// <summary> /// Returns a <see cref="System.Collections.Generic.IEnumerable<AssetFileMetadata>"/> enumeration with the <paramref name="asset"/> metadata. /// </summary> /// <param name="asset">The <see cref="IAsset"/> instance from where to get the metadata.</param> /// <returns>A <see cref="System.Collections.Generic.IEnumerable<AssetFileMetadata>"/> enumeration with the <paramref name="asset"/> metadata.</returns> public static IEnumerable <AssetFileMetadata> GetMetadata(this IAsset asset) { using (Task <IEnumerable <AssetFileMetadata> > task = asset.GetMetadataAsync(CancellationToken.None)) { return(task.Result); } }
/// <summary> /// Returns a <see cref="System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<AssetFileMetadata>>"/> instance to retrieve the <paramref name="asset"/> metadata. /// </summary> /// <param name="asset">The <see cref="IAsset"/> instance from where to get the metadata.</param> /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> instance used for cancellation.</param> /// <returns>A <see cref="System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<AssetFileMetadata>>"/> instance to retrieve the <paramref name="asset"/> metadata.</returns> public static async Task <IEnumerable <AssetFileMetadata> > GetMetadataAsync(this IAsset asset, CancellationToken cancellationToken) { if (asset == null) { throw new ArgumentNullException("asset", "The asset cannot be null."); } MediaContextBase context = asset.GetMediaContext(); ILocator sasLocator = await context.Locators.CreateAsync(LocatorType.Sas, asset, AccessPermissions.Read, AssetBaseCollectionExtensions.DefaultAccessPolicyDuration).ConfigureAwait(false); IEnumerable <AssetFileMetadata> assetMetadata = await asset.GetMetadataAsync(sasLocator, cancellationToken).ConfigureAwait(false); await sasLocator.DeleteAsync().ConfigureAwait(false); return(assetMetadata); }
/// <summary> /// Returns a <see cref="System.Threading.Tasks.Task<AssetFileMetadata>"/> instance to retrieve the <paramref name="assetFile"/> metadata. /// </summary> /// <param name="assetFile">The <see cref="IAssetFile"/> instance from where to get the metadata.</param> /// <param name="sasLocator">The <see cref="ILocator"/> instance.</param> /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> instance used for cancellation.</param> /// <returns>A <see cref="System.Threading.Tasks.Task<AssetFileMetadata>"/> instance to retrieve the <paramref name="assetFile"/> metadata.</returns> public static async Task <AssetFileMetadata> GetMetadataAsync(this IAssetFile assetFile, ILocator sasLocator, CancellationToken cancellationToken) { if (assetFile == null) { throw new ArgumentNullException("assetFile", "The asset file cannot be null."); } if (sasLocator == null) { throw new ArgumentNullException("sasLocator", "The SAS locator cannot be null."); } if (sasLocator.Type != LocatorType.Sas) { throw new ArgumentException("The locator type must be SAS.", "sasLocator"); } if (assetFile.ParentAssetId != sasLocator.AssetId) { throw new ArgumentException("sasLocator", "The SAS locator does not belong to the asset."); } AssetFileMetadata assetFileMetadata = null; if (!assetFile.Name.EndsWith(IAssetExtensions.MetadataFileSuffix, StringComparison.OrdinalIgnoreCase)) { IAsset asset = assetFile.Asset; IEnumerable <AssetFileMetadata> assetMetadata = await asset.GetMetadataAsync(sasLocator, cancellationToken).ConfigureAwait(false); if (assetMetadata != null) { assetFileMetadata = assetMetadata.FirstOrDefault(am => assetFile.Name.Equals(am.Name, StringComparison.OrdinalIgnoreCase)); } } return(assetFileMetadata); }