コード例 #1
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;
        }
コード例 #2
0
        private void SendFileThumbnail(string fileName, FatAttitude.ThumbnailSizes thumbSize, ref BrowserSender browserSender)
        {
            // Find file or folder?
            if (
                (! File.Exists(fileName)) && (! Directory.Exists(fileName))
                )
            {
                bool foo = browserSender.Send404Page();
                return;
            }

            FatAttitude.ShellHelper sh = new FatAttitude.ShellHelper();
            string strLog = ""; // ignore
            Bitmap thumb = sh.ThumbnailForFile(fileName, thumbSize, ref strLog);
            if (thumb == null)
            {
                browserSender.SendFileToBrowser("thumbnail_default.png", true, false);
                return;
            }

            byte[] outputdata =  ImageResizer.ImageToByteArray(thumb, ImageFormat.Jpeg);

            // Send to browser
            bool foo2 = browserSender.SendDataToBrowser("image/jpeg", outputdata);
        }
コード例 #3
0
        public Bitmap ThumbnailForWMPItem(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType)
        {
            // Get URL
            MimeType = "";
            string picFileName;
            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();

            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute(WMPMatchAttribute, itemID);
            if (pl.count == 0)
            {
                Functions.WriteLineToLogFile("Warning - no items found in library with ID " + itemID);
                return null;
            }

            //if (pl.count != 1) Functions.WriteLineToLogFile("Warning - more than one item found in library with ID " + itemID);

            IWMPMedia pic = pl.get_Item(0);

            picFileName = pic.sourceURL;

            WMPlayer.close();

            if (useFolderArtIfFound)
            {
                string itemFolder = Path.GetDirectoryName(picFileName);
                string folderArtFN = Path.Combine(itemFolder,"folder.jpg");
                if (File.Exists(folderArtFN))
                    picFileName = folderArtFN;
            }

            ShellHelper shellHelper = new ShellHelper();
            MimeType = "image/jpeg";
            string strLog = ""; // ignore
            switch (size)
            {
                case Thumbnail_Sizes.Small:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog);

                case Thumbnail_Sizes.Medium:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Medium, ref strLog);

                case Thumbnail_Sizes.Large:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Large, ref strLog);

                case Thumbnail_Sizes.ExtraLarge:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.ExtraLarge, ref strLog);

                default:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog);
            }
        }
コード例 #4
0
ファイル: PictureExporter.cs プロジェクト: piet5211/RPLiveTV
        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);
        }