public async Task Initialize()
        {
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFolder scoresFolder = await localFolder.CreateFolderAsync("HighScoreDatabase", CreationCollisionOption.OpenIfExists);

            db = new HighScoresDataContext(@"isostore:/HighScoreDatabase/highscores.sdf");
            if (!db.DatabaseExists())
            {
                db.CreateDatabase();
                DatabaseSchemaUpdater updater = db.CreateDatabaseSchemaUpdater();
                updater.DatabaseSchemaVersion = 1;
                updater.Execute();
            }
            else
            {
                DatabaseSchemaUpdater updater = db.CreateDatabaseSchemaUpdater();
                int databaseSchemaVersion = updater.DatabaseSchemaVersion;
                if (databaseSchemaVersion == 0)
                {
                    // add the difficulty column introduced in version one
                    updater.AddColumn<HighScore>("Difficulty");
                    updater.DatabaseSchemaVersion = 1;
                    updater.Execute();
                }
            }
        }
コード例 #2
0
        public async Task Initialize()
        {
            StorageFolder localFolder  = ApplicationData.Current.LocalFolder;
            StorageFolder scoresFolder = await localFolder.CreateFolderAsync("HighScoreDatabase", CreationCollisionOption.OpenIfExists);

            db = new HighScoresDataContext(@"isostore:/HighScoreDatabase/highscores.sdf");
            if (!db.DatabaseExists())
            {
                db.CreateDatabase();
                DatabaseSchemaUpdater updater = db.CreateDatabaseSchemaUpdater();
                updater.DatabaseSchemaVersion = 1;
                updater.Execute();
            }
            else
            {
                DatabaseSchemaUpdater updater = db.CreateDatabaseSchemaUpdater();
                int databaseSchemaVersion     = updater.DatabaseSchemaVersion;
                if (databaseSchemaVersion == 0)
                {
                    // add the difficulty column introduced in version one
                    updater.AddColumn <HighScore>("Difficulty");
                    updater.DatabaseSchemaVersion = 1;
                    updater.Execute();
                }
            }
        }
コード例 #3
0
        public HighScoreDatabaseRepository()
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!storage.DirectoryExists("HighScoreDatabase"))
                {
                    storage.CreateDirectory("HighScoreDatabase");
                }
            }
            db = new HighScoresDataContext(@"isostore:/HighScoreDatabase/highscores.sdf");
            if (!db.DatabaseExists())
            {
                db.CreateDatabase();
                IsolatedStorageSettings.ApplicationSettings["DatabaseSchemaVersionWhenCreated"] = 2;
            }
            else
            {
                DatabaseSchemaUpdater updater = db.CreateDatabaseSchemaUpdater();
                int databaseSchemaVersion = updater.DatabaseSchemaVersion;
                if (databaseSchemaVersion == 0)
                {
                    // get the database version from application settings
                    databaseSchemaVersion = (int)IsolatedStorageSettings.ApplicationSettings["DatabaseSchemaVersionWhenCreated"];
                }

                if (databaseSchemaVersion == 1)
                {
                    // add the difficulty column introduced in version two
                    updater.AddColumn<HighScore>("Difficulty");
                    updater.DatabaseSchemaVersion = 2;
                    updater.Execute();
                }
            }

            allQuery = CompiledQuery.Compile((HighScoresDataContext context) => from score in db.HighScores
                                                                                orderby score.Score descending
                                                                                select score);

            levelQuery = CompiledQuery.Compile((HighScoresDataContext context, int level) => from score in db.HighScores
                                                                                             orderby score.Score descending
                                                                                             where score.LevelsCompleted == level
                                                                                             select score);
        }
コード例 #4
0
        public HighScoreDatabaseRepository()
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!storage.DirectoryExists("HighScoreDatabase"))
                {
                    storage.CreateDirectory("HighScoreDatabase");
                }
            }
            db = new HighScoresDataContext(@"isostore:/HighScoreDatabase/highscores.sdf");
            if (!db.DatabaseExists())
            {
                db.CreateDatabase();
                DatabaseSchemaUpdater updater = db.CreateDatabaseSchemaUpdater();
                updater.DatabaseSchemaVersion = 1;
                updater.Execute();
            }
            else
            {
                DatabaseSchemaUpdater updater = db.CreateDatabaseSchemaUpdater();
                int databaseSchemaVersion     = updater.DatabaseSchemaVersion;
                if (databaseSchemaVersion == 0)
                {
                    // add the difficulty column introduced in version one
                    updater.AddColumn <HighScore>("Difficulty");
                    updater.DatabaseSchemaVersion = 1;
                    updater.Execute();
                }
            }

            allQuery = CompiledQuery.Compile((HighScoresDataContext context) => from score in db.HighScores
                                             orderby score.Score descending
                                             select score);

            levelQuery = CompiledQuery.Compile((HighScoresDataContext context, int level) => from score in db.HighScores
                                               orderby score.Score descending
                                               where score.LevelsCompleted == level
                                               select score);
        }