Esempio n. 1
0
        internal static RealmSchema CreateFromObjectStoreSchema(Native.Schema nativeSchema)
        {
            var objects = new ObjectSchema[nativeSchema.objects_len];

            for (var i = 0; i < nativeSchema.objects_len; i++)
            {
                var objectSchema = Marshal.PtrToStructure <Native.SchemaObject>(IntPtr.Add(nativeSchema.objects, i * Native.SchemaObject.Size));
                var builder      = new ObjectSchema.Builder(objectSchema.name);

                for (var n = objectSchema.properties_start; n < objectSchema.properties_end; n++)
                {
                    var nativeProperty = Marshal.PtrToStructure <Native.SchemaProperty>(IntPtr.Add(nativeSchema.properties, n * Native.SchemaProperty.Size));
                    builder.Add(new Property
                    {
                        Name         = nativeProperty.name,
                        Type         = nativeProperty.type,
                        ObjectType   = nativeProperty.object_type,
                        IsPrimaryKey = nativeProperty.is_primary,
                        IsNullable   = nativeProperty.is_nullable,
                        IsIndexed    = nativeProperty.is_indexed
                    });
                }

                objects[i] = builder.Build();
            }

            return(new RealmSchema(objects));
        }
Esempio n. 2
0
        private static void GetNativeSchema(Native.Schema schema, IntPtr managedCallbackPtr)
        {
            var handle   = GCHandle.FromIntPtr(managedCallbackPtr);
            var callback = (Action <Native.Schema>)handle.Target;

            callback(schema);
            handle.Free();
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }