Beispiel #1
0
        internal void Commit()
        {
            int insertion = PodcastDBManager.Commit(this);

            if (feed_id == 0)
            {
                feed_id = insertion;
            }
        }
        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 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();
        }