コード例 #1
0
        /// <summary>
        /// Simple but less efficient way of getting an image url if you only know
        /// the id. Use the overload accepting an IImageAssetRenderable if possible to save a
        /// potential db query if the route isn't cached.
        /// </summary>
        /// <param name="imageAssetId">Id of the image asset to get the url for</param>
        /// <param name="settings">Optional resizing settings for the image</param>
        public async Task <string> ImageAssetAsync(int?imageAssetId, IImageResizeSettings settings = null)
        {
            if (!imageAssetId.HasValue)
            {
                return(string.Empty);
            }

            var getImageQuery = new GetImageAssetRenderDetailsByIdQuery(imageAssetId.Value);
            var asset         = await _queryExecutor.ExecuteAsync(getImageQuery);

            return(ImageAsset(asset, settings));
        }
コード例 #2
0
        /// <summary>
        /// Simple but less efficient way of getting an image url if you only know
        /// the id. Use the overload accepting an IImageAssetRenderable if possible to save a
        /// potential db query if the route isn't cached.
        /// </summary>
        /// <param name="imageAssetId">Id of the image asset to get the url for</param>
        /// <param name="width">width to resize the image to</param>
        /// <param name="height">height to resize the image to</param>
        public async Task <string> ImageAssetAsync(int?imageAssetId, int?width, int?height = null)
        {
            if (!imageAssetId.HasValue)
            {
                return(string.Empty);
            }

            var getImageQuery = new GetImageAssetRenderDetailsByIdQuery(imageAssetId.Value);
            var asset         = await _queryExecutor.ExecuteAsync(getImageQuery);

            if (asset == null)
            {
                return(string.Empty);
            }

            var settings = GetResizeSettings(asset, width, height);

            return(GetUrl(asset, settings));
        }
コード例 #3
0
        public async Task <ImageAssetFile> ExecuteAsync(GetImageAssetFileByIdQuery query, IExecutionContext executionContext)
        {
            // Render details is potentially cached so we query for this rather than directly with the db
            var getImageQuery = new GetImageAssetRenderDetailsByIdQuery(query.ImageAssetId);
            var dbResult      = await _queryExecutor.ExecuteAsync(getImageQuery, executionContext);

            if (dbResult == null)
            {
                return(null);
            }
            var fileName      = Path.ChangeExtension(query.ImageAssetId.ToString(), dbResult.Extension);
            var contentStream = await _fileStoreService.GetAsync(ImageAssetConstants.FileContainerName, fileName);;

            if (contentStream == null)
            {
                throw new FileNotFoundException("Image asset file could not be found", fileName);
            }

            var result = _imageAssetFileMapper.Map(dbResult, contentStream);

            return(result);
        }
コード例 #4
0
        public Task <ImageAssetRenderDetails> GetImageAssetRenderDetailsByIdAsync(int imageAssetId, IExecutionContext executionContext = null)
        {
            var query = new GetImageAssetRenderDetailsByIdQuery(imageAssetId);

            return(_queryExecutor.ExecuteAsync(query, executionContext));
        }
コード例 #5
0
        public IContentRepositoryQueryContext <ImageAssetRenderDetails> AsRenderDetails()
        {
            var query = new GetImageAssetRenderDetailsByIdQuery(_imageAssetId);

            return(ContentRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
        }
        public Task <ImageAssetRenderDetails> AsRenderDetailsAsync()
        {
            var query = new GetImageAssetRenderDetailsByIdQuery(_imageAssetId);

            return(ExtendableContentRepository.ExecuteQueryAsync(query));
        }