예제 #1
0
        public async Task <Tuple <bool, string> > SignOutAsync()
        {
            try
            {
                LoggerService.Instance.Log("Account.SignOutAsync...");
                IsLoading = true;
                var error   = string.Empty;
                var success = false;

                if (SignedIn)
                {
                    var email = string.Empty;
                    if (!string.IsNullOrEmpty(UserInfo.Email))
                    {
                        email = UserInfo.Email.ToLower();
                    }

                    var name = string.Empty;
                    if (!string.IsNullOrEmpty(UserInfo.Name))
                    {
                        name = UserInfo.Name.ToLower();
                    }

#if _IOS_
                    var notificationToken = RemoteNotificationsService.Instance.GetTokenValue();
                    if (!string.IsNullOrEmpty(notificationToken))
                    {
                        var notificationType = RemoteNotificationsService.Instance.GetTokenType();
                        await NotificationClient.RemoveDevice(notificationType, notificationToken);
                    }
#endif
                    var response = await LogoutClient.Logout();

                    if (response != null)
                    {
                        if (response.Success)
                        {
                            SharedSettingsService.Instance.SetBoolValue("AutoDownloadDBCreated" + email, false);
                            await(Application.Current.MainPage.BindingContext as Cloud).Logout();
                            OnPropertyChanged("SignedIn");
                            success = true;
                        }
                        else
                        {
                            error = response.ErrorMessageClean;
                        }
                    }
                    else
                    {
                        error = "There was an error logging out";
                    }
                }
                else
                {
                    error = "Please log in before attempting to log out";
                }

                if (!string.IsNullOrEmpty(error))
                {
                    LoggerService.Instance.Log("ERROR: Account.SignOutAsync: " + error);
                }
                else
                {
                    LoggerService.Instance.Log("Account.SignOutAsync: success");
                }

                OnPropertyChanged("SignedIn");
                return(Tuple.Create(success, error));
            }
            finally
            {
                IsLoading = false;
            }
        }