Пример #1
0
        /// <summary>
        /// Returns a thumbnail image at a maximum size. Only one size is provided as the thumbnail will be scaled down. If the thumbnail does not exist the thumbnail is created
        /// </summary>
        /// <param name="VirtualPath">The virtual path of the image</param>
        /// <param name="MaximumSize">The maximum size for the image</param>
        /// <returns>The image with the thumbnail contents</returns>
        /// <remarks>
        /// this is a virtual file and all actual file methods will not be available.
        /// </remarks>
        public override FileSystem.Image ImageThumbnail(string VirtualPath, int MaximumSize)
        {
            var file = GetFile(VirtualPath);

            if (!file.IsImage)
            {
                return(null);
            }
            var db        = new FileSystem.FileStoreDb(this.connectionString);
            var image     = file.AsImage;
            var thumbnail = db.FileStoreFileThumbs.FirstOrDefault(x => x.FileId == Guid.Parse(image.Id));

            if (thumbnail == null)
            {
                FileSystem.FileStoreFileThumb thumb = new FileSystem.FileStoreFileThumb()
                {
                    contents    = FileSystem.Image.ResizeImageThumbnail(MaximumSize, image.FileContents),
                    FileId      = Guid.Parse(image.Id),
                    size        = MaximumSize,
                    thumbnailId = Guid.NewGuid()
                };
                db.FileStoreFileThumbs.InsertOnSubmit(thumb);
                db.SubmitChanges();
                image.FileContents = thumb.contents.ToArray();
            }
            else
            {
                image.FileContents = thumbnail.contents.ToArray();
            }
            db.Dispose();
            return(image);
        }
        /// <summary>
        /// Returns a thumbnail image at a maximum size. Only one size is provided as the thumbnail will be scaled down. If the thumbnail does not exist the thumbnail is created
        /// </summary>
        /// <param name="VirtualPath">The virtual path of the image</param>
        /// <param name="MaximumSize">The maximum size for the image</param>
        /// <returns>The image with the thumbnail contents</returns>
        /// <remarks>
        /// this is a virtual file and all actual file methods will not be available.
        /// </remarks>
        public override FileSystem.Image ImageThumbnail(string VirtualPath, int MaximumSize)
        {
            var file = GetFile(VirtualPath);
            if (!file.IsImage)
                return null;
            var db = new FileSystem.FileStoreDb(this.connectionString);
            var image = file.AsImage;
            var thumbnail = db.FileStoreFileThumbs.FirstOrDefault(x => x.FileId == Guid.Parse(image.Id));
            if (thumbnail == null)
            {

                FileSystem.FileStoreFileThumb thumb = new FileSystem.FileStoreFileThumb()
                {
                    contents = FileSystem.Image.ResizeImageThumbnail(MaximumSize, image.FileContents),
                    FileId = Guid.Parse(image.Id),
                    size = MaximumSize,
                    thumbnailId = Guid.NewGuid()
                };
                db.FileStoreFileThumbs.InsertOnSubmit(thumb);
                db.SubmitChanges();
                image.FileContents = thumb.contents.ToArray();
            }
            else
                image.FileContents = thumbnail.contents.ToArray();
            db.Dispose();
            return image;
        }