Exemple #1
0
        public void UpdateMenu()
        {
            logger.Info("Создаем меню новостей..");
            var newsMenu = new Menu();
            MenuItemId <SyndicationItem> newsItem;

            foreach (var news in viewModel.News)
            {
                Label itemLabel = new Label();
                itemLabel.Markup = ItemFormat(news.Item.Title.Text, news.Read);
                newsItem         = new MenuItemId <SyndicationItem>();
                newsItem.Add(itemLabel);
                newsItem.ID            = news.Item;
                newsItem.TooltipMarkup = String.Format("<b>{0:D}</b> {1}", news.Item.PublishDate, news.Item.Summary.Text);
                newsItem.Activated    += OnNewsActivated;
                newsMenu.Append(newsItem);
            }
            this.Submenu = newsMenu;
            UpdateIcon();
            newsMenu.ShowAll();
            logger.Info("Ок");
        }
Exemple #2
0
        private void ThreadWorks()
        {
            logger.Info("Поток: Получаем ленты новостей.");
            SyndicationFeed mainFeed = new SyndicationFeed();

            foreach (var feed in MainNewsFeed.NewsFeeds)
            {
                if (!feed.Active)
                {
                    continue;
                }
                SyndicationFeed syndicationFeed;
                try
                {
                    using (XmlReader reader = XmlReader.Create(feed.FeedUri.AbsoluteUri))
                    {
                        syndicationFeed = SyndicationFeed.Load(reader);
                    }
                    syndicationFeed.Id = feed.Id;
                    syndicationFeed.Items.ToList().ForEach(i => i.SourceFeed = syndicationFeed);
                }
                catch (Exception ex)
                {
                    logger.Warn(ex, "Не удалось прочитать feed");
                    continue;
                }
                SyndicationFeed tempFeed = new SyndicationFeed(
                    mainFeed.Items.Union(syndicationFeed.Items).OrderByDescending(u => u.PublishDate));

                mainFeed = tempFeed;
            }
            logger.Info("Создаем меню новостей..");
            Application.Invoke(delegate {
                logger.Info("Запуск операций в основном потоке..");
                UnreadNewsCount = 0;
                var newsMenu    = new Menu();
                MenuItemId <SyndicationItem> newsItem;
                foreach (var news in mainFeed.Items)
                {
                    Label itemLabel = new Label();
                    if (MainNewsFeed.ItemIsRead(news))
                    {
                        itemLabel.Text = news.Title.Text;
                    }
                    else
                    {
                        itemLabel.Markup = String.Format("<b>{0}</b>", news.Title.Text);
                        UnreadNewsCount++;
                    }
                    newsItem = new MenuItemId <SyndicationItem> ();
                    newsItem.Add(itemLabel);
                    newsItem.ID            = news;
                    newsItem.TooltipMarkup = String.Format("<b>{0:D}</b> {1}", news.PublishDate, news.Summary.Text);
                    newsItem.Activated    += OnNewsActivated;
                    newsMenu.Append(newsItem);
                }
                this.Submenu = newsMenu;
                UpdateIcon();
                newsMenu.ShowAll();
                MainNewsFeed.SaveFirstRead();
                logger.Info("Ок");
            });
        }
        private void ThreadWorks()
        {
            logger.Info ("Поток: Получаем ленты новостей.");
            SyndicationFeed mainFeed = new SyndicationFeed();
            foreach (var feed in MainNewsFeed.NewsFeeds)
            {
                if (!feed.Active)
                    continue;
                SyndicationFeed syndicationFeed;
                try
                {
                    using (XmlReader reader = XmlReader.Create(feed.FeedUri.AbsoluteUri))
                    {
                        syndicationFeed = SyndicationFeed.Load(reader);
                    }
                    syndicationFeed.Id = feed.Id;
                    syndicationFeed.Items.ToList().ForEach(i => i.SourceFeed = syndicationFeed);
                }
                catch(Exception ex)
                {
                    logger.Warn (ex, "Не удалось прочитать feed");
                    continue;
                }
                SyndicationFeed tempFeed = new SyndicationFeed(
                                                   mainFeed.Items.Union(syndicationFeed.Items).OrderByDescending(u => u.PublishDate));

                mainFeed = tempFeed;
            }
            logger.Info ("Создаем меню новостей..");
            Application.Invoke (delegate {
                logger.Info ("Запуск операций в основном потоке..");
                UnreadNewsCount = 0;
                var newsMenu = new Menu ();
                MenuItemId<SyndicationItem> newsItem;
                foreach (var news in mainFeed.Items) {
                    Label itemLabel = new Label ();
                    if (MainNewsFeed.ItemIsRead (news))
                        itemLabel.Text = news.Title.Text;
                    else {
                        itemLabel.Markup = String.Format ("<b>{0}</b>", news.Title.Text);
                        UnreadNewsCount++;
                    }
                    newsItem = new MenuItemId<SyndicationItem> ();
                    newsItem.Add (itemLabel);
                    newsItem.ID = news;
                    newsItem.TooltipMarkup = String.Format ("<b>{0:D}</b> {1}", news.PublishDate, news.Summary.Text);
                    newsItem.Activated += OnNewsActivated;
                    newsMenu.Append (newsItem);
                }
                this.Submenu = newsMenu;
                UpdateIcon ();
                newsMenu.ShowAll ();
                MainNewsFeed.SaveFirstRead ();
                logger.Info("Ок");
            });
        }