Example #1
0
            // Delegate Functions
            // Delegate Functions :: ThreadFunc
            //	TODO: Refactor
            /// <summary>
            ///	Downloads the cover and sets it in the database.
            /// </summary>
            /// <remarks>
            ///	<para>
            ///	This is the main method of the thread.
            ///	</para>
            ///
            ///	<para>
            ///	If the cover has trouble downloading, this thread
            ///	sleeps for a minute. In order to not overload the
            ///	server, this thread sleeps for a second between
            ///	downloads. The Amazon API requires that we do this.
            ///	</para>
            /// </remarks>
            private void ThreadFunc()
            {
                while (true)
                {
                    while (queue.Count > 0)
                    {
                        Album  album  = (Album)queue.Dequeue();
                        Pixbuf pixbuf = null;

                        // Download Cover
                        try {
                            pixbuf = getter.DownloadFromAmazon(album);
                        } catch (WebException) {
                            // Temporary web problem (Timeout etc.) - re-queue
                            Thread.Sleep(60000);                              // wait for a minute first
                            queue.Enqueue(album);
                            continue;
                        } catch (Exception) {
                        }

                        string key = album.Key;

                        // Check if cover has been modified while we were
                        //   downloading
                        if (Global.CoverDB.Covers [key] != null)
                        {
                            continue;
                        }

                        // Add border and set cover
                        if (pixbuf == null)
                        {
                            Global.CoverDB.UnmarkAsBeingChecked(key);
                        }
                        else
                        {
                            pixbuf = getter.AddBorder(pixbuf);
                            Global.CoverDB.SetCover(key, pixbuf);
                        }

                        new IdleData(album, pixbuf);
                    }

                    Thread.Sleep(1000);
                }
            }
Example #2
0
            // Delegate Functions
            // Delegate Functions :: ThreadFunc
            /// <summary>
            ///	Downloads the cover and sets it in the database.
            /// </summary>
            /// <remarks>
            ///	This is the main method of the thread.
            /// </remarks>
            private void ThreadFunc()
            {
                try {
                    pixbuf = getter.Download(url);
                    pixbuf = getter.AddBorder(pixbuf);
                } catch {
                }

                // Check if cover has been modified while we were downloading
                if (Global.CoverDB.Covers [key] != null)
                {
                    return;
                }

                if (pixbuf != null)
                {
                    Global.CoverDB.SetCover(key, pixbuf);
                }

                // Also do this if it is null, as we need to remove the
                // downloading image
                GLib.IdleHandler idle = new GLib.IdleHandler(SignalIdle);
                GLib.Idle.Add(idle);
            }