Example #1
0
        /// <summary>
        /// Adds an account with UserId and UserPassword received from accountItem.
        /// You should get these from server communication in actual account provider.
        /// </summary>
        /// <param name="accountItem"> Account item to add.</param>
        /// <returns> The account ID of the account instance. </returns>
        public int AccountAdd(UserCredentials accountItem)
        {
            if (accountItem == null)
            {
                throw new ArgumentNullException(nameof(accountItem));
            }

            try
            {
                int id = -1;

                // Create account instance
                Tizen.Account.AccountManager.Account account = Tizen.Account.AccountManager.Account.CreateAccount();
                if (account == null)
                {
                    return(id);
                }

                // Add account with inputed id and password.
                // In sample app, just add id as user_name and password as access_token.
                // But, you should get these from server communication in actual account provider.
                account.UserName    = accountItem.Username;
                account.AccessToken = accountItem.Password;
                account.SyncState   = AccountSyncState.Idle;

                // Insert account DB with the new account information.
                // AddAccount returns account id.

                // ApplicationManager.GetAppId()
                // var accountProvider = AccountService.GetAccountProviderByAppId();
                var appInfo         = Tizen.Applications.Application.Current.ApplicationInfo;
                var accountprovider = AccountService.GetAccountProviderByAppId(appInfo.ApplicationId);
                var providers       = AccountService.GetAccountProviders();
                id = AccountService.AddAccount(account);
                return(id);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error Message : " + e.ToString());
                return(-1);
            }
        }
Example #2
0
        /// <summary>
        /// Deletes the account information from the database.
        /// </summary>
        /// <param name="accountItem"> Account item to sign out.</param>
        public void AccountSignOut(UserCredentials accountItem)
        {
            try
            {
                if (accountItem == null)
                {
                    throw new ArgumentNullException(nameof(accountItem));
                }

                // GetAccountByID return account instance with reference to the given ID
                Tizen.Account.AccountManager.Account account = AccountService.GetAccountById(accountItem.Id);

                // Deletes the account information from the account DB.
                AccountService.DeleteAccount(account);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error Message : " + e.ToString());
            }
        }