Example #1
0
        private IEnumerable <WikiPage> GetPagesByUrl(string url)
        {
            WebRequest request = WebRequest.Create(url);

            using (WebResponse response = request.GetResponse())
            {
                Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                using (var dataStream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(dataStream))
                    {
                        using (var jsonReader = new JsonTextReader(reader))
                            while (jsonReader.Read())
                            {
                                if (jsonReader.TokenType == JsonToken.StartObject)
                                {
                                    var jobj = JObject.Load(jsonReader);
                                    var page = WikiPage.FromJson(jobj.ToString());
                                    yield return(page);
                                }
                            }
                    }
                }
            }
        }
Example #2
0
 public IEnumerable <WikiPage> GetAllPages()
 {
     using (FileStream fsStream = new FileStream("./TestData.json", FileMode.Open))
     {
         using (StreamReader reader = new StreamReader(fsStream))
         {
             using (var jsonReader = new JsonTextReader(reader))
             {
                 while (jsonReader.Read())
                 {
                     if (jsonReader.TokenType == JsonToken.StartObject)
                     {
                         JObject obj = JObject.Load(jsonReader);
                         yield return(WikiPage.FromJson(obj.ToString()));
                     }
                 }
             }
         }
     }
 }