示例#1
0
        private void locHandleResponse(IAsyncResult result)
        {
            queryUpdateState qState   = (queryUpdateState)result.AsyncState;
            HttpWebRequest   qRequest = (HttpWebRequest)qState.AsyncRequest;

            qState.AsyncResponse = (HttpWebResponse)qRequest.EndGetResponse(result);

            Stream streamResult;

            try
            {
                streamResult = qState.AsyncResponse.GetResponseStream();

                // load the XML
                XDocument xmlquery = XDocument.Load(streamResult);
                slat = xmlquery.Descendants("result").Descendants("geometry").Descendants("location").Descendants("lat").First().Value;
                slng = xmlquery.Descendants("result").Descendants("geometry").Descendants("location").Descendants("lng").First().Value;

                beginSearch(slat, slng, search);
            }
            catch (FormatException)
            {
                return;
            }
        }
示例#2
0
        private void HandleResponse(IAsyncResult result)
        {
            queryUpdateState qState   = (queryUpdateState)result.AsyncState;
            HttpWebRequest   qRequest = (HttpWebRequest)qState.AsyncRequest;

            qState.AsyncResponse = (HttpWebResponse)qRequest.EndGetResponse(result);

            Stream streamResult;

            try
            {
                streamResult = qState.AsyncResponse.GetResponseStream();

                // load the XML
                XDocument xmlquery = XDocument.Load(streamResult);
                string    x        = xmlquery.ToString();
                if (x.IndexOf("<Description xml:space=\"preserve\">") != -1)
                {
                    x = x.Substring(x.IndexOf("<Description xml:space=\"preserve\">") + 34);
                    x = x.Substring(0, x.IndexOf("</Description>"));

                    this.Dispatcher.BeginInvoke(new Action(() => textBlock1.Text = x));
                }
                else
                {
                    this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("Oy")));
                }
                this.Dispatcher.BeginInvoke(new Action(() => this.ProgressBar.Visibility = Visibility.Collapsed));
            }
            catch (FormatException)
            {
                return;
            }
        }
示例#3
0
        private void getCityHandleResponse(IAsyncResult result)
        {
            queryUpdateState qState   = (queryUpdateState)result.AsyncState;
            HttpWebRequest   qRequest = (HttpWebRequest)qState.AsyncRequest;

            qState.AsyncResponse = (HttpWebResponse)qRequest.EndGetResponse(result);

            Stream streamResult;

            try
            {
                streamResult = qState.AsyncResponse.GetResponseStream();

                // load the XML
                XDocument  xmlquery  = XDocument.Load(streamResult);
                XElement[] addresses = xmlquery.Descendants("result").Descendants("address_component").ToArray();

                foreach (var a in addresses)
                {
                    if (a.Descendants("type").First().Value == "administrative_area_level_2")
                    {
                        currentcity = a.Descendants("long_name").First().Value;
                        break;
                    }
                }
                beginSearch(clat, clng, currentcity);
            }
            catch (FormatException)
            {
                return;
            }
        }
示例#4
0
        private void wikipost(Uri u)
        {
            HttpWebRequest queryRequest = (HttpWebRequest)WebRequest.Create(u);

            queryRequest.Method = "POST";
            queryUpdateState qState = new queryUpdateState();

            qState.AsyncRequest = queryRequest;
            queryRequest.BeginGetResponse(new AsyncCallback(wikiHandleResponse), qState);
        }
示例#5
0
        private void wikiHandleResponse(IAsyncResult result)
        {
            queryUpdateState qState   = (queryUpdateState)result.AsyncState;
            HttpWebRequest   qRequest = (HttpWebRequest)qState.AsyncRequest;

            qState.AsyncResponse = (HttpWebResponse)qRequest.EndGetResponse(result);

            Stream streamResult;

            try
            {
                streamResult = qState.AsyncResponse.GetResponseStream();

                // load the XML
                XDocument xmlquery = XDocument.Load(streamResult);

                //Wikipedia Data Need to be parsed
                string a = xmlquery.Descendants("query").Descendants("pages").Descendants("page").Descendants("revisions").Descendants("rev").First().Value;
                string h = new CreoleParser().ToHTML(a);

                //this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.UpdateLayout()));
                this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.NavigateToString(h)));
                this.Dispatcher.BeginInvoke(new Action(() => webBrowser1.UpdateLayout()));

                //string x = xmlquery.ToString();

                /* if (x.IndexOf("<Description xml:space=\"preserve\">") != -1)
                 * {
                 *   x = x.Substring(x.IndexOf("<Description xml:space=\"preserve\">") + 34);
                 *   x = x.Substring(0, x.IndexOf("</Description>"));
                 *
                 *   this.Dispatcher.BeginInvoke(new Action(() => textBlock1.Text = x));
                 * }
                 * else
                 * {
                 *   this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("Oy")));
                 * }
                 * this.Dispatcher.BeginInvoke(new Action(() => this.ProgressBar.Visibility = Visibility.Collapsed));*/
            }
            catch (FormatException)
            {
                return;
            }
        }
示例#6
0
        private void HandleResponse1(IAsyncResult result)
        {
            queryUpdateState qState   = (queryUpdateState)result.AsyncState;
            HttpWebRequest   qRequest = (HttpWebRequest)qState.AsyncRequest;

            qState.AsyncResponse = (HttpWebResponse)qRequest.EndGetResponse(result);

            Stream streamResult;

            try
            {
                streamResult = qState.AsyncResponse.GetResponseStream();

                // load the XML
                XDocument  xmlquery = XDocument.Load(streamResult);
                XElement[] a        = xmlquery.Descendants("result").Descendants("name").ToArray();
                XElement[] geo_lat  = xmlquery.Descendants("result").Descendants("geometry").Descendants("location").Descendants("lat").ToArray();
                XElement[] geo_lng  = xmlquery.Descendants("result").Descendants("geometry").Descendants("location").Descendants("lng").ToArray();

                string   s        = xmlquery.Descendants("result").Descendants("type").ToArray().First().Value;
                double[] distance = new double[100];
                string[] names    = new string[100];
                string   i        = "";
                for (int il = 0; il < a.Length; il++)
                {
                    double a1       = (Math.Sin(Radians(double.Parse(clat) - double.Parse(geo_lat[il].Value)) / 2) * Math.Sin(Radians(double.Parse(clat) - double.Parse(geo_lat[il].Value)) / 2)) + Math.Cos(Radians(double.Parse(geo_lat[il].Value))) * Math.Cos(Radians(double.Parse(clat))) * (Math.Sin(Radians(double.Parse(clng) - double.Parse(geo_lng[il].Value)) / 2) * Math.Sin(Radians(double.Parse(clng) - double.Parse(geo_lng[il].Value)) / 2));
                    double angle    = 2 * Math.Atan2(Math.Sqrt(a1), Math.Sqrt(1 - a1));
                    double Distance = angle * 6378.16;
                    distance[il] = Math.Round(Distance, 2);
                    names[il]    = a[il].Value;
                    i           += Math.Round(Distance, 2) + " KM away,";
                    i           += a[il].Value + System.Environment.NewLine;

                    if (s == "airport")
                    {
                        if (distance[il] != 0.0 && names[il] != null)
                        {
                            airPlaces.Add(new Class2(names[il], distance[il] + "Kms"));
                        }
                    }
                    else if (s == "train_station")
                    {
                        if (distance[il] != 0.0 && names[il] != null)
                        {
                            railPlaces.Add(new Class2(names[il], distance[il] + "Kms"));
                        }
                    }
                    else if (s == "bus_station")
                    {
                        if (distance[il] != 0.0 && names[il] != null)
                        {
                            busPlaces.Add(new Class2(names[il], distance[il] + "Kms"));
                        }
                    }
                    else if (s == "hospital")
                    {
                        if (distance[il] != 0.0 && names[il] != null)
                        {
                            hospitalPlaces.Add(new Class2(names[il], distance[il] + "Kms"));
                        }
                    }
                    else if (s == "gas_station")
                    {
                        if (distance[il] != 0.0 && names[il] != null)
                        {
                            gasPlaces.Add(new Class2(names[il], distance[il] + "Kms"));
                        }
                    }
                }

                if (s == "airport")
                {
                    this.Dispatcher.BeginInvoke(new Action(() => AirportList.ItemsSource = airPlaces));
                }
                else if (s == "train_station")
                {
                    this.Dispatcher.BeginInvoke(new Action(() => RailwaysList.ItemsSource = railPlaces));
                }
                else if (s == "bus_station")
                {
                    this.Dispatcher.BeginInvoke(new Action(() => BusList.ItemsSource = busPlaces));
                }
                else if (s == "hospital")
                {
                    this.Dispatcher.BeginInvoke(new Action(() => HospitalList.ItemsSource = hospitalPlaces));
                }
                else if (s == "gas_station")
                {
                    this.Dispatcher.BeginInvoke(new Action(() => GasList.ItemsSource = gasPlaces));
                }

                if (watcher != null)
                {
                    watcher.Stop();
                }
            }
            catch (FormatException)
            {
                return;
            }
        }
 private void wikipost(Uri u)
 {
     HttpWebRequest queryRequest = (HttpWebRequest)WebRequest.Create(u);
     queryRequest.Method = "POST";
     queryUpdateState qState = new queryUpdateState();
     qState.AsyncRequest = queryRequest;
     queryRequest.BeginGetResponse(new AsyncCallback(wikiHandleResponse), qState);
 }