Example #1
0
        static void Main(string[] args)
        {
            // создание одного издателя событий
            var newsAggregator = new NewsAggregator();
            // создание трех наблюдателей
            var twitterWidget = new TwitterWidget();
            var lentaWidget   = new LentaWidget();
            var tvWidget      = new TvWidget();

            // подписка наблюдателей на событие NewsChanged издателя
            //System.Console.WriteLine(newsAggregator.NewsChanged);
            newsAggregator.NewsChanged += twitterWidget.Update;
            //System.Console.WriteLine(newsAggregator.NewsChanged);
            newsAggregator.NewsChanged += lentaWidget.Update;
            //System.Console.WriteLine(newsAggregator.NewsChanged);
            newsAggregator.NewsChanged += tvWidget.Update;
            //System.Console.WriteLine(newsAggregator.NewsChanged);

            newsAggregator.NewNewsAvailable();
            Console.WriteLine();

            newsAggregator.NewsChanged -= twitterWidget.Update;
            newsAggregator.NewNewsAvailable();
            Console.WriteLine();
            newsAggregator.NewNewsAvailable();

            Console.ReadLine();
        }
Example #2
0
        public void NotifyTwitter()
        {
            var aggregator = new NewsAggregator();
            var twitter    = new TwitterWidget();

            aggregator.RegistedWidget(twitter);

            aggregator.NotifyWidgets();
            aggregator.UnregisterWidget(twitter);

            twitter.Display();
        }
Example #3
0
    void Start()
    {
        NewsAggregator newsAggregator = new NewsAggregator();

        var twitterWidget = new TwitterWidget(newsAggregator);
        var lentaWidget   = new LentaWidget(newsAggregator);
        var tvWidget      = new TvWidget(newsAggregator);

        newsAggregator.NewNewsAvalible();
        Debug.Log("------------------------------------------------------------------------------");
        twitterWidget.RemoveFromSubject();
        newsAggregator.NewNewsAvalible();
    }
Example #4
0
        static void Main(string[] args)
        {
            //объявление новых наблюдателей (виджетов)
            var newsAggregator = new NewsAggregator();
            var twitterWidget  = new TwitterWidget(newsAggregator); // регистрация во время создания объекта
            var lentaWidget    = new LentaWidget(newsAggregator);
            var tvWidget       = new TvWidget(newsAggregator);

            //вызов метода, производящего обновление новостей
            newsAggregator.NewNewsAvailable();
            Console.WriteLine();
            newsAggregator.NewNewsAvailable();

            Console.ReadLine();
        }
Example #5
0
        static void Main(string[] args)
        {
            var newsAggregator = new NewsAggregator();

            var twitterWidget = new TwitterWidget(newsAggregator);
            var lentaWidget   = new LentaWidget(newsAggregator);
            var tvWidget      = new TvWidget(newsAggregator);

            newsAggregator.NewNewsAvailable();
            Console.WriteLine();
            twitterWidget.RemoveFormSubject();
            newsAggregator.NewNewsAvailable();

            Console.ReadLine();
        }
Example #6
0
        static void Main()
        {
            var newsAggregator = new NewsAggregator();

            var twitterWidget = new TwitterWidget(newsAggregator);
            var lentaWidget   = new LentaWidget(newsAggregator);
            var tvWidget      = new TvWidget(newsAggregator);

            newsAggregator.NewNewsAvailable();

            Console.WriteLine();

            twitterWidget.Unsubscribe();

            newsAggregator.NewNewsAvailable();
        }
Example #7
0
        static void Main(string[] args)
        {
            var newsAggregator = new NewsAggregator();

            var instagramWidget = new InstagramWidget();
            var twitterWidget   = new TwitterWidget();

            newsAggregator.NewsChanged += new NewsChangedEventHandler(instagramWidget.Update);
            newsAggregator.NewsChanged += new NewsChangedEventHandler(twitterWidget.Update);

            newsAggregator.NewNewsAvailable();
            Console.WriteLine();

            newsAggregator.NewsChanged -= new NewsChangedEventHandler(instagramWidget.Update);
            newsAggregator.NewNewsAvailable();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            var newsAggregator       = new NewsAggregator();
            var franceFootballWidget = new FranceFootballWidget();
            var deportivoWidget      = new DeportivoWidget();
            var barcaNewsWidget      = new BarcaNewsWidget();

            newsAggregator.NewsChanged += franceFootballWidget.Update;
            newsAggregator.NewsChanged += deportivoWidget.Update;
            newsAggregator.NewsChanged += barcaNewsWidget.Update;

            newsAggregator.NewNewsAvailable();
            Console.WriteLine();

            newsAggregator.NewsChanged -= franceFootballWidget.Update;
            newsAggregator.NewNewsAvailable();

            Console.ReadLine();
        }
Example #9
0
        static void Main(string[] args)
        {
            var newsAggregator = new NewsAggregator();
            var twitterWidget  = new TwitterWidget();
            var lentaWidget    = new LentaWidget();
            var tvWidget       = new TvWidget();

            newsAggregator.NewsChanged += twitterWidget.Update;
            newsAggregator.NewsChanged += lentaWidget.Update;
            newsAggregator.NewsChanged += tvWidget.Update;

            newsAggregator.NewNewsAvailable();
            Console.WriteLine();

            newsAggregator.NewsChanged -= twitterWidget.Update;
            newsAggregator.NewNewsAvailable();

            Console.ReadLine();
        }
Example #10
0
        static void Main()
        {
            var aggregator = new NewsAggregator();
            var twitter    = new TwitterObserver();
            var vk         = new VkObserver();

            aggregator.NewsChanged += twitter.Update;
            aggregator.NewsChanged += vk.Update;
            aggregator.NewNewsAvailable();

            Console.WriteLine("--------------");

            aggregator.NewNewsAvailable();
            aggregator.NewsChanged -= vk.Update;
            Console.WriteLine("--------------");
            aggregator.NewNewsAvailable();


            Console.ReadLine();
        }
Example #11
0
        static void Main(string[] args)
        {
            var newsAggregator = new NewsAggregator();

            var twitterWidget = new TwitterWidget();
            var lentaWidget   = new LentaWidget();
            var tvWidget      = new TvWidget();

            //handlers can be matched inside ctor of widget class
            //newsAggregator.NewsChanged += (s, a) => Console.WriteLine("{0} say: {1}, {2}, {3}", s, a.Lenta, a.Tv, a.Twitter);
            newsAggregator.NewsChanged += twitterWidget.Update;
            newsAggregator.NewsChanged += lentaWidget.Update;
            newsAggregator.NewsChanged += tvWidget.Update;

            newsAggregator.NewNewsAvailable();
            Console.WriteLine();
            newsAggregator.NewsChanged -= twitterWidget.Update;
            newsAggregator.NewNewsAvailable();

            Console.ReadLine();
        }
Example #12
0
        protected void Cari_Click(object sender, EventArgs e)
        {
            NewsAggregator na = new NewsAggregator();

            News.BuildLast(SearchBox.Text);
            News.computeFail(SearchBox.Text);
            na.ParseDetik(SearchBox.Text, RadioButtonList1.SelectedValue);
            na.ParseAntara(SearchBox.Text, RadioButtonList1.SelectedValue);
            na.ParseViva(SearchBox.Text, RadioButtonList1.SelectedValue);
            if (na.news.Count == 0)
            {
                result.InnerText = "No result found";
                return;
            }
            result.InnerText = "Displaying " + na.news.Count.ToString() + " results:";

            foreach (News n in na.news)
            {
                string pattern;
                pattern = SearchBox.Text;
                HtmlGenericControl li = new HtmlGenericControl("li");
                list.Controls.Add(li);
                HtmlGenericControl img = new HtmlGenericControl("img");
                img.Attributes.Add("src", n.GetImage());
                img.Attributes.Add("width", "100");
                img.Attributes.Add("hspace", "7");
                img.Attributes.Add("align", "left");
                HtmlGenericControl a = new HtmlGenericControl("a");
                a.Attributes.Add("href", n.GetLink());
                a.InnerText = n.GetTitle();
                HtmlGenericControl p2 = new HtmlGenericControl("p");
                p2.InnerText = n.GetDate().ToLongDateString() + ' ' + n.GetDate().ToLongTimeString();
                HtmlGenericControl p = new HtmlGenericControl("p");
                p.InnerText = n.GetContent();
                li.Controls.Add(img);
                li.Controls.Add(a);
                li.Controls.Add(p2);
                li.Controls.Add(p);
            }
        }
Example #13
0
        public void OutPatternInfo()
        {
            Console.WriteLine("IObserver - наблюдатель, IObservable - наблюдаемый объект\n" +
                              "Внутри библиотеки System есть данные интерфейсы.В нормальном проекте необходимо использовать их." +
                              "В каких случаях используется паттерн Observer:\n" +
                              "-Когда система состоит из множества классов, объекты которых должны находиться в согласованных состояниях\n" +
                              "-Когда общая схема взаимодействия объектов предполагает две стороны: одна рассылает сообщения и является главным,\n" +
                              "другая получает сообщения и реагирует на них. Отделение логики обеих сторон позволяет их рассматривать независимо\n" +
                              "и использовать отдельно друга от друга.\n" +
                              "-Когда существует один объект, рассылающий сообщения, и множество подписчиков, которые получают сообщения.\n" +
                              "При этом точное число подписчиков заранее неизвестно и процессе работы программы может изменяться.\n");

            var sender = new NewsAggregator();
            var admin  = new Admin(

                );
            var manager = new Manager(0, "Manager");
            var user    = new User(1, "Vasya", "KTR", InterestingState.Interesting);

            // имитация торгов
            var news = new News()
            {
                Title            = "Hello, this is Microsoft news",
                ShortDescription = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam,",
                LongDescription  = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod" +
                                   "tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo" +
                                   "consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse" +
                                   "cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non" +
                                   "proident,sunt in culpa qui officia deserunt mollit anim id est laborum."
            };

            /*sender.RegisterUser(user);
             * sender.RemoveUser(manager);*/

            /*sender.NotifyUsers(news);
            *  news.LongDescription = "da";
            *  // имитация торгов
            *  sender.NotifyUsers(news);*/
        }
Example #14
0
        private static void TestNewsImporter()
        {
            var providers = new List <NewsProvider>
            {
                // Fashion sites.
                new NewsProvider(@"riamoda.ru", 2, 24, @"http://riamoda.ru/rss.xml", NewsProviderType.Fashion),
                new NewsProvider(@"Modanews.ru", 2, 24, @"http://modanews.ru/rss/news/", NewsProviderType.Fashion),
                new NewsProvider(@"glianec.com.u", 2, 24, @"http://glianec.com.ua/?format=feed&type=rss", NewsProviderType.Fashion),
                new NewsProvider(@"fashiontime.ru - публикации", 2, 24, @"http://www.fashiontime.ru/rss/content.xml", NewsProviderType.Fashion),
                new NewsProvider(@"fashiontime.ru - новости", 2, 24, @"http://www.fashiontime.ru/rss/content_news.xml", NewsProviderType.Fashion),
                new NewsProvider(@"fashiontime.ru - статьи", 2, 24, @"http://www.fashiontime.ru/rss/content_article.xml", NewsProviderType.Fashion),
                new NewsProvider(@"intermoda.ru", 2, 24, @"http://www.intermoda.ru/rss/news", NewsProviderType.Fashion),
                new NewsProvider(@"profashion.ru", 2, 24, @"http://profashion.ru/news/rss/", NewsProviderType.Fashion),
                new NewsProvider(@"fashionunited.ru", 2, 24, @"https://fashionunited.ru/rss-novosti", NewsProviderType.Fashion),
                new NewsProvider(@"Style.rbc.ru", 2, 24, @"http://static.feed.rbc.ru/rbc/internal/rss.rbc.ru/style.rbc.ru/popural.rss", NewsProviderType.Fashion),
                new NewsProvider(@"be-in.ru", 2, 24, @"http://www.be-in.ru/rss/moda", NewsProviderType.Fashion),
                new NewsProvider(@"dress-code.com.ua", 2, 24, @"http://www.dress-code.com.ua/rss/common.rss", NewsProviderType.Fashion),
                new NewsProvider(@"trendymen.ru", 2, 24, @"http://trendymen.ru/_services/rss.php", NewsProviderType.Fashion),
                new NewsProvider(@"fashionpeople.ru", 2, 24, @"http://www.fashionpeople.ru/xml/rss.xml", NewsProviderType.Fashion),

                // Tech sites
                new NewsProvider(@"3dnews.ru", 2, 24, @"http://www.3dnews.ru/news/rss"),
                //new NewsProvider(@"popmech.ru", 2, 24, @"http://www.popmech.ru/rss"),
                new NewsProvider(@"mobbit", 2, 24, @"http://mobbit.info/rss.php"),
                new NewsProvider(@"ixbt.co", 2, 24, @"http://www.ixbt.com/export/articles.rdf"),
                new NewsProvider(@"mobile-review", 2, 24, @"http://www.mobile-review.com/newslistouter/rssnewsfull.xml"),
                new NewsProvider(@"mobile-review-reviews", 2, 24, @"http://www.mobile-review.com/rss-review.xml"),
                new NewsProvider(@"tech", 2, 24, @"https://www.google.com/news?output=rss&topic=t&ned=ru_ru&cf=all&num=20"),
                new NewsProvider(@"astronet.ru", 2, 24, @"http://www.astronet.ru/db/rss.xml"),
                new NewsProvider(@"nkj.ru", 2, 24, @"http://www.nkj.ru/rss/iblock_rss_31.xml"),
                new NewsProvider(@"elementy.r", 2, 24, @"http://elementy.ru/rss/news"),
                new NewsProvider(@"postnauka.ru", 2, 24, @"http://postnauka.ru/feed"),
                new NewsProvider(@"habrahabr-startups", 2, 24, @"http://habrahabr.ru/rss/tag/%D1%81%D1%82%D0%B0%D1%80%D1%82%D0%B0%D0%BF%D1%8B"), // стартапы
                new NewsProvider(@"habrahabr", 2, 24, @"http://www.habrahabr.ru/rss/main/"),                                                     // feed/http://habrahabr.ru/rss/best/
                new NewsProvider(@"geektimes.ru", 2, 24, @"http://geektimes.ru/rss/all/"),                                                       // http://geektimes.ru/rss/best/
                //new NewsProvider(@"", 2, 24, @""),

                new NewsProvider(@"The Verge", 1, 24, @"http://www.theverge.com/rss/full.xml"),
                new NewsProvider(@"Engadget", 1, 24, @"http://www.engadget.com/rss-full.xml"),
                new NewsProvider(@"Lifehacker", 1, 24, @"http://feeds.gawker.com/lifehacker/vip"), // Lifehacker
                //new NewsProvider(@"readwriteweb", 1, 24, @"http://www.readwriteweb.com/rss.xml"),
                new NewsProvider(@"Techcrunch", 1, 24, @"http://feeds.feedburner.com/Techcrunch"), //Techcrunch
                new NewsProvider(@"Wired", 1, 24, @"http://feeds.wired.com/wired/index"),
                new NewsProvider(@"Gizmodo", 1, 24, @"http://feeds.gawker.com/gizmodo/full"),      // Gizmodo
                new NewsProvider(@"Mashable", 1, 24, @"http://feeds.mashable.com/Mashable"),
                new NewsProvider(@"arstechnica", 1, 24, @"http://feeds.arstechnica.com/arstechnica/index/"),
                new NewsProvider(@"CNET", 1, 24, @"http://news.com.com/2547-1_3-0-5.xml"),
                new NewsProvider(@"Slashdot", 1, 24, @"http://rss.slashdot.org/Slashdot/slashdot"),
                new NewsProvider(@"Google Blog", 1, 24, @"http://googleblog.blogspot.com/atom.xml"),
                new NewsProvider(@"The Next Web", 1, 24, @"http://feeds2.feedburner.com/thenextweb"),
                new NewsProvider(@"boingboing", 1, 24, @"http://boingboing.net/feed"),
                new NewsProvider(@"thinkgeek", 1, 24, @"http://www.thinkgeek.com/thinkgeek.rss"),
                new NewsProvider(@"TED Talks", 1, 24, @"http://feeds.feedburner.com/tedtalks_video"),
                new NewsProvider(@"YCombinator", 1, 24, @"https://news.ycombinator.com/rss"),
                //new NewsProvider(@"", 1, 24, @""),
            };

            Console.WriteLine("Getting news...");

            var newsAggregator = new NewsAggregator();
            Dictionary <string, List <News> > news = newsAggregator.GetNews(providers);

            Console.WriteLine("Saving news...");

            using (var sw = new StreamWriter(@"C:\rss_notaccepted.txt"))
            {
                using (var swAccept = new StreamWriter(@"C:\rss_accepted.txt"))
                {
                    foreach (string newsprovider in news.Keys)
                    {
                        NewsProvider providerInfo = providers.FirstOrDefault(x => x.ProviderName == newsprovider);

                        foreach (var newsItem in news[newsprovider])
                        {
                            if (IsNewsAcceptable(newsItem, providerInfo))
                            {
                                swAccept.WriteLine(string.Format("{0} --- {1} --- {2}", providerInfo.ProviderName, newsItem.Header, DetectTheme(newsItem)));
                            }
                            else
                            {
                                // Debug.Assert(newsItem.Description.Length < 4000);
                                sw.WriteLine(string.Format("{0} --- {1}", providerInfo.ProviderName, newsItem.Header));
                            }
                        }
                    }
                }
            }
        }
Example #15
0
 public FeedController(IDataStore dataStore)
 {
     _dataStore      = dataStore;
     _newsAggregator = new NewsAggregator();
 }