Example #1
0
        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;

                });

            }
        }
Example #2
0
        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_Results.ItemsSource = resultsCollection;
                });
                var testnode = doc.DocumentNode.SelectSingleNode(".//div[@id='no-listings']");
                if (testnode != null)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("No results found");
                        EDAdvancedTextbox_SearhQuery.Text = "";
                        prog.IsVisible = false;
                    });
                    return;
                }
                HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(".//ul[@id='listing-table']//li//a");
                foreach (HtmlNode node in nodes)
                {
                    var y = new ResultMenuItem();
                    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) { }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if(!resultsCollection.Contains(y))
                            resultsCollection.Add(y);
                    });
                }
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    prog.IsVisible = false;
                });
                currentpage++;
                isdownloadingdata = false;

            }catch(Exception)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Please check your network connection and try again later", "Network Error",MessageBoxButton.OK);
                    });
            }
        }