コード例 #1
0
        public LoadVideos()
        {
            // scan file system for videos
            backgroundWorkerScanSource = new BackgroundWorkerScanSource();
            backgroundWorkerScanSource.Initialize();
            backgroundWorkerScanSource.backgroundWorkerScanSource_ProgressChanged    += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
            backgroundWorkerScanSource.backgroundWorkerScanSource_RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerScanSource_RunWorkerCompleted);

            // filter existing list for videos
            backgroundWorkerFilterSource = new BackgroundWorkerFilterSource();
            backgroundWorkerFilterSource.Initialize();
            backgroundWorkerFilterSource.backgroundWorkerFilterSource_ProgressChanged    += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
            backgroundWorkerFilterSource.backgroundWorkerFilterSource_RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerFilterSource_RunWorkerCompleted);

            // build gallery images for video items loaded
            buildGalleryImages = new BuildGalleryImages();
            buildGalleryImages.backgroundWorkerBuildGalleryImages_RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerBuildGalleryImages_RunWorkerCompleted);

            // calc stats for video items loaded
            calcVideoInfoStats = new CalcVideoInfoStats();
            calcVideoInfoStats.backgroundWorkerCalcStats_RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerCalcStats_RunWorkerCompleted);
        }
        public List <VideoInfo> BuildImages(List <VideoInfo> videoInfos, DoWorkEventArgs doWorkEvent)
        {
            if (BuildGalleryImages.ThumbnailsAlreadySet())
            {
                return(videoInfos);
            }

            // Abort the operation if the user has canceled.
            // Note that a call to CancelAsync may have set
            // CancellationPending to true just after the
            // last invocation of this method exits, so this
            // code will not have the opportunity to set the
            // DoWorkEventArgs.Cancel flag to true. This means
            // that RunWorkerCompletedEventArgs.Cancelled will
            // not be set to true in your RunWorkerCompleted
            // event handler. This is a race condition.

            if (backgroundWorker.CancellationPending)
            {
                doWorkEvent.Cancel = true;
                return(null);
            }

            int nbrVideoInfos = videoInfos.Count();
            int nbrPosters    = 0;

            foreach (VideoInfo videoInfo in videoInfos)
            {
                if (videoInfo.filter)
                {
                    if (videoInfo.files.posterThumbnail != null)
                    {
                        videoInfo.files.posterThumbnail.Dispose();
                    }
                    continue;
                }

                // no files or no video, so skip
                if (videoInfo.files == null || videoInfo.files.video == null)
                {
                    continue;
                }

                GalleryImageThumbnailInfo galleryImageThumbnailInfo = BuildGalleryImages.GetCachedThumbnail(videoInfo);
                videoInfo.files.posterThumbnail = galleryImageThumbnailInfo.thumbnail;

                nbrPosters++;

                // Thread.Sleep(1000); // dev


                // meh, smooth out update progress
                if (nbrPosters % 10 == 0)
                {
                    percentComplete = 100 - (int)Math.Floor((decimal)(nbrVideoInfos - nbrPosters) / nbrVideoInfos * 100);
                    string progressMessage = "";
                    if (galleryImageThumbnailInfo.fromCache)
                    {
                        progressMessage += "Using Gallery cache";
                    }
                    else if (galleryImageThumbnailInfo.createdCache)
                    {
                        progressMessage += "Creating Gallery cache";
                    }
                    else
                    {
                        progressMessage += "Building Gallery";
                    }
                    progressMessage += "..";

                    backgroundWorker.ReportProgress(percentComplete, progressMessage);

                    if (backgroundWorker.CancellationPending)
                    {
                        doWorkEvent.Cancel = true;
                        return(null);
                    }
                }
            }



            percentComplete = 100;
            backgroundWorker.ReportProgress(percentComplete, "Completed Gallery");

            // meh, so completed shows
            Thread.Sleep(500);


            return(videoInfos);
        }