• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-dotnet / 5716220196

31 Jul 2023 02:52PM UTC coverage: 82.478% (-0.3%) from 82.741%
5716220196

Pull #3261

github

aed2eb
fealebenpae
Merge remote-tracking branch 'origin/main' into yg/updated-marshaling

# Conflicts:
#	Realm/Realm/Handles/SharedRealmHandle.cs
Pull Request #3261: Use modern-er marshaling techniques

2029 of 2601 branches covered (78.01%)

Branch coverage included in aggregate %.

201 of 201 new or added lines in 21 files covered. (100.0%)

6246 of 7432 relevant lines covered (84.04%)

34048.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.5
/Realm/Realm/Configurations/PartitionSyncConfiguration.cs
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2021 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
using System;
20
using MongoDB.Bson;
21
using Realms.Helpers;
22

23
namespace Realms.Sync
24
{
25
    /// <summary>
26
    /// A <see cref="PartitionSyncConfiguration"/> is used to setup a <see cref="Realm"/> that can be synchronized between devices using Atlas Device Sync.
27
    /// </summary>
28
    /// <seealso href="https://docs.mongodb.com/realm/sync/overview/">Sync Overview Docs</seealso>
29
    public class PartitionSyncConfiguration : SyncConfigurationBase
30
    {
31
        /// <summary>
32
        /// Gets or sets a callback that is invoked when download progress is made when using <see cref="Realm.GetInstanceAsync"/>.
33
        /// This will only be invoked for the initial download of the Realm and will not be invoked as further download
34
        /// progress is made during the lifetime of the Realm. It is ignored when using
35
        /// <see cref="Realm.GetInstance(RealmConfigurationBase)"/>.
36
        /// </summary>
37
        /// <value>A callback that will be periodically invoked as the Realm is downloaded.</value>
38
        public Action<SyncProgress>? OnProgress { get; set; }
217✔
39

40
        /// <summary>
41
        /// Gets the partition identifying the Realm this configuration is describing.
42
        /// </summary>
43
        /// <value>The partition value for the Realm.</value>
44
        public RealmValue Partition { get; }
361✔
45

46
        /// <summary>
47
        /// Initializes a new instance of the <see cref="PartitionSyncConfiguration"/> class.
48
        /// </summary>
49
        /// <param name="partition">
50
        /// The partition identifying the remote Realm that will be synchronized.
51
        /// </param>
52
        /// <param name="user">
53
        /// A valid <see cref="User"/>.
54
        /// </param>
55
        /// <param name="optionalPath">
56
        /// Path to the realm, must be a valid full path for the current platform, relative subdirectory, or just filename.
57
        /// </param>
58
        public PartitionSyncConfiguration(string? partition, User user, string? optionalPath = null)
59
            : this(user, partition, optionalPath)
289✔
60
        {
61
        }
289✔
62

63
        /// <summary>
64
        /// Initializes a new instance of the <see cref="PartitionSyncConfiguration"/> class.
65
        /// </summary>
66
        /// <param name="partition">
67
        /// The partition identifying the remote Realm that will be synchronized.
68
        /// </param>
69
        /// <param name="user">
70
        /// A valid <see cref="User"/>.
71
        /// </param>
72
        /// <param name="optionalPath">
73
        /// Path to the realm, must be a valid full path for the current platform, relative subdirectory, or just filename.
74
        /// </param>
75
        public PartitionSyncConfiguration(long? partition, User user, string? optionalPath = null)
76
            : this(user, partition, optionalPath)
2✔
77
        {
78
        }
2✔
79

80
        /// <summary>
81
        /// Initializes a new instance of the <see cref="PartitionSyncConfiguration"/> class.
82
        /// </summary>
83
        /// <param name="partition">
84
        /// The partition identifying the remote Realm that will be synchronized.
85
        /// </param>
86
        /// <param name="user">
87
        /// A valid <see cref="User"/>.
88
        /// </param>
89
        /// <param name="optionalPath">
90
        /// Path to the realm, must be a valid full path for the current platform, relative subdirectory, or just filename.
91
        /// </param>
92
        public PartitionSyncConfiguration(ObjectId? partition, User user, string? optionalPath = null)
93
            : this(user, partition, optionalPath)
2✔
94
        {
95
        }
2✔
96

97
        /// <summary>
98
        /// Initializes a new instance of the <see cref="PartitionSyncConfiguration"/> class.
99
        /// </summary>
100
        /// <param name="partition">
101
        /// The partition identifying the remote Realm that will be synchronized.
102
        /// </param>
103
        /// <param name="user">
104
        /// A valid <see cref="User"/>.
105
        /// </param>
106
        /// <param name="optionalPath">
107
        /// Path to the realm, must be a valid full path for the current platform, relative subdirectory, or just filename.
108
        /// </param>
109
        public PartitionSyncConfiguration(Guid? partition, User user, string? optionalPath = null)
110
            : this(user, partition, optionalPath)
2✔
111
        {
112
        }
2✔
113

114
        private PartitionSyncConfiguration(User user, RealmValue partition, string? path)
115
            : base(user, GetPathToRealm(path ?? user?.Handle.GetRealmPath(partition.ToNativeJson())))
295!
116
        {
117
            Partition = partition;
295✔
118
        }
295✔
119

120
        internal override IDisposable? OnBeforeRealmOpen(AsyncOpenTaskHandle handle)
121
        {
122
            var onProgress = OnProgress;
212✔
123
            if (onProgress is null)
212✔
124
            {
125
                return null;
209✔
126
            }
127

128
            return new ProgressNotificationToken(
3✔
129
                observer: (progress) =>
3✔
130
                {
3✔
131
                    onProgress(progress);
5✔
132
                },
2✔
133
                register: handle.RegisterProgressNotifier,
3✔
134
                unregister: (token) =>
3✔
135
                {
3✔
136
                    if (!handle.IsClosed)
3!
137
                    {
3✔
138
                        handle.UnregisterProgressNotifier(token);
×
139
                    }
3✔
140
                });
6✔
141
        }
142

143
        internal override Native.SyncConfiguration CreateNativeSyncConfiguration()
144
        {
145
            var config = base.CreateNativeSyncConfiguration();
303✔
146
            config.Partition = Partition.ToNativeJson();
303✔
147
            return config;
303✔
148
        }
149
    }
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc