Beispiel #1
0
        private void UpdatePodcasts()
        {
            if (this.RefreshingData) return;
            this.RefreshingData = true;

            Module.UITreeView.AsyncInvokeHandler(() => { this._moduleNode.Text = @"Updating podcasts.."; });
            this._podcasts.Clear();

            Workload.WorkloadManager.Instance.Add(Subscriptions.Instance.Dictionary.Count);

            int i = 0;
            var tasks = new Task<Podcast>[Subscriptions.Instance.Dictionary.Count];

            foreach (KeyValuePair<string, PodcastSubscription> pair in Subscriptions.Instance.Dictionary)
            {
                var podcast = new Podcast(pair.Value);
                this._podcasts.Add(podcast);
                podcast.StateChanged += OnChildStateChanged;
                tasks[i] = Task.Factory.StartNew(() => TaskProcessPodcast(podcast));
                i++;
            }

            var tasksWaitQueue = tasks;

            while (tasksWaitQueue.Length > 0)
            {
                int taskIndex = Task.WaitAny(tasksWaitQueue);
                tasksWaitQueue = tasksWaitQueue.Where((t) => t != tasksWaitQueue[taskIndex]).ToArray();
                Workload.WorkloadManager.Instance.Step();
            }

            try { Task.WaitAll(tasks); }
            catch (AggregateException aggregateException)
            {
                foreach (var exception in aggregateException.InnerExceptions)
                {
                    LogManager.Instance.Write(LogMessageTypes.Error, string.Format("Podcasts module caught an exception while running podcast processing task:  {0}", exception));
                }
            }

            Module.UITreeView.AsyncInvokeHandler(() =>
            {
                Module.UITreeView.BeginUpdate();

                if (this._moduleNode.Nodes.Count > 0) this._moduleNode.Nodes.Clear();
                foreach (Task<Podcast> task in tasks)
                {
                    this._moduleNode.Nodes.Add(task.Result);
                    foreach (Episode episode in task.Result.Episodes)
                    {
                        task.Result.Nodes.Add(episode);
                    }
                }

                Module.UITreeView.EndUpdate();
                this._moduleNode.Text = @"Podcasts";
            });

            this.RefreshingData = false;
        }
Beispiel #2
0
        // Tries parsing a drag & dropped link to see if it's a podcast and parsable.
        public override bool AddSubscriptionFromUrl(string link)
        {
            if (Subscriptions.Instance.Dictionary.ContainsKey(link))
            {
                MessageBox.Show(string.Format(i18n.PodcastSubscriptionAlreadyExists, Subscriptions.Instance.Dictionary[link].Name), i18n.SubscriptionExists, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return true;
            }

            var podcastSubscription = new PodcastSubscription { Name = "test-podcast", Url = link };

            using (var podcast = new Podcast(podcastSubscription))
            {
                if (!podcast.IsValid()) return false;

                string podcastName = "";
                if (InputBox.Show(i18n.AddNewPodcastTitle, i18n.AddNewPodcastMessage, ref podcastName) != DialogResult.OK) return true;
                podcastSubscription.Name = podcastName;

                if (Subscriptions.Instance.Add(podcastSubscription)) this.MenuRefresh(this, new EventArgs());
            }

            return true;
        }
Beispiel #3
0
 private static Podcast TaskProcessPodcast(Podcast podcast)
 {
     podcast.Update();
     return podcast;
 }