/// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // Populate the username and phone number fields if they are available in the isolated storage settings.
            // If there are none, then leave blank
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            if (localSettings.Values.ContainsKey(setting_username))
            {
                tb_username.Text = localSettings.Values[setting_username] as string;
            }
            else
            {
                tb_username.Text = "";
            }

            if (localSettings.Values.ContainsKey(setting_phone_no))
            {
                tb_Phone_No.Text = localSettings.Values[setting_phone_no] as string;
            }
            else
            {
                tb_Phone_No.Text = "";
            }


        }
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session.  The state will be null the first time a page is visited.</param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     tb_appname.Text = "Party Tracker";
     tb_version.Text = versionString(Windows.ApplicationModel.Package.Current.Id.Version);
     
     
 }
Example #3
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // reset the logic.

            PeerFinder.Stop();
            grid_Loading.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            cancel_button.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            I_am_a_the_host = false;
            finished_connecting_to_peers = false;
            is_initial_connect = true;
            phonebook = new Dictionary<string, string>();
            session_pin = null;
            finalizing_connection = false;

            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            if (localSettings.Values.Count == 0)
            {
                // there are no settings, prompt user
                display_first_run_dialog();
            }
            else
            {
                // if the settings are invalid, ie. no username or no phone number make another prompt
                if (localSettings.Values[setting_username] == "" || localSettings.Values[setting_phone_no] == "")
                {
                    display_first_run_dialog();
                }

                 

            }

            if (localSettings.Values.ContainsKey(setting_username))
            {
                // display name will be a 6 char header containing the pin, derived from the last 4 digits of the telephone number [0000] followed by the username
                string display_name = localSettings.Values[setting_phone_no] as string;

                // check if somehow the phone number is less than 4 chars long. This will be functionally invalid, in the settings page, there should be a check that makes you enter a phone number that's at least valid.
                if (display_name.Length >= 4)
                {
                    display_name = display_name.Substring(display_name.Length - 4, 4);
                }
                else
                {
                    // padd it until it is of length 4
                    for (int i = 0; i < (4 - display_name.Length); i++)
                    {
                        display_name += "0";
                    }
                }

                display_name = "[" + display_name + "]" + (localSettings.Values[setting_username] as string);

                PeerFinder.DisplayName = display_name;
                //PeerFinder.DisplayName = localSettings.Values[setting_username] as string;
            }
            else
            {
                // this thing freaks out//
                //display_missing_settings_dialog();
            }

            PeerFinder.ConnectionRequested += PeerFinder_ConnectionRequested;

            PeerFinder.Start();
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            //HardwareButtons.BackPressed += HardwareButtons_BackPressed;

            myGeolocator = new Geolocator();
            myGeolocator.DesiredAccuracy = PositionAccuracy.High;
            myGeolocator.ReportInterval = 30;
            myGeolocator.MovementThreshold = 5;
            myGeolocator.PositionChanged += new TypedEventHandler<Geolocator, PositionChangedEventArgs>(OnPositionChanged);

            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            /* I'm going on a limb here and just assuming that the XAML assets are all loaded by the time this function is called */
            //phonebook = e.NavigationParameter as Dictionary<string, string>;
            KeyValuePair<string, Dictionary<string, string>> kvp = (KeyValuePair<string, Dictionary<string, string>>)e.NavigationParameter;

            phonebook = kvp.Value;
            sessionPin = kvp.Key.Substring(1, 4);

            peerLocations = new Dictionary<string, KeyValuePair<double, double>>();

            PeerFinder.DisplayName = kvp.Key + (localSettings.Values[setting_username] as string);
            PeerFinder.Start();
            peerFinderStarted = true;

            myMapIcons = new Dictionary<string, MapIcon>();
            foreach (string key in phonebook.Keys)
            {
                myMapIcons[key] = new MapIcon() { Title = key, Visible = true, NormalizedAnchorPoint = new Point(0.5, 0.5) };
            }



            myMapIcon = new MapIcon() { Title = "Me", Visible = true, NormalizedAnchorPoint = new Point(0.5, 0.5) };

            myMapIcons[localSettings.Values[setting_username] as string] = myMapIcon;


            PeerFinder_StartPeerWatcher(null, null);
            //peerWatcher.Start();

        }