public LegacyThumbnailExtractor2(ThumbnailSizes thumbSize)
        {
            // Default Size

            // LEGACY **
            switch (thumbSize)
            {
            case ThumbnailSizes.Small:
                this.DesiredSize = new Size(50, 50);
                break;

            case ThumbnailSizes.Medium:
                this.DesiredSize = new Size(100, 100);
                break;

            case ThumbnailSizes.Large:
                this.DesiredSize = new Size(200, 200);
                break;

            case ThumbnailSizes.ExtraLarge:
                this.DesiredSize = new Size(300, 300);
                break;

            default:
                this.DesiredSize = new Size(100, 100);
                break;
            }
        }
        public LegacyThumbnailExtractor2(ThumbnailSizes thumbSize)
        {
            // Default Size

            // LEGACY **
            switch (thumbSize)
            {
                case ThumbnailSizes.Small:
                    this.DesiredSize = new Size(50, 50);
                    break;

                case ThumbnailSizes.Medium:
                    this.DesiredSize = new Size(100, 100);
                    break;

                case ThumbnailSizes.Large:
                    this.DesiredSize = new Size(200, 200);
                    break;

                case ThumbnailSizes.ExtraLarge:
                    this.DesiredSize = new Size(300, 300);
                    break;

                default:
                    this.DesiredSize = new Size(100, 100);
                    break;
            }
        }
        public static bool SendThumbnailsAsZipFile(FileBrowseRequest request, ThumbnailSizes thumbSize, ref BrowserSender bSender)
        {
            // We'll need a shell helper
            FatAttitude.ShellHelper sh = new FatAttitude.ShellHelper();

            // Set up temp directory
            string tempFolderName = Path.GetRandomFileName();
            string tempPath = Path.Combine (Functions.ZipTempFolder, tempFolderName);
            Directory.CreateDirectory(tempPath);

            // Go through the thumbnails (filter already applied, so these are pic files)
            FileBrowseResult fbResult = FileBrowseExporter.BrowsePath(request.FullPath, request.Filters);
            // Any files?
            if (fbResult.Files.Count < 1) return false;

            int SkipCounter = 0;
            int OutputCounter = 0;
            List<string> outputFiles = new List<string>();
            foreach (BrowseItem bItem in fbResult.Files)
            {
                // Skip items before batch
                if (request.ThumbnailsLimitToBatch)
                    if (request.ThumbnailsBatch > 0)
                        if (SkipCounter++ < (request.ThumbnailsBatchSize * request.ThumbnailsBatch))
                            continue;

                string strFullPath = Path.Combine(fbResult.BaseDirectory, bItem.Name);
                string strLog = ""; // ignore log
                Bitmap bmp = sh.ThumbnailForFile(strFullPath, thumbSize, ref strLog);

                string fnSansExtension = Path.GetFileNameWithoutExtension(bItem.Name);
                string strOutputFileFullPath = Path.Combine(tempPath,  (fnSansExtension + "_thumb.jpg" ) );
                bmp.Save(strOutputFileFullPath, ImageFormat.Jpeg);

                outputFiles.Add(strOutputFileFullPath);

                // End of batch?
                if (request.ThumbnailsLimitToBatch)
                    if (OutputCounter++ >= request.ThumbnailsBatchSize)
                        break;
            }

            // Now zip up the files
            string strOutputZipFile = Path.Combine(Functions.ZipTempFolder, (  Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip") );
            bool result = ZipHelper.CreateZipFileFromFiles(outputFiles, strOutputZipFile);

            // And send the zip file to the browser
            result &= (bSender.SendFileToBrowser(strOutputZipFile));
            File.Delete(strOutputZipFile);
            Directory.Delete(tempPath, true);

            return result;
        }
Exemple #4
0
        private int GetDimension(ThumbnailSizes size)
        {
            switch (size)
            {
            case ThumbnailSizes.S:
                return(150);

            case ThumbnailSizes.M:
                return(200);

            case ThumbnailSizes.L:
                return(250);

            case ThumbnailSizes.XL:
                return(300);

            case ThumbnailSizes.XXL:
                return(450);

            default: return(200);
            }
        }
Exemple #5
0
        public async Task <byte[]> GetThumbDataAsync(string id, ThumbnailSizes size)
        {
            var coll = GetCollection <MemoryItemModel>(MemoryVaultCollections.Memories);

            var filter = Builders <MemoryItemModel> .Filter.Eq(f => f.Id, ObjectId.Parse(id));

            var project = Builders <MemoryItemModel> .Projection.Expression(e => e.Thumbnails.Find(t => t.Size == size).Data);

            // p => p.Id == ObjectId.Parse(id)
            // proj => proj.Thumbnails.Any(q => q.Size == size)

            //var data = await coll.FindAsync<byte[]>(
            //	filter, project);

            var data = await coll
                       .Aggregate()
                       .Match(filter)
                       .Project(project)
                       .FirstOrDefaultAsync();

            return(data);
        }
Exemple #6
0
        public Bitmap ThumbnailForFile(string FilePath, ThumbnailSizes thumbSize, ref string txtLog)
        {
            if (
                (!File.Exists(FilePath)) &&
                (!Directory.Exists(FilePath))
                )
            {
                return(null);
            }

            if (ShellFile.IsPlatformSupported)
            {
                try
                {
                    using (ShellFile sf = ShellFile.FromFilePath(FilePath))
                    {
                        if (sf == null)
                        {
                            return(null);
                        }

                        ShellThumbnail thumb = sf.Thumbnail;
                        if (thumb == null)
                        {
                            return(null);
                        }

                        switch (thumbSize)
                        {
                        case ThumbnailSizes.Medium:
                            return(thumb.MediumBitmap);

                        case ThumbnailSizes.Large:
                            return(thumb.LargeBitmap);

                        case ThumbnailSizes.ExtraLarge:
                            return(thumb.ExtraLargeBitmap);

                        default:     //case ThumbnailSizes.Small:
                            return(thumb.SmallBitmap);
                        }
                    }
                }
                catch
                {
                    // Do not return; try legacy method
                }
            }

            // Use legacy method
            LegacyThumbnailExtractor2 tc = new LegacyThumbnailExtractor2(thumbSize);


            Bitmap bThumb = null;
            Bitmap bmpNew = null;

            bThumb = tc.GetThumbnail(FilePath);

            // No thumbnail returned - look for folder.jpg (for MP3s)
            if (bThumb != null)
            {
                bmpNew = (Bitmap)bThumb.Clone();
            }
            else
            {
                // NB: use a new thumbnail extractor
                string stub      = Path.GetDirectoryName(FilePath);
                string artworkFN = Path.Combine(stub, "folder.jpg");

                txtLog += "Artwork FN: " + artworkFN + Environment.NewLine;
                if (File.Exists(artworkFN))
                {
                    bThumb = tc.GetThumbnail(artworkFN);

                    if (bThumb != null)
                    {
                        bmpNew = (Bitmap)bThumb.Clone();
                    }
                }
            }

            return(bmpNew);
        }
        public Bitmap ThumbnailForFile(string FilePath, ThumbnailSizes thumbSize, ref string txtLog)
        {
            if (
                (!File.Exists(FilePath)) &&
                (!Directory.Exists(FilePath))
                )
                return null;

            if (ShellFile.IsPlatformSupported)
            {
                try
                {
                    using (ShellFile sf = ShellFile.FromFilePath(FilePath))
                    {
                        if (sf == null) return null;

                        ShellThumbnail thumb = sf.Thumbnail;
                        if (thumb == null) return null;

                        switch (thumbSize)
                        {
                            case ThumbnailSizes.Medium:
                                return thumb.MediumBitmap;

                            case ThumbnailSizes.Large:
                                return thumb.LargeBitmap;

                            case ThumbnailSizes.ExtraLarge:
                                return thumb.ExtraLargeBitmap;

                            default: //case ThumbnailSizes.Small:
                                return thumb.SmallBitmap;
                        }

                    }
                }
                catch
                {
                    // Do not return; try legacy method
                }
            }

            // Use legacy method
            LegacyThumbnailExtractor2 tc = new LegacyThumbnailExtractor2(thumbSize);

            Bitmap bThumb = null;
            Bitmap bmpNew = null;

            bThumb = tc.GetThumbnail(FilePath);

            // No thumbnail returned - look for folder.jpg (for MP3s)
            if (bThumb != null)
            {
                bmpNew = (Bitmap)bThumb.Clone();
            }
            else
            {
                // NB: use a new thumbnail extractor
                string stub = Path.GetDirectoryName(FilePath);
                string artworkFN = Path.Combine(stub, "folder.jpg");

                txtLog += "Artwork FN: " + artworkFN + Environment.NewLine;
                if (File.Exists(artworkFN))
                {
                    bThumb = tc.GetThumbnail(artworkFN);

                    if (bThumb != null)
                        bmpNew = (Bitmap)bThumb.Clone();
                }
            }

            return bmpNew;
        }
Exemple #8
0
        public static bool SendThumbnailsAsZipFile(FileBrowseRequest request, ThumbnailSizes thumbSize, ref BrowserSender bSender)
        {
            // We'll need a shell helper
            FatAttitude.ShellHelper sh = new FatAttitude.ShellHelper();

            // Set up temp directory
            string tempFolderName = Path.GetRandomFileName();
            string tempPath       = Path.Combine(Functions.ZipTempFolder, tempFolderName);

            Directory.CreateDirectory(tempPath);

            // Go through the thumbnails (filter already applied, so these are pic files)
            FileBrowseResult fbResult = FileBrowseExporter.BrowsePath(request.FullPath, request.Filters);

            // Any files?
            if (fbResult.Files.Count < 1)
            {
                return(false);
            }

            int           SkipCounter   = 0;
            int           OutputCounter = 0;
            List <string> outputFiles   = new List <string>();

            foreach (BrowseItem bItem in fbResult.Files)
            {
                // Skip items before batch
                if (request.ThumbnailsLimitToBatch)
                {
                    if (request.ThumbnailsBatch > 0)
                    {
                        if (SkipCounter++ < (request.ThumbnailsBatchSize * request.ThumbnailsBatch))
                        {
                            continue;
                        }
                    }
                }

                string strFullPath = Path.Combine(fbResult.BaseDirectory, bItem.Name);
                string strLog      = ""; // ignore log
                Bitmap bmp         = sh.ThumbnailForFile(strFullPath, thumbSize, ref strLog);

                string fnSansExtension       = Path.GetFileNameWithoutExtension(bItem.Name);
                string strOutputFileFullPath = Path.Combine(tempPath, (fnSansExtension + "_thumb.jpg"));
                bmp.Save(strOutputFileFullPath, ImageFormat.Jpeg);

                outputFiles.Add(strOutputFileFullPath);

                // End of batch?
                if (request.ThumbnailsLimitToBatch)
                {
                    if (OutputCounter++ >= request.ThumbnailsBatchSize)
                    {
                        break;
                    }
                }
            }

            // Now zip up the files
            string strOutputZipFile = Path.Combine(Functions.ZipTempFolder, (Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip"));
            bool   result           = ZipHelper.CreateZipFileFromFiles(outputFiles, strOutputZipFile);

            // And send the zip file to the browser
            result &= (bSender.SendFileToBrowser(strOutputZipFile));
            File.Delete(strOutputZipFile);
            Directory.Delete(tempPath, true);

            return(result);
        }
Exemple #9
0
        public async Task <IActionResult> Fetch(string id, ThumbnailSizes size)
        {
            var data = await _repo.GetThumbDataAsync(id, size);

            return(File(data, "image/png"));
        }