Ejemplo n.º 1
0
        /// <summary>
        /// Maps a ImageAssetRenderDetails (which is potentially cached) into an
        /// ImageAssetFile object. If the dbImage is null then null is returned.
        /// </summary>
        /// <param name="dbImage">ImageAssetRenderDetails record to map.</param>
        /// <param name="contentStream">Steam containing the file data.</param>
        public ImageAssetFile Map(ImageAssetRenderDetails cachedImage, Stream contentStream)
        {
            if (cachedImage == null)
            {
                return(null);
            }

            if (contentStream == null)
            {
                throw new ArgumentNullException(nameof(contentStream));
            }

            var image = new ImageAssetFile()
            {
                ImageAssetId          = cachedImage.ImageAssetId,
                Extension             = cachedImage.Extension,
                FileName              = cachedImage.FileName,
                Height                = cachedImage.Height,
                Width                 = cachedImage.Width,
                Title                 = cachedImage.Title,
                DefaultAnchorLocation = cachedImage.DefaultAnchorLocation,
                UpdateDate            = cachedImage.UpdateDate,
                ContentStream         = contentStream
            };

            return(image);
        }
        /// <summary>
        /// Maps a ImageAssetRenderDetails (which is potentially cached) into an
        /// ImageAssetFile object. If the dbImage is null then null is returned.
        /// </summary>
        /// <param name="dbImage">ImageAssetRenderDetails record to map.</param>
        /// <param name="contentStream">Steam containing the file data.</param>
        public ImageAssetFile Map(ImageAssetRenderDetails renderDetails, Stream contentStream)
        {
            if (renderDetails == null)
            {
                return(null);
            }

            if (contentStream == null)
            {
                throw new ArgumentNullException(nameof(contentStream));
            }

            var image = new ImageAssetFile()
            {
                ImageAssetId          = renderDetails.ImageAssetId,
                FileExtension         = renderDetails.FileExtension,
                FileName              = renderDetails.FileName,
                FileNameOnDisk        = renderDetails.FileNameOnDisk,
                Height                = renderDetails.Height,
                Width                 = renderDetails.Width,
                Title                 = renderDetails.Title,
                DefaultAnchorLocation = renderDetails.DefaultAnchorLocation,
                FileStamp             = renderDetails.FileStamp,
                FileUpdateDate        = renderDetails.FileUpdateDate,
                ContentStream         = contentStream,
                VerificationToken     = renderDetails.VerificationToken
            };

            return(image);
        }
        /// <summary>
        /// Maps an EF ImageAsset record from the db into a ImageAssetDetails
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbImage">ImageAsset record from the database.</param>
        public ImageAssetRenderDetails Map(ImageAsset dbImage)
        {
            if (dbImage == null)
            {
                return(null);
            }

            var image = new ImageAssetRenderDetails()
            {
                ImageAssetId          = dbImage.ImageAssetId,
                FileExtension         = dbImage.FileExtension,
                FileName              = dbImage.FileName,
                FileNameOnDisk        = dbImage.FileNameOnDisk,
                Height                = dbImage.HeightInPixels,
                Width                 = dbImage.WidthInPixels,
                Title                 = dbImage.Title,
                DefaultAnchorLocation = dbImage.DefaultAnchorLocation,
                FileUpdateDate        = dbImage.FileUpdateDate,
                VerificationToken     = dbImage.VerificationToken
            };

            image.FileStamp = AssetFileStampHelper.ToFileStamp(dbImage.FileUpdateDate);
            image.Url       = _imageAssetRouteLibrary.ImageAsset(image);

            return(image);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Maps an EF ImageAsset record from the db into a ImageAssetDetails
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbImage">ImageAsset record from the database.</param>
        public ImageAssetRenderDetails Map(ImageAsset dbImage)
        {
            if (dbImage == null)
            {
                return(null);
            }

            var image = new ImageAssetRenderDetails();

            image.ImageAssetId          = dbImage.ImageAssetId;
            image.Extension             = dbImage.Extension;
            image.FileName              = dbImage.FileName;
            image.Height                = dbImage.Height;
            image.Width                 = dbImage.Width;
            image.Title                 = dbImage.FileDescription;
            image.DefaultAnchorLocation = dbImage.DefaultAnchorLocation;
            image.UpdateDate            = DbDateTimeMapper.AsUtc(dbImage.UpdateDate);

            return(image);
        }