Exemple #1
0
        public static DBOpenHelper GetOpenHelper(Account account, string communityId)
        {
            string dbName = String.Format(DBName, "");

            if (account == null)
            {
                return(_defaultHelper ?? (_defaultHelper = new DBOpenHelper(dbName)));
            }
            var          uniqueId = account.UserId;
            DBOpenHelper helper   = null;

            if (_openHelpers == null)
            {
                _openHelpers = new Dictionary <string, DBOpenHelper>();
                helper       = new DBOpenHelper(String.Format(DBName, uniqueId));
                _openHelpers.Add(uniqueId, helper);
            }
            else
            {
                if (!_openHelpers.TryGetValue(uniqueId, out helper))
                {
                    helper = new DBOpenHelper(dbName);
                }
            }
            return(helper);
        }
Exemple #2
0
        public static DBOpenHelper GetOpenHelper(string dbNamePrefix, Account account, string communityId)
        {
            var dbName = new StringBuilder(dbNamePrefix);

            // If we have account information, we will use it to create a database suffix for the user.
            if (account != null)
            {
                // Default user path for a user is 'internal', if community ID is null.
                if (String.IsNullOrWhiteSpace(communityId))
                {
                    dbName.Append(communityId);
                }
            }
            dbName.Append(DBNameSuffix);
            DBOpenHelper helper = null;

            if (_openHelpers == null)
            {
                _openHelpers = new Dictionary <string, DBOpenHelper>();
                helper       = new DBOpenHelper(dbName.ToString());
                _openHelpers.Add(dbName.ToString(), helper);
            }
            else
            {
                if (!_openHelpers.TryGetValue(dbName.ToString(), out helper))
                {
                    helper = new DBOpenHelper(dbName.ToString());
                }
            }
            return(helper);
        }
        public static string GenerateDatabasePath(Account account)
        {
            DBOpenHelper open      = DBOpenHelper.GetOpenHelper(account);
            var          localPath = AppInfoService.GetApplicationLocalFolderPath();

            return(Path.Combine(localPath, open.DatabaseFile));
        }
Exemple #4
0
        public static async Task <bool> HasSmartStore(Account account)
        {
            IRandomAccessStreamWithContentType stream = null;
            bool fileExists = false;

            try
            {
                var path   = DBOpenHelper.GetOpenHelper(account).DatabaseFile;
                var folder = ApplicationData.Current.LocalFolder;
                var file   = await folder.GetFileAsync(path);

                stream = await file.OpenReadAsync();

                fileExists = true;
            }
            catch (UnauthorizedAccessException)
            {
                fileExists = true;
            }
            catch (Exception)
            {
                fileExists = false;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
            return(fileExists);
        }
        public static DBOpenHelper GetOpenHelper(Account account, string communityId)
        {
            string dbName = String.Format(DBName, "");

            if (account == null) return _defaultHelper ?? (_defaultHelper = new DBOpenHelper(dbName));
            var uniqueId = account.UserId;
            DBOpenHelper helper = null;
            if (_openHelpers == null)
            {
                _openHelpers = new Dictionary<string, DBOpenHelper>();
                helper = new DBOpenHelper(String.Format(DBName, uniqueId));
                _openHelpers.Add(uniqueId, helper);
            }
            else
            {
                if (!_openHelpers.TryGetValue(uniqueId, out helper))
                {
                    helper = new DBOpenHelper(dbName);
                }
            }
            return helper;
        }
        public static void DeleteAllDatabases(bool includeGlobal)
        {
            var accounts = AccountManager.GetAccounts();

            foreach (var accountKey in accounts.Keys)
            {
                var account = accounts[accountKey];
                var path    = DBOpenHelper.GetOpenHelper(account).DatabaseFile;
                var helper  = DBHelper.GetInstance(GenerateDatabasePath(account));
                DropAllSoups(path);
                SQLiteResult result = helper.Execute("DROP TABLE IF EXISTS " + SoupIndexMapTable);
                helper.Execute("DROP TABLE IF EXISTS " + SoupNamesTable);
                helper.Dispose();
            }
            if (includeGlobal)
            {
                var path   = DBOpenHelper.GetOpenHelper(null).DatabaseFile;
                var helper = DBHelper.GetInstance(GenerateDatabasePath(null));
                DropAllSoups(path);
                SQLiteResult result = helper.Execute("DROP TABLE IF EXISTS " + SoupIndexMapTable);
                helper.Execute("DROP TABLE IF EXISTS " + SoupNamesTable);
                helper.Dispose();
            }
        }
        public static async Task <bool> HasSmartStore(Account account)
        {
            var path = DBOpenHelper.GetOpenHelper(account).DatabaseFile;

            return(await AppInfoService.DoesFileExistAsync(path));
        }
Exemple #8
0
        public static string GenerateDatabasePath(Account account)
        {
            DBOpenHelper open = DBOpenHelper.GetOpenHelper(AccountManager.GetAccount());

            return(Path.Combine(ApplicationData.Current.LocalFolder.Path, open.DatabaseFile));
        }
        public static DBOpenHelper GetOpenHelper(string dbNamePrefix, Account account, string communityId)
        {
            var dbName = new StringBuilder(dbNamePrefix);

		    // If we have account information, we will use it to create a database suffix for the user.
		    if (account != null)
            {

			    // Default user path for a user is 'internal', if community ID is null.
		        if (String.IsNullOrWhiteSpace(communityId))
		        {
                    dbName.Append(communityId);
		        }
		    }
		    dbName.Append(DBNameSuffix);
		    DBOpenHelper helper = null;
            if (_openHelpers == null)
            {
                _openHelpers = new Dictionary<string, DBOpenHelper>();
                helper = new DBOpenHelper(dbName.ToString());
                _openHelpers.Add(dbName.ToString(), helper);
            }
            else
            {
                if (!_openHelpers.TryGetValue(dbName.ToString(), out helper))
                {
                    helper = new DBOpenHelper(dbName.ToString());
                }
            }
            return helper;
        }