Exemplo n.º 1
0
        private void Remove(ICollection podcasts)
        {
            if (podcasts == null)
            {
                throw new ArgumentNullException("podcasts");
            }

            lock (podcasts.SyncRoot)
            {
                foreach (PodcastInfo pi in podcasts)
                {
                    try
                    {
                        RemovePodcast(pi, false);
                    }
                    catch {
                        continue;
                    }
                }

                PodcastDBManager.Delete(podcasts)
                ;
                UpdateCounts();
            }
        }
Exemplo n.º 2
0
        internal void Delete()
        {
            lock (podcasts.SyncRoot)
            {
                podcasts.Clear();
            }

            PodcastDBManager.Delete(this);
        }
Exemplo n.º 3
0
        internal void Commit()
        {
            int insertion = PodcastDBManager.Commit(this);

            if (feed_id == 0)
            {
                feed_id = insertion;
            }
        }
        private static void LoadFromDatabase()
        {
            DateTime stop;
            DateTime start;
            TimeSpan span;

            start = DateTime.Now;

            try
            {
                Library.Clear();

                ICollection feeds = PodcastDBManager.LoadPodcastFeeds();

                Library.AddPodcastFeeds(feeds, false);

                ArrayList podcast_list = new ArrayList();

                foreach (PodcastFeedInfo feed in feeds)
                {
                    feed.UpdateStarted  += OnFeedUpdateStatusChanged;
                    feed.UpdateFinished += OnFeedUpdateStatusChanged;

                    foreach (PodcastInfo pi in feed.Podcasts)
                    {
                        if (pi.IsActive)
                        {
                            podcast_list.Add(pi);
                        }
                    }
                }

                Library.AddPodcasts(podcast_list, false);

                InitSource();

                stop = DateTime.Now;
                span = stop - start;

                lock (init_sync)
                {
                    initialized = true;
                }

                Console.WriteLine(Catalog.GetString("Loading Podcast Feeds:  {0} ms"), span.Milliseconds);
            } catch {
                Console.WriteLine(Catalog.GetString("Unable to load Podcast DB"));
            } finally
            {
                lock (init_sync)
                {
                    initializing = false;
                }
            }
        }
        public int RemovePodcasts(ICollection podcasts, bool update)
        {
            if (podcasts == null)
            {
                throw new ArgumentNullException("podcasts");
            }

            ArrayList removed_podcasts = new ArrayList();

            lock (PodcastSync)
            {
                foreach (PodcastInfo pi in podcasts)
                {
                    if (pi != null)
                    {
                        try
                        {
                            if (RemovePodcastFromLibrary(pi, false))
                            {
                                removed_podcasts.Add(pi);
                            }
                        } catch {
                            continue;
                        }
                    }
                }

                if (update && (removed_podcasts.Count > 0))
                {
                    PodcastEventArgs args;

                    if (removed_podcasts.Count == 1)
                    {
                        args = new PodcastEventArgs(removed_podcasts[0] as PodcastInfo);
                    }
                    else
                    {
                        args = new PodcastEventArgs(removed_podcasts);
                    }

                    try {
                        UpdateParentFeeds(removed_podcasts);
                        EmitPodcastRemoved(args);
                    } finally {
                        PodcastDBManager.Deactivate(removed_podcasts);
                    }
                }
            }

            return(removed_podcasts.Count);
        }
Exemplo n.º 6
0
        private void RemovePodcast(PodcastInfo pi, bool update)
        {
            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            lock (podcasts.SyncRoot)
            {
                podcasts.Remove(pi);

                if (update)
                {
                    PodcastDBManager.Delete(pi);
                    UpdateCounts();
                }
            }
        }
        internal static void Initialize(PodcastPlugin plugin)
        {
            lock (init_sync)
            {
                if (initializing || initialized)
                {
                    return;
                }

                disposed     = false;
                initializing = true;
            }

            DownloadCore.Initialize();
            DownloadCore.MaxDownloads = 2;

            DownloadCore.DownloadCompleted   += OnDownloadCompletedHandler;
            DownloadCore.DownloadTaskStarted += OnDownloadTaskStartedHandler;
            DownloadCore.DownloadTaskStopped += OnDownloadTaskStoppedHandler;

            DownloadCore.DownloadDropped    += OnDownloadDroppedHandler;
            DownloadCore.DownloadRegistered += OnDownloadRegisteredHandler;
            DownloadCore.RegistrationFailed += OnRegistrationFailedHandler;

            downloads = new Hashtable();

            Library     = new PodcastLibrary();
            FeedFetcher = new PodcastFeedFetcher();

            Plugin = plugin;

            PodcastDBManager.InitPodcastDatabase();

            ServicePointManager.CertificatePolicy = new PodcastCertificatePolicy();

            if (Globals.Library.IsLoaded)
            {
                LoadFromDatabase();
            }
            else
            {
                Globals.Library.Reloaded += OnLibraryReloaded;
            }
        }
        private bool AddPodcastToLibrary(PodcastInfo pi)
        {
            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            bool ret = false;

            if (pi == null)
            {
                return(ret);
            }

            if (!podcasts.ContainsKey(pi.Key) && pi.IsActive)
            {
                //bool commit = false;

                podcasts.Add(pi.Key, pi);

                /*if (pi.ID == 0) {
                 * commit = true;
                 * }*/

                if (pi.Track != null)
                {
                    AddTrack(pi.Track, pi, true);
                } /*else if (pi.Track == null && pi.IsDownloaded) {
                   * pi.IsDownloaded = false;
                   * commit = true;
                   * }*/


                // TODO move this into PodcastInfo
                if (pi.ID == 0)
                {
                    pi.ID = PodcastDBManager.Commit(pi);
                }

                ret = true;
            }

            return(ret);
        }
        private bool RemovePodcastFromLibrary(PodcastInfo pi, bool commit_podcast)
        {
            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            if (pi.IsQueued)
            {
                return(false);
            }

            podcasts.Remove(pi.Key);

            if (pi.Track != null)
            {
                ThreadAssist.ProxyToMain(delegate {
                    RemoveTrack(pi.Track, true);
                });
            }

            if (!pi.IsActive)
            {
                return(true);
            }
            else
            {
                pi.IsActive = false;
            }

            if (commit_podcast)
            {
                PodcastDBManager.Deactivate(pi);
            }

            return(true);
        }
Exemplo n.º 10
0
        private static void OnDownloadCompletedHandler(object sender,
                                                       DownloadCompletedEventArgs args)
        {
            DownloadInfo dif       = args.DownloadInfo;
            SafeUri      local_uri = new SafeUri(args.LocalUri);

            if (dif == null || local_uri == null)
            {
                return;
            }

            PodcastInfo pi = null;

            lock (downloads.SyncRoot)
            {
                if (downloads.Contains(dif))
                {
                    pi = downloads [args.DownloadInfo] as PodcastInfo;
                }
            }

            if (pi != null)
            {
                TrackInfo ti = null;

                try
                {
                    try
                    {
                        ti = new LibraryTrackInfo(local_uri.LocalPath);
                    }
                    catch (ApplicationException)
                    {
                        ti = Globals.Library.TracksFnKeyed
                             [PathUtil.MakeFileNameKey(local_uri)] as TrackInfo;
                    }
                }
                catch (Exception e)
                {
                    PodcastErrorsSource.Instance.AddError(
                        local_uri.ToString(),
                        Catalog.GetString("Unable to add file to library"),
                        e
                        );
                }

                pi.IsDownloaded = true;

                if (ti != null)
                {
                    pi.Track = ti;
                }
                else
                {
                    pi.DownloadFailed = true;
                    PodcastDBManager.Commit(pi);
                    return;
                }

                pi.LocalPath = local_uri.ToString();
                PodcastDBManager.Commit(pi);
                pi.Feed.UpdateCounts();

                ThreadAssist.ProxyToMain(delegate {
                    Library.AddTrack(ti, pi, true);
                });
            }

            source.Update();
        }