BlogEngine.Core.Providers.DbFileSystemProvider.ImageThumbnail C# (CSharp) Method

ImageThumbnail() public method

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
this is a virtual file and all actual file methods will not be available.
public ImageThumbnail ( string VirtualPath, int MaximumSize ) : FileSystem.Image
VirtualPath string The virtual path of the image
MaximumSize int The maximum size for the image
return FileSystem.Image
        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;
        }