예제 #1
0
        public void ShouldThrowGetSasUriWithSpecificLocatorIfAssetFileIsNull()
        {
            IAssetFile nullAssetFile = null;

            var sasLocator = this.context.Locators.Where(l => l.Type == LocatorType.Sas).FirstOrDefault();

            nullAssetFile.GetSasUri(sasLocator);
        }
예제 #2
0
        public void ShouldThrowGetSasUriWithSpecificLocatorIfAssetFileIsNull()
        {
            this.asset = this.context.Assets.CreateFromFile("dummy.ism", AssetCreationOptions.None);

            var locator = this.context.Locators.Create(LocatorType.Sas, this.asset, AccessPermissions.Read, TimeSpan.FromDays(1));

            IAssetFile nullAssetFile = null;

            nullAssetFile.GetSasUri(locator);
        }
예제 #3
0
        /// <summary>
        /// Returns a <see cref="System.Threading.Tasks.Task&lt;System.Collections.Generic.IEnumerable&lt;AssetFileMetadata&gt;&gt;"/> 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="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&lt;System.Collections.Generic.IEnumerable&lt;AssetFileMetadata&gt;&gt;"/> instance to retrieve the <paramref name="asset"/> metadata.</returns>
        public static async Task <IEnumerable <AssetFileMetadata> > GetMetadataAsync(this IAsset asset, ILocator sasLocator, CancellationToken cancellationToken)
        {
            if (asset == null)
            {
                throw new ArgumentNullException("asset", "The asset 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 (asset.Id != sasLocator.AssetId)
            {
                throw new ArgumentException("sasLocator", "The SAS locator does not belong to the asset.");
            }

            IEnumerable <AssetFileMetadata> assetMetadata = null;

            IAssetFile metadataAssetFile = asset
                                           .AssetFiles
                                           .ToArray()
                                           .FirstOrDefault(af => af.Name.EndsWith(MetadataFileSuffix, StringComparison.OrdinalIgnoreCase));

            if (metadataAssetFile != null)
            {
                MediaContextBase context = asset.GetMediaContext();

                Uri assetFileMetadataUri = metadataAssetFile.GetSasUri(sasLocator);

                assetMetadata = await AssetMetadataParser.ParseAssetFileMetadataAsync(
                    assetFileMetadataUri,
                    context.MediaServicesClassFactory.GetBlobStorageClientRetryPolicy().AsAzureStorageClientRetryPolicy(),
                    cancellationToken)
                                .ConfigureAwait(false);
            }

            return(assetMetadata);
        }
        public Asset GetAsset(string assetId)
        {
            if (assetId == string.Empty)
            {
                throw new ArgumentException("assetId cannot be empty", "assetId");
            }

            var asset = this.context.Assets.Where(a => a.Id == assetId).FirstOrDefault();

            if (asset == null)
            {
                return(null);
            }

            IAssetFile highQualityVideoAssetFile = null;
            IAssetFile midQualityVideoAssetFile  = null;
            IAssetFile lowQualityVideoAssetFile  = null;
            ILocator   sasLocator      = null;
            var        videoAssetFiles = asset
                                         .AssetFiles
                                         .ToArray()
                                         .Where(af => af.Name.EndsWith(Mp4AssetFileNameSuffix, StringComparison.OrdinalIgnoreCase) && af.Name.Contains(H264VideoCodec))
                                         .OrderByDescending(af => af.ContentFileSize)
                                         .ToArray();

            var count = videoAssetFiles.Length;

            if (count > 0)
            {
                highQualityVideoAssetFile = videoAssetFiles[0];
                midQualityVideoAssetFile  = videoAssetFiles[count / 2];
                lowQualityVideoAssetFile  = videoAssetFiles[count - 1];
                sasLocator = asset.Locators
                             .ToArray()
                             .Where(l => l.Type == LocatorType.Sas)
                             .OrderBy(l => l.ExpirationDateTime)
                             .LastOrDefault();
            }

            return(new Asset
            {
                Id = asset.Id,
                Name = asset.Name,
                State = asset.State.ToString(),
                SmoothStreamingUri = asset.GetSmoothStreamingUri(),
                MpegDashUri = asset.GetMpegDashUri(),
                HlsUri = asset.GetHlsUri(),
                Hlsv3Uri = asset.GetHlsv3Uri(),
                HighQualityMp4Uri = highQualityVideoAssetFile != null && sasLocator != null?highQualityVideoAssetFile.GetSasUri(sasLocator) : null,
                                        MidQualityMp4Uri = midQualityVideoAssetFile != null && sasLocator != null?midQualityVideoAssetFile.GetSasUri(sasLocator) : null,
                                                               LowQualityMp4Uri = lowQualityVideoAssetFile != null && sasLocator != null?lowQualityVideoAssetFile.GetSasUri(sasLocator) : null
            });
        }
예제 #5
0
        public void ShouldThrowGetSasUriIfAssetFileIsNull()
        {
            IAssetFile nullAssetFile = null;

            nullAssetFile.GetSasUri();
        }