-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathAsymmetrics.cs
79 lines (69 loc) · 2.12 KB
/
Asymmetrics.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
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Linq;
using System.Xml.Linq;
using Examples.Models;
using NUnit.Framework;
using Realms;
using Realms.Sync;
using Realms.Sync.ErrorHandling;
namespace Examples
{
public partial class Asymmetrics
{
App app;
Realms.Sync.User user;
Realm realm;
const string myRealmAppId = Config.FSAppId;
[OneTimeSetUp]
public void Setup()
{
app = App.Create(myRealmAppId);
user = app.LogInAsync(
Credentials.Anonymous()).Result;
var config = new FlexibleSyncConfiguration(user)
{
Schema = new[] { typeof(Measurement) }
};
realm = Realm.GetInstance(config);
// You cannot add a subscription for an AsymmetricObject
// This causes a compile-time error:
// :uncomment-start:
//realm.Subscriptions.Update(() =>
//{
// realm.Subscriptions.Add(realm.All<Measurement>());
//});
// :uncomment-end:
}
// :snippet-start: asymmetry
// :remove-start:
[Realms.Explicit]
// :remove-end:
private partial class Measurement : IAsymmetricObject
{
[PrimaryKey, MapTo("_id")]
public Guid Id { get; private set; } = Guid.NewGuid();
public double Value { get; set; }
public DateTimeOffset Timestamp { get; private set; } = DateTimeOffset.UtcNow;
}
// :remove-start:
[Test]
// :remove-end:
public void SendMeasurementToRealm()
{
var measurement = new Measurement
{
Value = 9.876
};
realm.Write(() =>
{
realm.Add(measurement);
});
// The following line will cause a compile time error
// _ = realm.All<Measurement>();
// The following line will compile but throw a
// Realms.Exceptions.RealmInvalidObjectException at runtime
// _ = measurement.Value;
}
// :snippet-end:
}
}