Exemplo n.º 1
0
        public static async Task <HealthUpdate> GetSystemHealthAsync()
        {
            HealthUpdate objHealth = null;

            if (IsDataNetworkAvailable && IsRegisteredUser)
            {
                objHealth = await MembershipServiceWrapper.CheckPendingUpdates(CurrentProfile.ProfileId, CurrentProfile.LastSynced.HasValue?CurrentProfile.LastSynced.Value : DateTime.MinValue);
            }
            return(objHealth);
        }
Exemplo n.º 2
0
        private void ValidateButton_Click(object sender, EventArgs e)
        {
            if (!IsMobileNumberEdited && Config.IsEnterpriseBuild && (string.IsNullOrWhiteSpace(EnterpriseEmailTextBox.Text) || !EnterpriseEmailTextBox.Text.EndsWith(Config.EnterpriseEmailDomain)))
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.InvalidEnterpriseEmailWhileRegistering, "basicWrap", "Oops!"));
                EnterpriseEmailTextBox.Focus();
                return;
            }

            selectedCountryCode = (CountryCodes)CountryCodeListPicker.SelectedItem;
            if (selectedCountryCode == null)
            {
                selectedCountryCode = (CountryCodes)CountryCodeListPicker.Items[0];
                CountryCodeListPicker.SelectedIndex = CountryCodeListPicker.Items.IndexOf(CountryCodeListPicker.Items.First(c => ((c as CountryCodes).IsdCode == Constants.CountryCode)));
            }
            if (MobileNumberTextBox.Text == String.Empty || MobileNumberTextBox.Text.Length > int.Parse(selectedCountryCode.MaxPhoneDigits))
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.InvalidMobileNumberWhileRegistering, "basicWrap", "Oops!"));
                MobileNumberTextBox.Focus();
                return;
            }

            if (IsMobileNumberEdited)
            {
                if (selectedCountryCode.IsdCode + MobileNumberTextBox.Text.Trim() == Globals.CurrentProfile.MobileNumber)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.MobileNumberEditingText, "basicWrap", "Oops!"));
                    MobileNumberTextBox.Focus();
                    return;
                }
            }
            //BL: Disable the button for 5 minutes
            //Call Server to send SMS/ email
            try
            {
                m_ProgressBar.Visibility = Visibility.Visible;

                MembershipServiceWrapper.ValidateMobileNumberAsync(NameTextBox.Text, LiveIdTextBox.Text, selectedCountryCode.IsdCode, MobileNumberTextBox.Text, EnterpriseEmailTextBox.Text);
                m_ProgressBar.Visibility = Visibility.Collapsed;
                ValidateNumber.IsEnabled = false;
                Task ignoredAwaitableResult = this.delayedWork();

                Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.MobileNumberValidatingSMSToast, "basicWrap", "Information!"));
            }
            catch (Exception)
            {
                m_ProgressBar.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 3
0
        public async void CheckPendingUpdatesFromServer()
        {
            try
            {
                if (Globals.IsRegisteredUser && Globals.IsDataNetworkAvailable)
                {
                    this.PendingUpdates = null;
                    this.PendingUpdates = await MembershipServiceWrapper.CheckPendingUpdates(Globals.User.CurrentProfileId, this.LastSyncDateTime);

                    if (this.PendingUpdates != null)
                    {
                        if (!this.PendingUpdates.IsProfileActive)
                        {
                            SaveCurrentProfileSetting(ProfileSetting.MobileNumber, "+000000000000");
                            Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.ProfileDeactivatedText, "basicWrap", "Oops!"));
                            this.LastSyncDateTime = DateTime.Now;
                        }
                        if (this.PendingUpdates.IsGroupModified)
                        {
                            //TODO
                        }
                        if (!string.IsNullOrEmpty(this.PendingUpdates.ServerVersion))
                        {
                            var     nameHelper     = new AssemblyName(Assembly.GetExecutingAssembly().FullName);
                            Version serverVersion  = new Version(PendingUpdates.ServerVersion);
                            var     currentVersion = nameHelper.Version;
                            if (serverVersion > currentVersion)
                            {
                                if (MessageBox.Show(CustomMessage.AppUpdateNotifyText, "Confirm", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                                {
                                    MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();


                                    marketplaceDetailTask.ContentType = MarketplaceContentType.Applications;

                                    marketplaceDetailTask.Show();
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
        public async Task <string> UpdateUserLocal2Server(bool IsMobileNumberEdit = false, string NewMobileNumber = "", string NewSecurityToken = "")
        {
            IsSuccess         = true;
            Message           = string.Empty;
            this.IsInProgress = true;

            string result = "SUCCESS";

            try
            {
                MembershipServiceRef.Profile profObjectToBeSynced = App.MyProfiles.ConvertProfile(App.MyProfiles.CurrentProfile);

                profObjectToBeSynced.Name        = Globals.User.Name;
                profObjectToBeSynced.UserID      = Convert.ToInt64(Globals.User.UserId);
                profObjectToBeSynced.Email       = Globals.User.LiveEmail;
                profObjectToBeSynced.FBAuthID    = Globals.User.FBAuthId;
                profObjectToBeSynced.LiveDetails = new MembershipServiceRef.LiveCred();

                profObjectToBeSynced.MyBuddies = App.MyBuddies.GetAllCurrentProfileBuddies();
                profObjectToBeSynced.AscGroups = App.MyGroups.GetAllCurrentProfileGroups();

                MembershipServiceRef.Profile serverProfile = null;
                if (IsMobileNumberEdit && NewMobileNumber != string.Empty && NewSecurityToken != String.Empty)
                {
                    profObjectToBeSynced.MobileNumber  = NewMobileNumber;
                    profObjectToBeSynced.SecurityToken = NewSecurityToken;
                    profObjectToBeSynced.RegionCode    = Constants.CountryCode;
                    serverProfile = await MembershipServiceWrapper.UpdateProfilePhone(profObjectToBeSynced);
                }
                else
                {
                    serverProfile = await MembershipServiceWrapper.UpdateProfile(profObjectToBeSynced);
                }
                if (!ResultInterpreter.IsError(serverProfile.DataInfo))
                {
                    this.SyncFullProfileServer2Local(serverProfile);
                }
                else
                {
                    result = "ERROR";
                    if (ResultInterpreter.IsError(serverProfile.DataInfo, "PROFILENOTFOUND"))
                    {
                        result = "PROFILENOTFOUND";
                    }
                    else if (ResultInterpreter.IsError(serverProfile.DataInfo, "The Profile is invalid."))
                    {
                        result = "INVALIDPROFILE";
                    }
                    else if (ResultInterpreter.IsError(serverProfile.DataInfo, "Invalid Security Token"))
                    {
                        result = "INCORRECTSECURITYCODE";
                    }
                }
                this.IsInProgress = false;
                this.IsDataLoaded = true;
            }
            catch (Exception ex)
            {
                result    = "ERROR";
                IsSuccess = false;
                Message   = ex.Message;
            }
            return(result);
        }
Exemplo n.º 6
0
        private async void ConfirmButton_Click(object sender, EventArgs e)
        {
            //Need to remove the back entry . Currently we are removing the back entry from Settings page.
            try
            {
                if (!ValidateInputs())
                {
                    return;
                }

                if (!Globals.IsDataNetworkAvailable)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.NetworkNotAvailableText, "basicWrap", "Connection Unavailable"));
                    return;
                }

                var countryDetails = selectedCountryCode == null ? (CountryCodes)CountryCodeListPicker.Items[CountryCodeListPicker.SelectedIndex] : selectedCountryCode;
                if ((countryDetails.IsdCode != Constants.CountryCode && countryDetails.CountryName != Constants.CountryName) || (countryDetails.IsdCode == Constants.CountryCode && countryDetails.CountryName != Constants.CountryName))
                {
                    if (!Globals.IsRegisteredUser)
                    {
                        var BuddiesToDelete = App.MyBuddies.Buddies.Count > 0 ? App.MyBuddies.Buddies.Where(c => !c.PhoneNumber.StartsWith(countryDetails.IsdCode)) : null;
                        if (BuddiesToDelete != null && BuddiesToDelete.Count() > 0)
                        {
                            StringBuilder message = new StringBuilder();
                            message.Append("The below buddies would be removed as they don't belong to ");
                            message.Append(countryDetails.CountryName + Environment.NewLine);

                            foreach (var buddy in BuddiesToDelete)
                            {
                                message.Append(buddy.Name + "(" + buddy.PhoneNumber + ")" + Environment.NewLine);
                            }

                            if (MessageBox.Show(message.ToString(), "Buddy update", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                            {
                                var count = BuddiesToDelete.Count();
                                while (BuddiesToDelete.Count() > 0)
                                {
                                    var buddy = BuddiesToDelete.ElementAt(0);

                                    if (buddy != null)
                                    {
                                        App.MyBuddies.DeleteBuddy(buddy);
                                    }
                                    if (App.MyBuddies.IsSuccess)
                                    {
                                    }
                                }
                                Globals.SetEmergencyNumbers(countryDetails);
                            }
                            else
                            {
                                CountryCodeListPicker.SelectedItem = CountryCodeListPicker.Items.First(c => ((c as CountryCodes).IsdCode == Constants.CountryCode));
                                return;
                            }
                        }
                        else
                        {
                            Globals.SetEmergencyNumbers(countryDetails);
                        }
                    }
                    else
                    {
                        var BuddiesToDelete = App.MyBuddies.Buddies.Count > 0 ? App.MyBuddies.Buddies : null;
                        if (BuddiesToDelete != null && BuddiesToDelete.Count() > 0)
                        {
                            if (MessageBox.Show(CustomMessage.RegisteredBuddiesDeleteText, "Buddy Update", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                            {
                                var count = BuddiesToDelete.Count();
                                while (BuddiesToDelete.Count() > 0)
                                {
                                    var buddy = BuddiesToDelete.ElementAt(0);

                                    if (buddy != null)
                                    {
                                        App.MyBuddies.DeleteBuddy(buddy);
                                    }
                                    if (App.MyBuddies.IsSuccess)
                                    {
                                    }
                                }

                                Globals.SetEmergencyNumbers(countryDetails);
                            }
                            else
                            {
                                CountryCodeListPicker.SelectedItem = CountryCodeListPicker.Items.First(c => ((c as CountryCodes).IsdCode == Constants.CountryCode));
                                return;
                            }
                        }
                        else
                        {
                            Globals.SetEmergencyNumbers(countryDetails);
                        }
                    }
                }

                Profile profile = null;
                m_ProgressBar.Visibility = Visibility.Visible;
                if (IsMobileNumberEdited)
                {
                    string message = await App.CurrentUser.UpdateUserLocal2Server(true, countryDetails.IsdCode + Utility.GetPlainPhoneNumber(MobileNumberTextBox.Text), HiddenSecurityCodeTextBox.Text.Trim());

                    if (message != "INCORRECTSECURITYCODE")
                    {
                        NavigationService.Navigate(new Uri("/Pages/Settings.xaml?ToPage=Profile&FromPage=Register", UriKind.Relative));
                    }

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (message == "PROFILENOTFOUND")
                        {
                            Globals.DisplayToast(CustomMessage.ProfileNotFound, "basicWrap", "Oops!");
                        }
                        else if (message == "INCORRECTSECURITYCODE")
                        {
                            Globals.DisplayToast(CustomMessage.IncorrectSecurityCode, "basicWrap", "Oops!");
                        }
                        else if (message == "ERROR")
                        {
                            Globals.DisplayToast(CustomMessage.UnableToUpdateMobile, "basicWrap", "Oops!");
                        }
                        else
                        {
                            Globals.DisplayToast(CustomMessage.ProfileLoadedSuccessfullyText, "basicWrap", "Success!");
                        }
                    });
                }
                else
                {
                    CountryCodeTextBox.Text = countryDetails.IsdCode;
                    profile = await MembershipServiceWrapper.CreateProfile(NameTextBox.Text, LiveIdTextBox.Text, CountryCodeTextBox.Text, Utility.GetPlainPhoneNumber(MobileNumberTextBox.Text), HiddenSecurityCodeTextBox.Text.Trim(), EnterpriseEmailTextBox.Text, HiddenEmailSecurityCodeTextBox.Text.Trim(), AccessToken, RefreshToken);

                    //1. If profile doesn't exist, send the local profile(if any) to create a new profile in server.
                    //2. If security code matches. Else, throw error

                    if (profile != null && ResultInterpreter.IsError(profile.DataInfo))
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.ProfileCreationFailText, "basicWrap", "Error!"));
                        m_ProgressBar.Visibility = Visibility.Collapsed;
                        return;
                    }
                    else if (profile != null && ResultInterpreter.IsAuthError(profile.DataInfo))
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.IncorrectSecurityCode, "basicWrap", "Error!"));
                        m_ProgressBar.Visibility = Visibility.Collapsed;
                        return;
                    }

                    App.CurrentUser.SyncFullProfileServer2Local(profile);

                    NavigationService.Navigate(new Uri("/Pages/Settings.xaml?ToPage=Buddies&FromPage=Register", UriKind.Relative));
                    Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.ProfileCreationSuccessText, "basicWrap", "Info!"));
                }
                m_ProgressBar.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                m_ProgressBar.Visibility = Visibility.Collapsed;
                Deployment.Current.Dispatcher.BeginInvoke(() => Globals.DisplayToast(CustomMessage.UnableToConnectService, "basicWrap", "Info!"));
                return;
            }
        }
Exemplo n.º 7
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;
            }
        }