-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathConvert.cs
67 lines (54 loc) · 2.19 KB
/
Convert.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using Realms;
using Realms.Sync;
using MongoDB.Bson;
using System.Linq;
using NUnit.Framework;
using System.Threading.Tasks;
using Realms.Exceptions.Sync;
namespace Examples
{
public class Convert
{
public async Task TestNoSyncToSync()
{
// :snippet-start: nonsync-to-sync
var existingConfig = new RealmConfiguration("example.realm");
var existingRealm = Realm.GetInstance(existingConfig);
var app = App.Create("my-app-id");
var user = await app.LogInAsync(
Credentials.EmailPassword("email@example.com", "password"));
var syncConfig = new PartitionSyncConfiguration("user_partition", user);
existingRealm.WriteCopy(syncConfig);
// You can now delete the nonsynced realm:
Realm.DeleteRealm(existingConfig);
// You can now use the synced realm:
var syncedRealm = Realm.GetInstance(syncConfig);
// :snippet-end:
}
public async Task TestSyncToNoSync()
{
// :snippet-start: sync-to-nosync
// Open the existing sycned realm
var app = App.Create("my-app-id");
var user = await app.LogInAsync(
Credentials.EmailPassword("email@example.com", "password"));
var syncedConfig = new FlexibleSyncConfiguration(user);
var syncedRealm = await Realm.GetInstanceAsync(syncedConfig);
// When copying a Synced realm, you must ensure
// that there are no pending Sync operations. You do this
// by calling WaitForUploadAsync() and WaitForDownloadAsync()
// methods:
var session = syncedRealm.SyncSession;
await session.WaitForUploadAsync();
await session.WaitForDownloadAsync();
var nonSyncConfig = new RealmConfiguration();
syncedRealm.WriteCopy(nonSyncConfig);
// You can now delete the synced realm:
Realm.DeleteRealm(syncedConfig);
// You can now use the nonsynced realm:
var nonSyncedRealm = Realm.GetInstance(nonSyncConfig);
// :snippet-end:
}
}
}