예제 #1
0
        /// <summary>
        /// Factory for asynchronously obtaining a <see cref="Realm"/> instance.
        /// </summary>
        /// <remarks>
        /// If the configuration points to a remote realm belonging to a Realm Object Server
        /// the realm will be downloaded and fully synchronized with the server prior to the completion
        /// of the returned Task object.
        /// Otherwise this method behaves identically to <see cref="GetInstance(RealmConfigurationBase)"/>
        /// and immediately returns a completed Task.
        /// </remarks>
        /// <returns>A <see cref="Task{Realm}"/> that is completed once the remote realm is fully synchronized or immediately if it's a local realm.</returns>
        /// <param name="config">A configuration object that describes the realm.</param>
        public static Task<Realm> GetInstanceAsync(RealmConfigurationBase config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var schema = config.ObjectClasses != null ? RealmSchema.CreateSchemaForClasses(config.ObjectClasses) : RealmSchema.Default;
            return config.CreateRealmAsync(schema);
        }
예제 #2
0
        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));
        }
예제 #3
0
        internal static Realm GetInstance(RealmConfigurationBase config, RealmSchema schema)
        {
            Argument.NotNull(config, nameof(config));

            if (schema == null)
            {
                if (config.ObjectClasses != null)
                {
                    schema = RealmSchema.CreateSchemaForClasses(config.ObjectClasses);
                }
                else
                {
                    schema = config.IsDynamic ? RealmSchema.Empty : RealmSchema.Default;
                }
            }

            return(config.CreateRealm(schema));
        }
예제 #4
0
        internal static Realm GetInstance(RealmConfigurationBase config, RealmSchema schema)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (schema == null)
            {
                if (config.ObjectClasses != null)
                {
                    schema = RealmSchema.CreateSchemaForClasses(config.ObjectClasses);
                }
                else
                {
                    schema = RealmSchema.Default;
                }
            }

            return(config.CreateRealm(schema));
        }
예제 #5
0
        /// <summary>
        /// Factory for asynchronously obtaining a <see cref="Realm"/> instance.
        /// </summary>
        /// <remarks>
        /// If the configuration points to a remote realm belonging to a Realm Object Server
        /// the realm will be downloaded and fully synchronized with the server prior to the completion
        /// of the returned Task object.
        /// Otherwise this method behaves identically to <see cref="GetInstance(RealmConfigurationBase)"/>
        /// and immediately returns a completed Task.
        /// </remarks>
        /// <returns>A <see cref="Task{Realm}"/> that is completed once the remote realm is fully synchronized or immediately if it's a local realm.</returns>
        /// <param name="config">A configuration object that describes the realm.</param>
        public static Task <Realm> GetInstanceAsync(RealmConfigurationBase config = null)
        {
            if (config == null)
            {
                config = RealmConfiguration.DefaultConfiguration;
            }

            RealmSchema schema;

            if (config.ObjectClasses != null)
            {
                schema = RealmSchema.CreateSchemaForClasses(config.ObjectClasses);
            }
            else if (config.IsDynamic)
            {
                schema = RealmSchema.Empty;
            }
            else
            {
                schema = RealmSchema.Default;
            }

            return(config.CreateRealmAsync(schema));
        }
예제 #6
0
        /// <summary>
        /// Factory for asynchronously obtaining a <see cref="Realm"/> instance.
        /// </summary>
        /// <remarks>
        /// If the configuration points to a remote realm belonging to a Realm Object Server
        /// the realm will be downloaded and fully synchronized with the server prior to the completion
        /// of the returned Task object.
        /// Otherwise this method behaves identically to <see cref="GetInstance(RealmConfigurationBase)"/>
        /// and immediately returns a completed Task.
        /// </remarks>
        /// <returns>A <see cref="Task{Realm}"/> that is completed once the remote realm is fully synchronized or immediately if it's a local realm.</returns>
        /// <param name="config">A configuration object that describes the realm.</param>
        public static Task <Realm> GetInstanceAsync(RealmConfigurationBase config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            RealmSchema schema;

            if (config.ObjectClasses != null)
            {
                schema = RealmSchema.CreateSchemaForClasses(config.ObjectClasses);
            }
            else if (config.IsDynamic)
            {
                schema = RealmSchema.Empty;
            }
            else
            {
                schema = RealmSchema.Default;
            }

            return(config.CreateRealmAsync(schema));
        }