public void get_search_results(string search, int count = 0, int page = 0, string post_type = null) { WordpressEventArgs args = new WordpressEventArgs(WordpressDataType.PostList, HttpStatusCode.OK, true); string str = url + "?json=get_search_results&search=" + search; if (count != 0) { str += "&count=" + count.ToString(); } if (page != 0) { str += "&page=" + page.ToString(); } if (!string.IsNullOrEmpty(post_type)) { str += "&post_type=" + post_type; } Helper.HttpWebRequestDownload((asynchronousResult) => { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); PostList pl = new PostList(); if (response.StatusCode == HttpStatusCode.OK) { try { using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { string resultString = streamReader1.ReadToEnd(); pl = Helper.Deserialize<PostList>(resultString); } } catch { args.Success = false; } } else { args.Success = false; args.ResponseCode = response.StatusCode; pl.Count = 1; pl.Posts = new List<Post>(); pl.Posts.Add(new Post() { Title = "Failed to connect", Content = "Check data connection and try again, HttpStatusCode=" + response.StatusCode}); } Deployment.Current.Dispatcher.BeginInvoke(new Action(() => { try { get_search_results_complete.Invoke(pl, args); } catch { } })); }, str); }
/// <summary> /// Gets a page with a given slug /// </summary> /// <param name="slug">Page slug to find</param> /// <param name="children">Search page children as well</param> public void get_page(string slug, bool children = false) { WordpressEventArgs args = new WordpressEventArgs(WordpressDataType.PostList,HttpStatusCode.OK,true); string str = url + "?json=get_page&slug=" + slug; if (children) { str += "&children=true"; } Helper.HttpWebRequestDownload((asynchronousResult) => { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); PostList pl = new PostList(); if (response.StatusCode == HttpStatusCode.OK) { try { using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { string resultString = streamReader1.ReadToEnd(); pl = Helper.Deserialize<PostList>(resultString); } } catch { args.Success = false; } } else { args.Success = false; args.ResponseCode = response.StatusCode; pl.Count = 1; List<Category> cats = new List<Category>(); cats.Add(new Category() { Slug = slug }); pl.Posts = new List<Post>(); pl.Posts.Add(new Post() { Title = "Failed to connect", Content = "Check data connection and try again, HttpStatusCode=" + response.StatusCode, Categories = cats }); } Deployment.Current.Dispatcher.BeginInvoke(new Action(() => { try { get_page_complete.Invoke(pl, new WordpressEventArgs()); } catch { } })); }, str); }