Пример #1
0
        public static async Task GetMigratedData()
        {
            //Get the new Data and store locally.
            ProfileList profiles = null;

            //Globals.IsAutoUpgradeFailed = false;
            try
            {
                profiles = await MembershipServiceWrapper.GetProfilesForLiveId(AutoUpgradeLiveAuthID);
            }
            catch (Exception ex)
            {
                Globals.IsAutoUpgradeFailed = true;
                //App.CurrentUser.UnregisterLocally();
                return;
            }
            if (profiles != null && profiles.List.Count > 0)
            {
                //App.CurrentUser.UnregisterLocally();
                App.MyProfiles.DeleteOfflineProfile();

                //Load all new profiles to Local Storage + Assign first profile as CurrentProfile
                Globals.User.Name       = profiles.List[0].Name;
                Globals.User.LiveEmail  = profiles.List[0].Email;
                Globals.User.LiveAuthId = AutoUpgradeLiveAuthID;
                App.CurrentUser.UpdateUser(Globals.User);

                UserViewModel.RestoreAllProfiles(profiles.List);
                Globals.Load2CurrentProfile(profiles.List[0].ProfileID.ToString(CultureInfo.InvariantCulture));

                if (Globals.CurrentProfile.CountryCode != null)
                {
                    Globals.SetEmergencyNumbers(Globals.AllCountryCodes.First(c => c.IsdCode == Globals.CurrentProfile.CountryCode));
                }

                Globals.IsAutoUpgradeFailed = false;
            }
            else
            {
                Globals.IsAutoUpgradeFailed = true;
                //App.CurrentUser.UnregisterLocally();
            }
        }
Пример #2
0
        /// <summary>
        ///     Calls LiveAuthClient.Initialize to get the user login status.
        ///     Retrieves user profile information if user is already signed in.
        /// </summary>
        private async void InitializeSignInAsync()
        {
            try
            {
                this.authClient          = new LiveAuthClient(Config.LiveAuthClientId);
                m_ProgressBar.Visibility = System.Windows.Visibility.Visible;
                LiveLoginResult loginResult = await this.authClient.LoginAsync(scopes);

                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    this.liveClient = new LiveConnectClient(loginResult.Session);
                    AccessToken     = loginResult.Session.AccessToken;
                    RefreshToken    = loginResult.Session.RefreshToken;
                    LiveOperationResult operationResult = await this.liveClient.GetAsync("me");

                    dynamic properties = operationResult.Result;
                    LiveIdTextBox.Text            = properties.emails.account;
                    LiveAuthTokenPanel.Visibility = System.Windows.Visibility.Visible;
                    WaitTextBlock.Visibility      = System.Windows.Visibility.Collapsed;

                    if (NameTextBox.Text.Trim() == string.Empty && properties.name != null)
                    {
                        NameTextBox.Text = properties.name;
                    }

                    //LiveLoginButton.Visibility = Visibility.Collapsed;
                    //Save Email to Local Storage
                    Globals.User.Name       = NameTextBox.Text;
                    Globals.User.LiveEmail  = LiveIdTextBox.Text;
                    Globals.User.LiveAuthId = loginResult.Session.AuthenticationToken;
                    App.CurrentUser.UpdateUser(Globals.User);


                    //If user already exists, get all his info and store locally. Delete any local profile //TODO
                    ProfileList profiles = null;
                    try
                    {
                        profiles = await MembershipServiceWrapper.GetProfilesForLiveId();
                    }
                    catch (Exception ex)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.UnableToConnectService, "basicWrap", "Information!"));
                        return;
                    }
                    if (profiles != null && profiles.List.Count > 0)
                    {
                        //Load all profiles to Local Storage
                        // + Assign first profile as CurrentProfile

                        //If atleast one buddy, retain the profile. Else delete!
                        //Globals.CurrentProfile.MobileNumber = "0000000000";

                        profiles.List[0].IsSOSOn      = Globals.CurrentProfile.IsSOSOn;
                        profiles.List[0].IsTrackingOn = Globals.CurrentProfile.IsTrackingOn;
                        //profiles.List[0].SessionID = Globals.CurrentProfile.SessionToken;

                        App.MyProfiles.DeleteOfflineProfile();

                        UserViewModel.RestoreAllProfiles(profiles.List);

                        Globals.Load2CurrentProfile(profiles.List[0].ProfileID.ToString());

                        Globals.IsAutoUpgradeFailed = false;
                        //if (NavigationService.BackStack != null && NavigationService.BackStack.Count() > 0)
                        //    NavigationService.RemoveBackEntry();

                        if (Globals.CurrentProfile.CountryCode != null)
                        {
                            Globals.SetEmergencyNumbers(Globals.AllCountryCodes.First(c => c.IsdCode == Globals.CurrentProfile.CountryCode));
                        }

                        //Allow change of Current Profile in Settings
                        NavigationService.Navigate(new Uri("/Pages/Settings.xaml?FromPage=Register", UriKind.Relative));
                        Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.ProfileLoadedSuccessfullyText, "basicWrap", "Info!"));
                    }
                    else
                    {
                        WaitTextBlock.Visibility            = System.Windows.Visibility.Collapsed;
                        ProfilePanel.Visibility             = Visibility.Visible;
                        CountryCodeListPicker.SelectedIndex = CountryCodeListPicker.Items.IndexOf(CountryCodeListPicker.Items.First(c => ((c as CountryCodes).IsdCode == Constants.CountryCode)));
                    }
                }
                else if (loginResult.Status == LiveConnectSessionStatus.NotConnected || loginResult.Status == LiveConnectSessionStatus.Unknown)
                {
                    NavigationService.Navigate(new Uri("/Pages/Settings.xaml?FromPage=Register", UriKind.Relative));
                }
                else
                {
                    WaitTextBlock.Text = CustomMessage.UnableToGetLoginInfoText;
                }
            }
            catch (LiveAuthException authExp)
            {
                if (authExp.ErrorCode == "access_denied")
                {
                    IsComingFromBackground = true;
                }
                WaitTextBlock.Text = CustomMessage.UnableToGetLoginInfoText;
                //TODO: Authentication Token Expired!
            }
            catch (LiveConnectException ex)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.LiveConnectExceptionText, "basicWrap", "Connection error."));
                WaitTextBlock.Text = CustomMessage.UnableToGetLoginInfoText;
            }
            finally
            {
                m_ProgressBar.Visibility = System.Windows.Visibility.Collapsed;
            }
        }