public void req3ResponseHandler(IAsyncResult e) { try { HttpWebRequest req = e.AsyncState as HttpWebRequest; HttpWebResponse res = req.EndGetResponse(e) as HttpWebResponse; if (res.StatusCode != HttpStatusCode.OK) { MessageBox.Show("Error - Could not connect to server"); return; } HtmlDocument doc = new HtmlDocument(); string html = new StreamReader(res.GetResponseStream()).ReadToEnd(); doc.LoadHtml(html); Deployment.Current.Dispatcher.BeginInvoke(() => { ListBox_Level3.ItemsSource = resultsCollection; }); FilterOptionHtmlNodes = doc.DocumentNode.SelectSingleNode(".//div[@class='fields']"); //FilterOptionHtmlNodes = doc.DocumentNode.SelectSingleNode(".//div[@id='header-search-options']"); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(".//ul[@id='listing-table']//li//a"); if (nodes == null) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("No reults were found , try again !"); StackPanel_RefiningOptions.Children.Clear(); }); return; } foreach (HtmlNode node in nodes) { var y = new ResultMenuItem(); //{ //Title = HttpUtility.HtmlDecode(node.InnerText), try { y.Anchorlink = node.Attributes["href"].Value; } catch (NullReferenceException) { } try { y.Title = HttpUtility.HtmlDecode(node.SelectSingleNode(".//span[@class='title']").InnerText); } catch (Exception) { } try { y.Price = HttpUtility.HtmlDecode(node.SelectSingleNode(".//span[@class='price']").InnerText); } catch (NullReferenceException) { } try { y.Date = HttpUtility.HtmlDecode(node.SelectSingleNode(".//span[@class='date']").InnerText); } catch (NullReferenceException) { } try { y.Imgurl = node.SelectSingleNode(".//img").Attributes["src"].Value; } catch (NullReferenceException) { } //}; //y.Title = HttpUtility.HtmlDecode(node.SelectSingleNode("//span[@class='title']").InnerText); Deployment.Current.Dispatcher.BeginInvoke(() => { resultsCollection.Add(y); }); } Deployment.Current.Dispatcher.BeginInvoke(() => { StackPanel_RefiningOptions.Children.Clear(); var inputelements = FilterOptionHtmlNodes.SelectNodes(".//input[@type='text']"); var selectelements = FilterOptionHtmlNodes.SelectNodes(".//div[@class='range-fields']"); List<EDAdvancedTextbox> Textboxes; List<StackPanel> Listpickers; if (inputelements != null) { Textboxes = new HTMLtoXAML().ConvertInputFields(inputelements); foreach (var item in Textboxes) { item.KeyUp += (sender, xe) => { if (xe.Key == Key.Enter) this.Focus(); }; StackPanel_RefiningOptions.Children.Add(item); } } if (selectelements != null) { Listpickers = new HTMLtoXAML().ConvertSelectwithLabel(selectelements); foreach (var item2 in Listpickers) { StackPanel_RefiningOptions.Children.Add(item2); } } Button refine_button = new Button(); refine_button.BorderThickness = new Thickness(2.0); refine_button.Content = "submit"; refine_button.Click +=new RoutedEventHandler((o,ex)=> { string filteroptions = "/?"; filteroptions += filteroptionsfromPanel(StackPanel_RefiningOptions); refinesearch(filteroptions); }); StackPanel_RefiningOptions.Children.Add(refine_button); }); Deployment.Current.Dispatcher.BeginInvoke(() => { PivotItem_Level3.Visibility = Visibility.Visible; if (!Pivot_Browse.Items.Contains(PivotItem_Level3)) { Pivot_Browse.Items.Add(PivotItem_Level3); ApplicationBar.IsVisible = true; } Pivot_Browse.SelectedItem = PivotItem_Level3; }); Deployment.Current.Dispatcher.BeginInvoke(() => { Grid_Refine.Visibility = Visibility.Collapsed; prog.IsVisible = false; }); currentpage++; isdownloadingdata = false; } catch (WebException) { isdownloadingdata = false; Deployment.Current.Dispatcher.BeginInvoke(() => { prog.IsVisible = false; }); } }
public void req_filteroptionsResponseHandler(IAsyncResult e) { try { HttpWebRequest req = e.AsyncState as HttpWebRequest; HttpWebResponse res = req.EndGetResponse(e) as HttpWebResponse; if (res.StatusCode != HttpStatusCode.OK) { MessageBox.Show("Error - Could not connect to server"); return; } string json = new StreamReader(res.GetResponseStream()).ReadToEnd(); JObject bar = JObject.Parse("{'root':" + json + "}"); Dictionary<string, string> tempdict = new Dictionary<string, string>(); foreach (var foo in bar["root"]["models"]) { var key = foo[1].Value<string>(); var val = foo[0].Value<string>(); if (val == "--") key = "Go back"; tempdict.Add(key,val); } Level++; if (newSearchCategories.Count > Level) newSearchCategories[Level] = tempdict; else newSearchCategories.Add(tempdict); Deployment.Current.Dispatcher.BeginInvoke(() => { ListBox_FilterOptions.ItemsSource = newSearchCategories[Level]; }); string html = bar["root"]["form_html"].Value<string>(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); var fields = doc.DocumentNode.SelectSingleNode(".//div[@class='fields']"); Deployment.Current.Dispatcher.BeginInvoke(() => { //StackPanel_MoreOptions.Children.Clear(); //var temp = new HTMLtoXAML().ConvertInputFields(fields.SelectNodes(".//input[@type='text']")); //if (temp != null) //{ // foreach (var item in temp) // { // if (!StackPanel_MoreOptions.Children.Contains(item)) // { // StackPanel_MoreOptions.Children.Add(item); // } // } //} //Deployment.Current.Dispatcher.BeginInvoke(() => //{ // StackPanel_MoreOptions.Children.Clear(); // var temp2 = new HTMLtoXAML().ConvertSelectFields(fields.SelectNodes(".//select")); // if (temp2 != null) // { // foreach (var item2 in temp2) // { // if(!StackPanel_MoreOptions.Children.Contains(item2)) // { // StackPanel_MoreOptions.Children.Add(item2); // } // } // } //}); StackPanel_MoreOptions.Children.Clear(); var inputelements = fields.SelectNodes(".//input[@type='text']"); var selectelements = fields.SelectNodes(".//div[@class='range-fields']"); List<EDAdvancedTextbox> Textboxes; List<StackPanel> Listpickers; List<UIElement> tempUIList = new List<UIElement>(); if (inputelements != null) { Textboxes = new HTMLtoXAML().ConvertInputFields(inputelements); foreach (var item in Textboxes) { //StackPanel_MoreOptions.Children.Add(item); item.KeyUp += (sender, xe) => { if (xe.Key == Key.Enter) this.Focus(); }; tempUIList.Add(item); } } if (selectelements != null) { Listpickers = new HTMLtoXAML().ConvertSelectwithLabel(selectelements); foreach (var item2 in Listpickers) { //StackPanel_MoreOptions.Children.Add(item2); tempUIList.Add(item2); } } if (newRefineUIElements.Count > Level) newRefineUIElements[Level] = tempUIList; else newRefineUIElements.Add(tempUIList); }); FillnewMoreOptionsControls(); Deployment.Current.Dispatcher.BeginInvoke(() => { prog.IsVisible = false; }); } catch (WebException) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("Please check your network connection and try again later", "Network Error", MessageBoxButton.OK); }); } }