/// <summary>
        /// Handles the DoWork event of the queued background worker.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PanoClient.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance
        /// containing the event data.</param>
        void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e)
        {
            string extension = e.Argument as string;

            // Should we continue processing this item?
            // The callback checks if the item is already cached.
            if (!OnCanContinueProcessing(extension))
            {
                e.Cancel = true;
                return;
            }

            // Read shell info
            ShellInfoExtractor info = ShellInfoExtractor.FromFile(extension);

            // Return the info
            CacheItem result = null;

            if ((info.SmallIcon == null || info.LargeIcon == null) && !RetryOnError)
            {
                result = new CacheItem(extension, info.SmallIcon, info.LargeIcon, info.FileType, CacheState.Error);
            }
            else
            {
                result = new CacheItem(extension, info.SmallIcon, info.LargeIcon, info.FileType, CacheState.Cached);
            }

            e.Result = result;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Raises the DoWork event.
 /// </summary>
 /// <param name="e">A <see cref="QueuedWorkerDoWorkEventArgs"/> that contains event data.</param>
 protected virtual void OnDoWork(QueuedWorkerDoWorkEventArgs e)
 {
     if (DoWork != null)
     {
         DoWork(this, e);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the DoWork event of the queued background worker.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PanoClient.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance
        /// containing the event data.</param>
        void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e)
        {
            CacheRequest request = e.Argument as CacheRequest;

            // Should we continue processing this item?
            // The callback checks the following and returns false if
            //   the item is already cached -OR-
            //   the item is in the edit cache -OR-
            //   the item is outside the visible area (only if the CacheMode is OnDemand).
            if (!OnCanContinueProcessing(request))
            {
                e.Cancel = true;
                return;
            }

            Image  thumb        = null;
            string diskCacheKey = request.Adaptor.GetUniqueIdentifier(request.VirtualItemKey, request.Size, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC);

            // Check the disk cache
            using (Stream stream = diskCache.Read(diskCacheKey))
            {
                if (stream.Length > 0)
                {
                    thumb = new Bitmap(stream);
                }
            }

            // Extract the thumbnail from the source image.
            if (thumb == null)
            {
                thumb = request.Adaptor.GetThumbnail(request.VirtualItemKey, request.Size, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC);
                // Save to disk cache
                if (thumb != null)
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        thumb.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        diskCache.Write(diskCacheKey, stream);
                    }
                }
            }

            // Return the thumbnail
            CacheItem result = null;

            if (thumb == null && !RetryOnError)
            {
                result = new CacheItem(request.Guid, request.Size, null, CacheState.Error, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC);
            }
            else
            {
                result = new CacheItem(request.Guid, request.Size, thumb, CacheState.Cached, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC);
            }

            e.Result = result;
        }
        /// <summary>
        /// Handles the DoWork event of the queued background worker.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PanoClient.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance
        /// containing the event data.</param>
        void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e)
        {
            CacheRequest request = e.Argument as CacheRequest;

            // Should we continue processing this item?
            // The callback checks the following and returns false if
            //   the item is in the edit cache -OR-
            //   the item was fetched by the UI thread before.
            if (!OnCanContinueProcessing(request))
            {
                e.Cancel = true;
                return;
            }

            // Get item details
            e.Result = request.Adaptor.GetDetails(request.VirtualItemKey, request.UseWIC);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Used by the worker thread to process items.
        /// </summary>
        private void Run()
        {
            while (!Stopping)
            {
                lock (lockObject)
                {
                    // Wait until we have pending work items
                    if (paused || IsWorkQueueEmpty())
                    {
                        Monitor.Wait(lockObject);
                    }
                }

                // Loop until we exhaust the queue
                bool queueFull = true;
                while (queueFull && !Stopping && !Paused)
                {
                    // Get an item from the queue
                    AsyncOperation asyncOp  = null;
                    object         request  = null;
                    int            priority = 0;
                    lock (lockObject)
                    {
                        // Check queues
                        Utility.Tuple <AsyncOperation, int> work = GetWork();
                        asyncOp  = work.Item1;
                        priority = work.Item2;
                        if (asyncOp != null)
                        {
                            request = asyncOp.UserSuppliedState;
                        }

                        // Check if the item was removed
                        if (request != null && cancelledItems.ContainsKey(request))
                        {
                            request = null;
                        }
                    }

                    if (request != null)
                    {
                        Exception error  = null;
                        object    result = null;
                        bool      cancel = false;
                        // Start the work
                        try
                        {
                            // Raise the do work event
                            QueuedWorkerDoWorkEventArgs doWorkArg = new QueuedWorkerDoWorkEventArgs(request, priority);
                            OnDoWork(doWorkArg);
                            result = doWorkArg.Result;
                            cancel = doWorkArg.Cancel;
                        }
                        catch (Exception e)
                        {
                            error = e;
                        }

                        // Raise the work complete event
                        QueuedWorkerCompletedEventArgs workCompletedArg = new QueuedWorkerCompletedEventArgs(request, result, priority, error, cancel);
                        if (!Stopping)
                        {
                            asyncOp.PostOperationCompleted(workCompletedCallback, workCompletedArg);
                        }
                    }
                    else if (asyncOp != null)
                    {
                        asyncOp.OperationCompleted();
                    }

                    // Check if the cache is exhausted
                    lock (lockObject)
                    {
                        queueFull = !IsWorkQueueEmpty();
                    }
                }
            }
        }