internal void PopulateConfiguration(ref Native.Configuration configuration) { var migrationHandle = GCHandle.Alloc(this); configuration.migration_callback = MigrationCallback; configuration.managed_migration_handle = GCHandle.ToIntPtr(migrationHandle); }
internal override Realm CreateRealm(RealmSchema schema) { var srHandle = new SharedRealmHandle(); var configuration = new Native.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); } var srPtr = IntPtr.Zero; try { srPtr = srHandle.Open(configuration, schema, EncryptionKey); } catch (ManagedExceptionDuringMigrationException) { throw new AggregateException("Exception occurred in a Realm migration callback. See inner exception for more details.", migration?.MigrationException); } srHandle.SetHandle(srPtr); return(new Realm(srHandle, this, schema)); }
public static IntPtr Open(Native.Configuration configuration, RealmSchema schema, byte[] encryptionKey) { var marshaledSchema = new SchemaMarshaler(schema); var result = NativeMethods.open(configuration, marshaledSchema.Objects, marshaledSchema.Objects.Length, marshaledSchema.Properties, encryptionKey, out NativeException nativeException); nativeException.ThrowIfNecessary(); return(result); }
internal static Realm GetInstance(RealmConfiguration config, RealmSchema schema) { config = config ?? RealmConfiguration.DefaultConfiguration; var srHandle = new SharedRealmHandle(); if (schema == null) { if (config.ObjectClasses != null) { schema = RealmSchema.CreateSchemaForClasses(config.ObjectClasses); } else { schema = RealmSchema.Default; } } var configuration = new Native.Configuration { Path = config.DatabasePath, read_only = config.ReadOnly, delete_if_migration_needed = config.ShouldDeleteIfMigrationNeeded, schema_version = config.SchemaVersion }; Migration migration = null; if (config.MigrationCallback != null) { migration = new Migration(config, schema); migration.PopulateConfiguration(ref configuration); } var srPtr = IntPtr.Zero; try { srPtr = srHandle.Open(configuration, schema, config.EncryptionKey); } catch (ManagedExceptionDuringMigrationException) { throw new AggregateException("Exception occurred in a Realm migration callback. See inner exception for more details.", migration?.MigrationException); } RuntimeHelpers.PrepareConstrainedRegions(); try { /* Retain handle in a constrained execution region */ } finally { srHandle.SetHandle(srPtr); } return(new Realm(srHandle, config, schema)); }
public static extern IntPtr open(Native.Configuration configuration, [MarshalAs(UnmanagedType.LPArray), In] Native.SchemaObject[] objects, int objects_length, [MarshalAs(UnmanagedType.LPArray), In] Native.SchemaProperty[] properties, byte[] encryptionKey, out NativeException ex);
internal override Realm CreateRealm(RealmSchema schema) { var srHandle = new SharedRealmHandle(); var configuration = new Native.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); } var srPtr = IntPtr.Zero; try { srPtr = srHandle.Open(configuration, schema, EncryptionKey); } catch (ManagedExceptionDuringMigrationException) { throw new AggregateException("Exception occurred in a Realm migration callback. See inner exception for more details.", migration?.MigrationException); } srHandle.SetHandle(srPtr); return new Realm(srHandle, this, schema); }