Ejemplo n.º 1
0
        private bool IsFeedValidOrJustAddToList(IRSSFeed newFeed)
        {
            MessageShow.ShowMessage(this, "Desktop Aggregator will now attempt to read the feed's posts. Please Wait while attempting reading",
                                    "First RSS Reading");
            System.Exception newFeedExecption = null;
            var myDelegate = new System.EventHandler <RSSErrorArgs>(delegate(object sender, RSSErrorArgs e) { newFeedExecption = e.RSSException; });

            newFeed.RSSReadingError += myDelegate;

            newFeed.GetAllItemsFromWeb(false, false);

            newFeed.RSSReadingError -= myDelegate;
            DialogResult result;

            if (newFeedExecption != null)
            {
                result = MessageShow.ShowMessage(this,
                                                 "it appears there were some error reading the feed posts. The Error is: \n " +
                                                 newFeedExecption.Message + "\n \n Do you still wants to add this feed?",
                                                 "RSS Reading Error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
            }
            else
            {
                result = MessageShow.ShowMessage(this,
                                                 "it appears the feed is valid so it will be added to the feeds list",
                                                 "RSS Reading completed successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return(result == DialogResult.OK || result == DialogResult.Yes);
        }
        public async Task <List <IRSSPost> > GetRSSItemsFromFeeds(List <IRSSFeed> feedsToRefresh, bool unreadOnly, bool fromweb)
        {
            if (BusyRefreshingFromWeb)
            {
                return(null);
            }

            string oldDispalyName = DisplayFeedsName;

            //chkbUnreadposts.Checked = unreadOnly;
            //tpFeeds.Text = string.Format("Feeds Viewer (Selected Feeds: {0})", DisplayFeedsName);
            //tstxtbSearchFeed.Text = "Search in feeds: " + DisplayFeedsName;
            // LogInThisForm(string.Empty, true); //clear log
            OnLogOperation(this, new LogArgs(DateTime.Now + ": Start refreshing feed(s): " + DisplayFeedsName));
            string refreshMsg = string.Format("Start refreshing: {0} at {1}", DisplayFeedsName, DateTime.Now);

            OnWebRefresh(this, new LogArgs(refreshMsg));



            var posts    = new List <IRSSPost>();
            int i        = 0;
            int finished = 0;

            foreach (var feed in feedsToRefresh)
            {
                IRSSFeed feed1 = feed;
                var      items = await feed1.GetAllItemsFromWeb(false, !Settings.AppRSSSetings.NotifyOnRSSErrors);

                posts.AddRange(items);
                OnLogOperation(this,
                               new LogArgs(string.Format("{0}: creating task {1} for feed {2}",
                                                         DateTime.Now, i, feed1.RSSName)));
                var op = string.Format(
                    "{0}: Task  finished for feed {1}. Time: {2} Seconds, Download size: {3} KB. {4} new posts",
                    DateTime.Now, feed1.RSSName,
                    feed1.LastDownloadTime.TotalSeconds,
                    feed1.LastDownloadSizeKb,
                    feed1.LastNewPostsCount);
                OnLogOperation(this, new LogArgs(string.Format(op)));
                //string msg = string.Format("{0} Finished feeds: {1}/{2}",
                //                           Resources.UnReadRSSPostsReading,
                //                           ++finished, numOfTasks);
                //Util.Utils.UpdateControl(chkbUnreadposts, msg);
                //if (tasks[i1].Status == TaskStatus.RanToCompletion)
                //{
                //    var results = tasks[i1].Result.ToList();
                //    var unreadposts =
                //        feed1.GetAllItemsFromCache(unreadOnly, true, true).
                //            ToList();
                //    posts.AddRange(unreadposts);
                //    DisplayPosts = posts;
                //    if (unreadposts.Count > 0)
                //    {
                //       // DisplayRSSItems(DisplayPosts, dgvRSSItems);
                //      //  UpdateFeedsCountsAfterChange();
                //    }
                //}
            }

            OnWebEndRefresh(this, new LogArgs(refreshMsg));

            // Util.Utils.UpdateControl(chkbUnreadposts, oldDispalyName);


            DisplayPosts = posts;
            DisplayRSSItems(unreadOnly);
            //UpdateFeedsCountsAfterChange(true);
            ulong totalFeedsKB = 0;

            foreach (RSSFeedsContainer rssGrouping in FeedsGroup)
            {
                foreach (var feed in rssGrouping.GetFeeds())
                {
                    totalFeedsKB += feed.TotalDownloadedKB;
                }
            }

            TotalDownloadedKB = totalFeedsKB;

            //save feeds to disk?
            if (Settings.AppRSSSetings.SaveRSSFeedsOnEveryRefresh && fromweb && posts.Count > 0)
            {
                SaveAllFeedsToDisk();
            }

            // var postsarg = new RefreshArgs(posts);
            //  OnWebRefresh(this, postsarg);
            //Util.Utils.UpdateControl(tpFeeds,string.Format("Feeds Viewer (Selected Feeds: {0})", oldDispalyName));

            return(posts);
        }