Exemple #1
0
        private void responseResultMethod(IAsyncResult ar)
        {
            if (!ar.IsCompleted)
            {
                return;
            }
            Land            land     = null;
            Stream          stream   = null;
            HttpWebResponse response = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
                response = (HttpWebResponse)request.EndGetResponse(ar);

                stream = response.GetResponseStream();
                XmlReader reader = XmlReader.Create(stream);
                land = new Land();

                XmlSerializer xmls = new XmlSerializer(typeof(Land));
                land = xmls.Deserialize(reader) as Land;
                reader.Close();

                //close objects
                stream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                if (stream != null)
                {
                    stream.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
                land = null;
            }
            finally
            {
                if (onLandLoaded != null)
                {
                    onLandLoaded(land);
                }
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string landAsString = NavigationContext.QueryString.ContainsKey("land") ? NavigationContext.QueryString["land"] : "";
            if (landAsString != "")
            {
                Land land = new Land();
                land.FromString(landAsString);

                TextBlockId.Text = "Id=" + land.Id.ToString();
                TextBlockLandType.Text ="LandType=" + land.LandType.ToString();
                TextBlockLandThreat.Text = "LandThreat=" + land.LandThreat.ToString();
                TextBlockGeohexKey.Text = "GeohexKey="+ land.GeohexKey;
                TextBlockEarthwatcherGuid.Text = "EarthwatcherGuid=" +land.EarthwatcherGuid;
            }

        }
        private void responseResultMethod(IAsyncResult ar)
        {
            if (!ar.IsCompleted) return;
            Land land = null;
            Stream stream = null;
            HttpWebResponse response = null;
            try
            {
                HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
                response = (HttpWebResponse)request.EndGetResponse(ar);

                stream = response.GetResponseStream();
                XmlReader reader = XmlReader.Create(stream);
                land = new Land();
                
                XmlSerializer xmls = new XmlSerializer(typeof(Land));
                land = xmls.Deserialize(reader) as Land;
                reader.Close();

                //close objects
                stream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                if (stream != null) stream.Close();
                if (response != null) response.Close();
                land = null;
            }
            finally
            {
                if (onLandLoaded != null)
                {
                    onLandLoaded(land);
                }
            }
        }
        void landHelper_onLandLoaded(Land land)
        {
            this.Dispatcher.BeginInvoke(delegate()
                                            {
                                                if (land != null)
                                                {
                                                    _land = land;
                                                    _hexa = land.GeohexKey;
                                                    CreateHex();
                                                }
                                                else
                                                {
                                                    //todo : handle land == null
                                                    MessageBox.Show("The Login was invalid. Please try again.");

                                                    string url = string.Format("/UI/LoginPage.xaml");
                                                    Uri uri = new Uri(url, UriKind.Relative);
                                                    NavigationService.Navigate(uri);
                                                }
                                            });

        }