public static string CopyBundledFileToDocuments(string realmName, string destPath = null) { destPath = RealmConfigurationBase.GetPathToRealm(destPath); // any relative subdir or filename works var assembly = typeof(TestHelpers).Assembly; var resourceName = assembly.GetManifestResourceNames().SingleOrDefault(s => s.EndsWith(realmName)); if (resourceName == null) { throw new Exception($"Couldn't find embedded resource '{realmName}' in the RealmTests assembly"); } using var stream = assembly.GetManifestResourceStream(resourceName); using var destination = new FileStream(destPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); stream.CopyTo(destination); return(destPath); }
public static void CopyBundledDatabaseToDocuments(string realmName, string destPath = null, bool overwrite = true) { destPath = RealmConfigurationBase.GetPathToRealm(destPath); // any relative subdir or filename works #if __ANDROID__ using (var asset = Application.Context.Assets.Open(realmName)) using (var destination = File.OpenWrite(destPath)) { asset.CopyTo(destination); } #else #if __IOS__ var sourceDir = Foundation.NSBundle.MainBundle.BundlePath; #else var sourceDir = NUnit.Framework.TestContext.CurrentContext.TestDirectory; #endif File.Copy(Path.Combine(sourceDir, realmName), destPath, overwrite); #endif }
public void Migrate() { var uri = RealmConfigurationBase.GetPathToRealm(DATABASE_PATH); bool databaseExist = File.Exists(uri); var configuration = new RealmConfiguration(DATABASE_PATH) { SchemaVersion = DATABASE_SCHEMA_VERSION, MigrationCallback = (migration, oldSchemaVersion) => OnMigration(migration, oldSchemaVersion, migration.NewRealm.Config.SchemaVersion) }; Realm database = Realm.GetInstance(configuration); if (!databaseExist) { var transaction = database.BeginWrite(); this.OnDataBaseCreated(database); transaction.Commit(); } database.Dispose(); }