private static bool MigrationCallback(IntPtr oldRealmPtr, IntPtr newRealmPtr, Native.Schema oldSchema, ulong schemaVersion, IntPtr managedMigrationHandle) { var migrationHandle = GCHandle.FromIntPtr(managedMigrationHandle); var migration = (Migration)migrationHandle.Target; // the realms here are owned by Object Store so we should do nothing to clean them up var oldRealmHandle = new UnownedRealmHandle(); var newRealmHandle = new UnownedRealmHandle(); RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { oldRealmHandle.SetHandle(oldRealmPtr); newRealmHandle.SetHandle(newRealmPtr); } var oldConfiguration = new RealmConfiguration(migration._configuration.DatabasePath) { SchemaVersion = schemaVersion, IsReadOnly = true }; var oldRealm = new Realm(oldRealmHandle, oldConfiguration, RealmSchema.CreateFromObjectStoreSchema(oldSchema)); var newRealm = new Realm(newRealmHandle, migration._configuration, migration._schema); var result = migration.Execute(oldRealm, newRealm); migrationHandle.Free(); return(result); }
public RealmSchema GetSchema() { RealmSchema result = null; Action <Native.Schema> callback = (nativeSmallSchema) => result = RealmSchema.CreateFromObjectStoreSchema(nativeSmallSchema); // The callbackHandle will get freed in SharedRealmHandle.GetNativeSchema. var callbackHandle = GCHandle.Alloc(callback); NativeMethods.get_schema(this, GCHandle.ToIntPtr(callbackHandle), out var nativeException); nativeException.ThrowIfNecessary(); return(result); }
internal override Realm CreateRealm(RealmSchema schema) { var configuration = new Configuration { Path = DatabasePath, read_only = IsReadOnly, delete_if_migration_needed = ShouldDeleteIfMigrationNeeded, schema_version = SchemaVersion }; Migration migration = null; if (MigrationCallback != null) { migration = new Migration(this, schema); migration.PopulateConfiguration(ref configuration); } if (ShouldCompactOnLaunch != null) { var handle = GCHandle.Alloc(ShouldCompactOnLaunch); configuration.should_compact_callback = ShouldCompactOnLaunchCallback; configuration.managed_should_compact_delegate = GCHandle.ToIntPtr(handle); } var srPtr = IntPtr.Zero; try { srPtr = SharedRealmHandle.Open(configuration, schema, EncryptionKey); } catch (ManagedExceptionDuringMigrationException) { throw new AggregateException("Exception occurred in a Realm migration callback. See inner exception for more details.", migration?.MigrationException); } var srHandle = new SharedRealmHandle(); srHandle.SetHandle(srPtr); if (Dynamic && !schema.Any()) { srHandle.GetSchema(nativeSchema => schema = RealmSchema.CreateFromObjectStoreSchema(nativeSchema)); } return(new Realm(srHandle, this, schema)); }
public RealmSchema GetSchema() { RealmSchema result = null; Action <Native.Schema> callback = schema => result = RealmSchema.CreateFromObjectStoreSchema(schema); var handle = GCHandle.Alloc(callback); try { NativeMethods.get_schema(this, GCHandle.ToIntPtr(handle), out var nativeException); nativeException.ThrowIfNecessary(); } finally { handle.Free(); } return(result); }
private static bool MigrationCallback(IntPtr oldRealmPtr, IntPtr newRealmPtr, Native.Schema oldSchema, ulong schemaVersion, IntPtr managedMigrationHandle) { var migrationHandle = GCHandle.FromIntPtr(managedMigrationHandle); var migration = (Migration)migrationHandle.Target; var oldRealmHandle = new UnownedRealmHandle(oldRealmPtr); var oldConfiguration = new RealmConfiguration(migration._configuration.DatabasePath) { SchemaVersion = schemaVersion, IsReadOnly = true }; var oldRealm = new Realm(oldRealmHandle, oldConfiguration, RealmSchema.CreateFromObjectStoreSchema(oldSchema)); var newRealmHandle = new UnownedRealmHandle(newRealmPtr); var newRealm = new Realm(newRealmHandle, migration._configuration, migration._schema); var result = migration.Execute(oldRealm, newRealm); migrationHandle.Free(); return(result); }