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

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

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

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

            foreach(KeyValuePair<string,FeedSubscription> pair in Subscriptions.Instance.Dictionary)
            {
                var feed = new Feed(pair.Value);
                this._feeds.Add(feed);
                feed.StateChanged += OnChildStateChanged;
                tasks[i] = Task.Factory.StartNew(() => TaskProcessFeed(feed));
                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("Feeds module caught an exception while running feed processing task:  {0}", exception));
                }
            }

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

                if (this._moduleNode.Nodes.Count > 0) this._moduleNode.Nodes.Clear();
                foreach (Task<Feed> task in tasks)
                {
                    this._moduleNode.Nodes.Add(task.Result);
                    foreach(Story story in task.Result.Stories)
                    {
                        task.Result.Nodes.Add(story);
                    }
                }

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

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

            var feedSubscription = new FeedSubscription { Name = "test-feed", Url = link };

            using (var feed = new Feed(feedSubscription))
            {
                if (!feed.IsValid()) return false;

                string feedName = "";
                if (InputBox.Show(i18n.AddNewFeedTitle, i18n.AddNewFeedMessage, ref feedName) != DialogResult.OK) return true;
                feedSubscription.Name = feedName;

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

            return true;
        }
Example #3
0
 // The module updater task.
 private static Feed TaskProcessFeed(Feed feed)
 {
     feed.Update();
     return feed;
 }