Пример #1
0
        public ClientContext(string appId, ClientContextConfig config)
        {
            _config      = config;
            this.AppID   = appId;
            this._custom = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(_clientID))
            {
                string fullPath      = InternalSDKUtils.DetermineAppLocalStoragePath(CLIENT_ID_CACHE_FILENAME);
                var    directoryPath = InternalSDKUtils.DetermineAppLocalStoragePath();

                lock (_lock)
                {
                    if (!Directory.Exists(directoryPath))
                    {
                        Directory.CreateDirectory(directoryPath);
                    }

                    if (!System.IO.File.Exists(fullPath) || new System.IO.FileInfo(fullPath).Length == 0)
                    {
                        _clientID = Guid.NewGuid().ToString();
                        System.IO.File.WriteAllText(fullPath, _clientID);
                    }
                    else
                    {
                        using (System.IO.StreamReader file = new System.IO.StreamReader(fullPath))
                        {
                            _clientID = file.ReadToEnd();
                            file.Close();
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Constructor of <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.SQLiteEventStore"/>
        /// </summary>
        /// <param name="maConfig">Mobile Analytics Manager Configuration.</param>
        public SQLiteEventStore(MobileAnalyticsManagerConfig maConfig)
        {
            _maConfig = maConfig;
#if BCL
            _dbFileFullPath = InternalSDKUtils.DetermineAppLocalStoragePath(dbFileName);
#elif PCL
            _dbFileFullPath = System.IO.Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, dbFileName);
#endif
            SetupSQLiteEventStore();
        }
Пример #3
0
        /// <summary>
        /// Constructor of <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.SQLiteEventStore"/>
        /// </summary>
        /// <param name="maConfig">Mobile Analytics Manager Configuration.</param>
        public SQLiteEventStore(MobileAnalyticsManagerConfig maConfig)
        {
            _maConfig = maConfig;
#if BCL
            _dbFileFullPath = InternalSDKUtils.DetermineAppLocalStoragePath(dbFileName);
#elif PCL
            _dbFileFullPath = System.IO.Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, dbFileName);
#endif
            _logger.InfoFormat("Initialize SQLite event store. The SQLite DB file path is {0}.", _dbFileFullPath);
            SetupSQLiteEventStore();
        }
Пример #4
0
        public Session(string appID, MobileAnalyticsManagerConfig maConfig)
        {
            _maConfig = maConfig;
            _appId    = appID;
#if BCL
            _sessionStorageFileName = InternalSDKUtils.DetermineAppLocalStoragePath(appID + _sessionStorageFileName);
#elif PCL
            _sessionStorageFileFullPath = System.IO.Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, appID + _sessionStorageFileName);
#endif
            _sessionStorage = new SessionStorage();
        }
Пример #5
0
        public Session(string appID, MobileAnalyticsManagerConfig maConfig)
        {
            _maConfig = maConfig;
            _appID    = appID;
#if BCL
            _sessionStorageFileFullPath = InternalSDKUtils.DetermineAppLocalStoragePath(appID + _sessionStorageFileName);
#elif PCL
            _sessionStorageFileFullPath = System.IO.Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, appID + _sessionStorageFileName);
#endif
            _logger.InfoFormat("Initialize a new session. The session storage file is {0}.", _sessionStorageFileFullPath);
            _sessionStorage = new SessionStorage();
        }
Пример #6
0
        public static void ClassInit(TestContext context)
        {
#if BCL
            // This attribute must be set in BCL platform
            AWSConfigs.ApplicationName = "IntegrationTestApp";

            // clean the session and db files left in last execution
            string appDataPath = InternalSDKUtils.DetermineAppLocalStoragePath("");
            if (Directory.Exists(appDataPath))
            {
                Directory.Delete(appDataPath, true);
            }
#endif
        }
        /// <summary>
        /// Sets up SQLite database.
        /// </summary>
        private void SetupSQLiteEventStore()
        {
            this.DBfileFullPath = InternalSDKUtils.DetermineAppLocalStoragePath(dbFileName);

            string vacuumCommand = "PRAGMA auto_vacuum = 1";
            string sqlCommand    = string.Format(CultureInfo.InvariantCulture, "CREATE TABLE IF NOT EXISTS {0} ({1} TEXT NOT NULL,{2} TEXT NOT NULL UNIQUE,{3} TEXT NOT NULL, {4}  INTEGER NOT NULL DEFAULT 0 )",
                                                 TABLE_NAME, EVENT_COLUMN_NAME, EVENT_ID_COLUMN_NAME, MA_APP_ID_COLUMN_NAME, EVENT_DELIVERY_ATTEMPT_COUNT_COLUMN_NAME);

            lock (_lock)
            {
                using (var connection = new SQLiteConnection("Data Source=" + this.DBfileFullPath + ";Version=3;"))
                {
                    try
                    {
                        if (!File.Exists(this.DBfileFullPath))
                        {
                            string directory = Path.GetDirectoryName(this.DBfileFullPath);
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }
                            SQLiteConnection.CreateFile(this.DBfileFullPath);
                        }

                        connection.Open();
                        using (var command = new SQLiteCommand(vacuumCommand, connection))
                        {
                            command.ExecuteNonQuery();
                        }
                        using (var command = new SQLiteCommand(sqlCommand, connection))
                        {
                            command.ExecuteNonQuery();
                        }
                    }
                    finally
                    {
                        if (null != connection)
                        {
                            connection.Close();
                        }
                    }
                }
            }
        }
Пример #8
0
        public void Cleanup()
        {
            if (poolid != null)
            {
                DeleteIdentityPool(poolid);
            }

            CleanupCreatedRoles();

#if INCLUDE_FACEBOOK_TESTS
            if (facebookUser != null)
            {
                FacebookUtilities.DeleteFacebookUser(facebookUser);
            }
#endif
            //drop all the tables from the db
#if !BCL35
            var filePath = InternalSDKUtils.DetermineAppLocalStoragePath(DB_FILE_NAME);
            if (File.Exists(filePath))
            {
                using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};Version=3;", filePath)))
                {
                    connection.Open();

                    SQLiteCommand cmd = connection.CreateCommand();

                    cmd.CommandText = "DROP TABLE IF EXISTS records";
                    cmd.ExecuteNonQuery();

                    cmd             = connection.CreateCommand();
                    cmd.CommandText = "DROP TABLE IF EXISTS datasets";
                    cmd.ExecuteNonQuery();

                    cmd             = connection.CreateCommand();
                    cmd.CommandText = "DROP TABLE IF EXISTS kvstore";
                    cmd.ExecuteNonQuery();
                }
            }
#endif
            BaseClean();
        }
        private void SetupDatabase()
        {
            //check if database already exists
            var filePath = InternalSDKUtils.DetermineAppLocalStoragePath(DB_FILE_NAME);

            var directoryPath = InternalSDKUtils.DetermineAppLocalStoragePath();

            if (!Directory.Exists(directoryPath))
            {
                DirectoryInfo di = Directory.CreateDirectory(directoryPath);
            }

            if (!File.Exists(filePath))
            {
                SQLiteConnection.CreateFile(filePath);
            }

            connection = new SQLiteConnection(string.Format(CultureInfo.InvariantCulture, "Data Source={0};Version=3;", filePath));
            connection.Open();
            string createDatasetTable = "CREATE TABLE IF NOT EXISTS " + TABLE_DATASETS + "("
                                        + DatasetColumns.IDENTITY_ID + " TEXT NOT NULL,"
                                        + DatasetColumns.DATASET_NAME + " TEXT NOT NULL,"
                                        + DatasetColumns.CREATION_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + DatasetColumns.LAST_MODIFIED_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + DatasetColumns.LAST_MODIFIED_BY + " TEXT,"
                                        + DatasetColumns.STORAGE_SIZE_BYTES + " INTEGER DEFAULT 0,"
                                        + DatasetColumns.RECORD_COUNT + " INTEGER DEFAULT 0,"
                                        + DatasetColumns.LAST_SYNC_COUNT + " INTEGER NOT NULL DEFAULT 0,"
                                        + DatasetColumns.LAST_SYNC_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + DatasetColumns.LAST_SYNC_RESULT + " TEXT,"
                                        + "UNIQUE (" + DatasetColumns.IDENTITY_ID + ", "
                                        + DatasetColumns.DATASET_NAME + ")"
                                        + ")";

            using (var command = new SQLiteCommand(createDatasetTable, connection))
            {
                command.ExecuteNonQuery();
            }

            string createRecordsTable = "CREATE TABLE IF NOT EXISTS " + TABLE_RECORDS + "("
                                        + RecordColumns.IDENTITY_ID + " TEXT NOT NULL,"
                                        + RecordColumns.DATASET_NAME + " TEXT NOT NULL,"
                                        + RecordColumns.KEY + " TEXT NOT NULL,"
                                        + RecordColumns.VALUE + " TEXT,"
                                        + RecordColumns.SYNC_COUNT + " INTEGER NOT NULL DEFAULT 0,"
                                        + RecordColumns.LAST_MODIFIED_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + RecordColumns.LAST_MODIFIED_BY + " TEXT,"
                                        + RecordColumns.DEVICE_LAST_MODIFIED_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + RecordColumns.MODIFIED + " INTEGER NOT NULL DEFAULT 1,"
                                        + "UNIQUE (" + RecordColumns.IDENTITY_ID + ", " + RecordColumns.DATASET_NAME
                                        + ", " + RecordColumns.KEY + ")"
                                        + ")";

            using (var command = new SQLiteCommand(createRecordsTable, connection))
            {
                command.ExecuteNonQuery();
            }

            string createKvStore = "CREATE TABLE IF NOT EXISTS kvstore (key TEXT NOT NULL, value TEXT NOT NULL, UNIQUE (KEY))";

            using (var command = new SQLiteCommand(createKvStore, connection))
            {
                command.ExecuteNonQuery();
            }
        }
Пример #10
0
 static SQLiteEventStore()
 {
     _dbFileFullPath = InternalSDKUtils.DetermineAppLocalStoragePath(dbFileName);
     SetupSQLiteEventStore();
 }