*/
using System;
-using Tizen;
+using System.IO;
+using Tizen.System;
namespace Tizen.Account.AccountManager
{
{
case AccountError.InvalidParameter:
{
- exp = new ArgumentException(msg + " Invalid Parameters Provided");
+ exp = new ArgumentException($"{msg} Invalid Parameters Provided");
break;
}
case AccountError.OutOfMemory:
{
- exp = new OutOfMemoryException(msg + " Out Of Memory");
+ exp = new OutOfMemoryException($"{msg} Out Of Memory");
break;
}
case AccountError.InvalidOperation:
{
- exp = new InvalidOperationException(msg + " Inavlid operation");
+ exp = new InvalidOperationException($"{msg} Inavlid operation");
break;
}
case AccountError.NoData:
{
- exp = new InvalidOperationException(msg + " Empty Data");
+ exp = new InvalidOperationException($"{msg} Empty Data");
break;
}
case AccountError.PermissionDenied:
{
- exp = new UnauthorizedAccessException(msg + " Permission Denied");
+ exp = new UnauthorizedAccessException($"{msg} Permission Denied");
break;
}
case AccountError.DBFailed:
{
- exp = new InvalidOperationException(msg + " DataBase Failed");
+ exp = new InvalidOperationException($"{msg} DataBase Failed");
break;
}
case AccountError.DBBusy:
{
- exp = new InvalidOperationException(msg + " DataBase Busy");
+ exp = new InvalidOperationException($"{msg} DataBase Busy");
break;
}
case AccountError.QuerySyntaxError:
{
- exp = new InvalidOperationException(msg + " Network Error");
+ exp = new InvalidOperationException($"{msg} Network Error");
break;
}
case AccountError.XMLFileNotFound:
{
- exp = new System.IO.FileNotFoundException(msg + " XML File not found");
+ exp = new FileNotFoundException($"{msg} XML File not found");
break;
}
case AccountError.XMLParseFailed:
{
- exp = new System.IO.InvalidDataException(msg + " XML parse error");
+ exp = new InvalidDataException($"{msg} XML parse error");
break;
}
return exp;
}
+
+ internal static bool IsAccountFeatureSupported()
+ {
+ return ((Information.TryGetValue("http://tizen.org/feature/account", out bool IsAccountSupported)) && IsAccountSupported);
+ }
+
+ internal static void CheckAccountFeature()
+ {
+ if (IsAccountFeatureSupported() == false)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "platform account feature is disabled");
+ throw new NotSupportedException("platform account feature is disabled");
+ }
+ }
}
}
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static IEnumerable<Account> GetAccountsAsync()
{
+ AccountErrorFactory.CheckAccountFeature();
+
List<Account> accounts = new List<Account>();
List<int> values = new List<int>();
Interop.Account.AccountCallback accountCallback = (IntPtr data, IntPtr userdata) =>
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static Account GetAccountById(int accountId)
{
+ AccountErrorFactory.CheckAccountFeature();
+
AccountError err = (AccountError)Interop.Account.CreateUnmanagedHandle(out IntPtr handle);
if (err != AccountError.None)
{
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static IEnumerable<AccountProvider> GetAccountProviders()
{
+ AccountErrorFactory.CheckAccountFeature();
+
List<string> values = new List<string>();
List<AccountProvider> providers = new List<AccountProvider>();
Interop.AccountProvider.AccountProviderCallback accountCallback = (IntPtr handle, IntPtr data) =>
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static AccountProvider GetAccountProviderByAppId(string appId)
{
+ AccountErrorFactory.CheckAccountFeature();
+
IntPtr handle;
Interop.AccountProvider.Create(out handle);
AccountError err = (AccountError)Interop.AccountService.GetAccountProviderByAppId(appId, out handle);
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static IEnumerable<AccountProvider> GetAccountProvidersByFeature(string feature)
{
+ AccountErrorFactory.CheckAccountFeature();
+
List<string> values = new List<string>();
List<AccountProvider> providers = new List<AccountProvider>();
Interop.AccountProvider.AccountProviderCallback providerCallback = (IntPtr handle, IntPtr data) =>
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static int AddAccount(Account account)
{
+ AccountErrorFactory.CheckAccountFeature();
+
if (account == null)
{
throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to AddAccount");
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static void UpdateAccount(Account account)
{
+ AccountErrorFactory.CheckAccountFeature();
+
if (account == null)
{
throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to UpdateAccount");
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static void DeleteAccount(Account account)
{
+ AccountErrorFactory.CheckAccountFeature();
+
if (account == null)
{
throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to DeleteAccount");
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static void DeleteAccount(string userName, string packageName)
{
+ AccountErrorFactory.CheckAccountFeature();
+
AccountError err = (AccountError)Interop.AccountService.DeleteAccountByUser(userName, packageName);
if (err != AccountError.None)
{
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static void DeleteAccount(string packageName)
{
+ AccountErrorFactory.CheckAccountFeature();
+
AccountError err = (AccountError)Interop.AccountService.DeleteAccountByPackage(packageName);
if (err != AccountError.None)
{
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static IEnumerable<Account> GetAccountsByUserName(string userName)
{
+ AccountErrorFactory.CheckAccountFeature();
+
List<Account> accounts = new List<Account>();
List<int> values = new List<int>();
Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static IEnumerable<Account> GetAccountsByPackageName(string packageName)
{
+ AccountErrorFactory.CheckAccountFeature();
+
List<Account> accounts = new List<Account>();
List<int> values = new List<int>();
Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static IEnumerable<Account> GetAccountsByCapabilityType(string type)
{
+ AccountErrorFactory.CheckAccountFeature();
+
List<Account> accounts = new List<Account>();
List<int> values = new List<int>();
Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static Dictionary<string, CapabilityState> GetCapabilitiesById(int accountId)
{
+ AccountErrorFactory.CheckAccountFeature();
+
Dictionary<string, CapabilityState> capabilities = new Dictionary<string, CapabilityState>();
Interop.Account.AccountCapabilityCallback capabilityCallback = (string type, int capabilityState, IntPtr data) =>
{
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static int GetAccountsCount()
{
+ AccountErrorFactory.CheckAccountFeature();
+
int count = 0;
AccountError err = (AccountError)Interop.AccountService.GetAccountCount(out count);
if (err != AccountError.None)
/// <exception cref="NotSupportedException">The required feature is not supported.</exception>
public static void UpdateSyncStatusById(Account account, AccountSyncState status)
{
+ AccountErrorFactory.CheckAccountFeature();
+
AccountError err = (AccountError)Interop.AccountService.UpdateAccountSyncStatusById(account.AccountId, (int)status);
if (err != AccountError.None)
{
private static readonly Interop.AccountService.SubscribeCallback s_accountUpdatedCallback = (string eventType, int accountId, IntPtr userData) =>
{
+ AccountErrorFactory.CheckAccountFeature();
+
AccountSubscriberEventArgs eventArgs = new AccountSubscriberEventArgs(eventType, accountId);
s_accountUpdated?.Invoke(null, eventArgs);
return true;
{
add
{
+ AccountErrorFactory.CheckAccountFeature();
+
if (s_accountUpdated == null)
{
if (s_subscriberHandle == null)
remove
{
+ AccountErrorFactory.CheckAccountFeature();
+
s_accountUpdated -= value;
if (s_accountUpdated == null)
{