示例#1
0
        public void test()
        {
            // DEBUGGING CODE

            var manager  = new DatabaseManager();
            var fetcher  = new ArticleFetcher(manager.GetSources());
            var articles = fetcher.GetArticles();

            foreach (NewsArticle a in articles)
            {
                Console.WriteLine(a.Title + "\n" + a.Description);
            }

            var testClusters = manager.GetClusters();

            Console.WriteLine(testClusters.Length + " CLUSTERS");

            int k = 0;

            foreach (Cluster c in testClusters)
            {
                foreach (NewsArticle article in c.Articles)
                {
                    k++;
                    Console.WriteLine("START OF ARTICLE");
                    Console.WriteLine(article.Title);
                    Console.WriteLine(article.Description);
                    Console.WriteLine(article.Url);
                    Console.WriteLine(article.UrlToImage);
                    Console.WriteLine(article.Source.ID);
                    Console.WriteLine(article.Source.Name);
                    Console.WriteLine("END OF ARTICLE");
                }
                Console.WriteLine("END OF CLUSTER");
                Console.WriteLine();
            }
            Console.WriteLine(k + " ARTICLES");

            var a1 = new NewsArticle();

            a1.Title = "he was for unique1 it and to of";
            var a2 = new NewsArticle();

            a2.Title = "the it and secondunique of to";
            var a3 = new NewsArticle();

            a3.Title = "with are on thethirdone in a to of";
            var d = new DocumentClusterer(new List <NewsArticle>(new NewsArticle[] { a1, a2, a3 }));
        }
示例#2
0
        public TabController()
        {
            var manager = new DatabaseManager();

            Cluster[] clusters;

            double timePassed = (DateTime.Now - manager.LastUpdated()).TotalHours;

            Console.WriteLine("Hours since last update: " + timePassed);

            if (timePassed >= 8 || manager.FirstTime)
            {
                Console.WriteLine("Articles Updated");
                var fetcher  = new ArticleFetcher(manager.GetSources());
                var articles = fetcher.GetArticles();

                var d = new DocumentClusterer(articles);
                clusters = d.cluster(12);
                manager.AddNewClusters(clusters);
            }
            else
            {
                clusters = manager.GetClusters();
            }

            DateTime needsUpdate = manager.LastUpdated().AddHours(8);

            tab1       = new ArticleViewController(clusters[0], needsUpdate);
            tab1.Title = "First";

            tab2       = new ArticleViewController(clusters[1], needsUpdate);
            tab2.Title = "Second";

            tab3       = new ArticleViewController(clusters[2], needsUpdate);
            tab3.Title = "Third";

            var tabs = new UIViewController[] {
                tab1, tab2, tab3
            };

            ViewControllers = tabs;
        }
示例#3
0
        /**
         * Updates the list of sources in the database if 14 days have passed
         * since the last update and returns the list of sources
         */
        public List <NewsSource> GetSources()
        {
            if ((DateTime.Now - SourcesLastUpdated()).TotalDays >= 14 || FirstTime)
            {
                sourcesConn.Query <NewsSource>("DELETE FROM Sources");

                var sources = ArticleFetcher.GetListOfSources();
                foreach (var source in sources)
                {
                    sourcesConn.Insert(source);
                }
                return(sources);
            }
            else
            {
                var temp    = sourcesConn.Table <NewsSource>();
                var sources = new List <NewsSource>();
                foreach (var source in temp)
                {
                    sources.Add(source);
                }
                return(sources);
            }
        }