A SyncConfiguration is used to setup a Realm that can be synchronized between devices using the Realm Object Server. A valid User is required to create a SyncConfiguration.
Inheritance: RealmConfigurationBase
        public async void Compact_ShouldReduceSize(bool encrypt, bool populate)
        {
            var user = await User.LoginAsync(Credentials.AccessToken("foo:bar", Guid.NewGuid().ToString(), isAdmin: false), new Uri("http://localhost:9080"));
            var serverUri = new Uri($"realm://localhost:9080/~/compactrealm_{encrypt}_{populate}.realm");

            var config = new SyncConfiguration(user, serverUri);
            if (encrypt)
            {
                config.EncryptionKey = new byte[64];
                config.EncryptionKey[0] = 5;
            }

            Realm.DeleteRealm(config);

            using (var realm = Realm.GetInstance(config))
            {
                if (populate)
                {
                    AddDummyData(realm);
                }
            }

            var initialSize = new FileInfo(config.DatabasePath).Length;

            Assert.That(Realm.Compact(config));

            var finalSize = new FileInfo(config.DatabasePath).Length;
            Assert.That(initialSize >= finalSize);

            using (var realm = Realm.GetInstance(config))
            {
                Assert.That(realm.All<IntPrimaryKeyWithValueObject>().Count(), Is.EqualTo(populate ? 500 : 0));
            }
        }
Exemplo n.º 2
0
        public async void SyncConfiguration_WithoutPath()
        {
            var user = await User.LoginAsync(Credentials.AccessToken("foo:bar", Guid.NewGuid().ToString(), true), new Uri("http://localhost:9080"));
            var serverUri = new Uri("realm://localhost:9080/foobar");
            var config = new SyncConfiguration(user, serverUri);

            Realm.DeleteRealm(config);

            var file = new FileInfo(config.DatabasePath);
            Assert.That(file.Exists, Is.False);

            using (var realm = Realm.GetInstance(config))
            {
            }

            file = new FileInfo(config.DatabasePath);
            Assert.That(file.Exists);
        }
        /// <summary>
        /// Returns an instance of the Management Realm owned by the user.
        /// </summary>
        /// <remarks>
        /// This Realm can be used to control access and permissions for Realms owned by the user. This includes
        /// giving other users access to Realms.
        /// </remarks>
        /// <seealso href="https://realm.io/docs/realm-object-server/#modifying-permissions">How to control permissions</seealso>
        /// <param name="user">The user whose Management Realm to get.</param>
        /// <returns>A Realm that can be used to control access and permissions for Realms owned by the user.</returns>
        public static Realm GetManagementRealm(this User user)
        {
            var managementUriBuilder = new UriBuilder(user.ServerUri);
            if (managementUriBuilder.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase))
            {
                managementUriBuilder.Scheme = "realm";
            }
            else if (managementUriBuilder.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
            {
                managementUriBuilder.Scheme = "realms";
            }

            managementUriBuilder.Path = "/~/__management";

            var configuration = new SyncConfiguration(user, managementUriBuilder.Uri)
            {
                ObjectClasses = new[] { typeof(PermissionChange), typeof(PermissionOffer), typeof(PermissionOfferResponse) }
            };

            return Realm.GetInstance(configuration);
        }
Exemplo n.º 4
0
        public async void SyncConfiguration_WithAbsolutePath()
        {
            var user = await User.LoginAsync(Credentials.AccessToken("foo:bar", Guid.NewGuid().ToString(), true), new Uri("http://localhost:9080"));
            var serverUri = new Uri("realm://localhost:9080/foobar");

            var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "bla.realm");
            var config = new SyncConfiguration(user, serverUri, path);

            Realm.DeleteRealm(config);

            var file = new FileInfo(config.DatabasePath);
            Assert.That(file.Exists, Is.False);
            
            using (var realm = Realm.GetInstance(config))
            {
            }

            file = new FileInfo(config.DatabasePath);
            Assert.That(file.Exists);
            Assert.That(config.DatabasePath, Is.EqualTo(path));
        }
 public static extern IntPtr open_with_sync_async(Configuration configuration, SyncConfiguration sync_configuration,
                                                  [MarshalAs(UnmanagedType.LPArray), In] SchemaObject[] objects, int objects_length,
                                                  [MarshalAs(UnmanagedType.LPArray), In] SchemaProperty[] properties,
                                                  byte[] encryptionKey,
                                                  IntPtr task_completion_source,
                                                  out NativeException ex);
        public static AsyncOpenTaskHandle OpenWithSyncAsync(Configuration configuration, SyncConfiguration syncConfiguration, RealmSchema schema, byte[] encryptionKey, GCHandle tcsHandle)
        {
            DoInitialMetadataConfiguration();

            var marshaledSchema = new SharedRealmHandle.SchemaMarshaler(schema);

            var asyncTaskPtr = NativeMethods.open_with_sync_async(configuration, syncConfiguration, marshaledSchema.Objects, marshaledSchema.Objects.Length, marshaledSchema.Properties, encryptionKey, GCHandle.ToIntPtr(tcsHandle), out var nativeException);

            nativeException.ThrowIfNecessary();
            var asyncTaskHandle = new AsyncOpenTaskHandle(asyncTaskPtr);

            return(asyncTaskHandle);
        }
 public static extern IntPtr get_session([MarshalAs(UnmanagedType.LPWStr)] string path, IntPtr path_len, SyncConfiguration configuration, byte[] encryptionKey, out NativeException ex);
Exemplo n.º 8
0
        private static async Task<Realm> GetSyncedRealm(Type objectType)
        {
            var credentials = Credentials.UsernamePassword("z@z", "z", false);
            var user = await User.LoginAsync(credentials, new Uri("http://localhost:9080"));
            var configuration = new SyncConfiguration(user, new Uri($"realm://localhost:9080/~/merge_by_pk_{objectType.Name}"))
            {
                ObjectClasses = new[] { objectType }
            };

            Realm.DeleteRealm(configuration);

            return Realm.GetInstance(configuration);
        }