コード例 #1
0
ファイル: Program.cs プロジェクト: sondet/JesperSamuel
 private static void testNewspaper()
 {
     string s = "http://www.aftonbladet.se";
     Newspaper n = new Newspaper(s);
     Console.WriteLine("url:");
     //string input = Console.ReadLine();
     //Newspaper n1 = new Newspaper(input);
     NewspaperConnection connection = new NewspaperConnection();
     //connection.SearchNewspaperForKeywords(n1, new Competition(false,new string[0],new string[0]));
     List<Newspaper> nn = Newspaper.CreateNewspapersFromFile("Newspapersss.txt");
     if (nn == null) return;
     foreach (Newspaper news in nn)
     {
         Console.WriteLine(news);
     }
 }
コード例 #2
0
        public static List<Newspaper> CreateNewspapersFromFile(string fileName)
        {
            List<Newspaper> papers = new List<Newspaper>();
            StreamReader reader = null;
            try
            {
                reader = new StreamReader(Directory.GetCurrentDirectory() + "\\" + fileName);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }

            string line = "";
            while (line != null)
            {
                try
                {
                    line = reader.ReadLine();
                    Newspaper n = new Newspaper(line);
                    papers.Add(n);
                }
                catch (Exception)
                {
                    continue;
                }
            }
            reader.Close();
            papers.TrimExcess();
            return (papers.Count > 0) ? papers: null;
        }
コード例 #3
0
 public void SearchNewspaperForKeywords(Newspaper paper, Competition competition)
 {
     string paperStr = mClient.DownloadString(paper.Uri.ToString());
     Console.WriteLine(paperStr);
 }