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

realm / realm-dotnet / 9881710012

10 Jul 2024 09:26PM UTC coverage: 81.928% (+0.6%) from 81.376%
9881710012

Pull #3644

github

59a21e
nirinchev
Prepare a debug build
Pull Request #3644: Prepare a debug build

2317 of 3019 branches covered (76.75%)

Branch coverage included in aggregate %.

9402 of 11285 relevant lines covered (83.31%)

42998.09 hits per line

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

82.35
/Realm/Realm/Sync/AppConfiguration.cs
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2020 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 System.Net.Http;
21
using System.Net.WebSockets;
22
using Realms.Helpers;
23

24
namespace Realms.Sync
25
{
26
    /// <summary>
27
    /// A class exposing configuration options for a <see cref="App"/>.
28
    /// </summary>
29
    public class AppConfiguration
30
    {
31
        private string? _baseFilePath;
32

33
        private byte[]? _metadataEncryptionKey;
34

35
        /// <summary>
36
        /// Gets the unique app id that identifies the Realm application.
37
        /// </summary>
38
        /// <value>The Atlas App Services App's id.</value>
39
        public string AppId { get; }
1,052✔
40

41
        /// <summary>
42
        /// Gets or sets the root folder relative to which all local data for this application will be stored. This data includes
43
        /// metadata for users and synchronized Realms.
44
        /// </summary>
45
        /// <value>The app's base path.</value>
46
        public string BaseFilePath
47
        {
48
            get => _baseFilePath ?? InteropConfig.GetDefaultStorageFolder("Could not determine a writable folder to store app files (such as metadata and Realm files). When constructing the app, set AppConfiguration.BaseFilePath to an absolute path where the app is allowed to write.");
1,068✔
49
            set
50
            {
1,045✔
51
                Argument.NotNull(value, nameof(value));
1,045✔
52
                _baseFilePath = value;
1,045✔
53
            }
1,045✔
54
        }
55

56
        /// <summary>
57
        /// Gets or sets the base url for this Realm application.
58
        /// </summary>
59
        /// <remarks>
60
        /// This only needs to be set if for some reason your application isn't hosted on services.cloud.mongodb.com.
61
        /// This is typically the case when synchronizing with an edge server.
62
        /// </remarks>
63
        /// <value>The app's base url.</value>
64
        public Uri BaseUri { get; set; } = AppHandle.DefaultBaseUri;
3,150✔
65

66
        /// <summary>
67
        /// Gets or sets the local app's name.
68
        /// </summary>
69
        /// <value>The friendly name identifying the current client application.</value>
70
        [Obsolete("This property has no effect and will be removed in a future version.")]
71
        public string? LocalAppName { get; set; }
×
72

73
        /// <summary>
74
        /// Gets or sets the local app's version.
75
        /// </summary>
76
        /// <value>The client application's version.</value>
77
        /// <seealso cref="LocalAppName"/>
78
        [Obsolete("This property has no effect and will be removed in a future version.")]
79
        public string? LocalAppVersion { get; set; }
×
80

81
        /// <summary>
82
        /// Gets or sets the persistence mode for user metadata on this device.
83
        /// </summary>
84
        /// <remarks>
85
        /// The default value is <see cref="MetadataPersistenceMode.Encrypted"/> for iOS devices and <see cref="MetadataPersistenceMode.NotEncrypted"/>
86
        /// for all other platforms. On iOS we integrate with the system keychain to generate and store a random encryption key the first time the app
87
        /// is launched. On other platforms, <see cref="MetadataEncryptionKey"/> needs to be set if <see cref="MetadataPersistenceMode.Encrypted"/> is
88
        /// specified.
89
        /// </remarks>
90
        /// <value>The user metadata persistence mode.</value>
91
        public MetadataPersistenceMode? MetadataPersistenceMode { get; set; }
5,210✔
92

93
        /// <summary>
94
        /// Gets or sets the encryption key for user metadata on this device.
95
        /// </summary>
96
        /// <remarks>
97
        /// This will not change the encryption key for individual Realms. This should still be set in <see cref="SyncConfigurationBase.EncryptionKey"/>
98
        /// when opening the <see cref="Realm"/>.
99
        /// </remarks>
100
        /// <value>The user metadata encryption key.</value>
101
        public byte[]? MetadataEncryptionKey
102
        {
103
            get => _metadataEncryptionKey;
2,087✔
104
            set
105
            {
1✔
106
                if (value != null && value.Length != 64)
1!
107
                {
×
108
                    throw new FormatException("EncryptionKey must be 64 bytes");
×
109
                }
110

111
                _metadataEncryptionKey = value;
1✔
112
            }
1✔
113
        }
114

115
        /// <summary>
116
        /// Gets or sets the default request timeout for HTTP requests to MongoDB Atlas. Default is 1 minute.
117
        /// </summary>
118
        /// <value>The default HTTP request timeout.</value>
119
        public TimeSpan DefaultRequestTimeout { get; set; } = TimeSpan.FromMinutes(1);
2,106✔
120

121
        /// <summary>
122
        /// Gets or sets the <see cref="HttpMessageHandler"/> that will be used
123
        /// for the http requests to MongoDB Atlas.
124
        /// </summary>
125
        /// <value>The http client handler that configures things like certificates and proxy settings.</value>
126
        /// <remarks>
127
        /// You can use this to override the default http client handler and configure settings like proxies,
128
        /// client certificates, and cookies. While these are not required to connect to MongoDB Atlas under
129
        /// normal circumstances, they can be useful if client devices are behind a corporate firewall or use
130
        /// a more complex networking setup.
131
        /// </remarks>
132
        public HttpMessageHandler? HttpClientHandler { get; set; }
1,059✔
133

134
        /// <summary>
135
        /// Gets or sets the delegate that will be used to configure outgoing WebSocket connections to MongoDB Atlas.
136
        /// </summary>
137
        /// <value>The delegate that will be used to configure outgoing WebSocket connections.</value>
138
        /// <remarks>
139
        /// You can use this to modify the default <see cref="ClientWebSocket"/> behavior. Normally this is not
140
        /// required to connect to MongoDB Atlas, but it can be useful if client devices are behind a corporate firewall
141
        /// or use a more complex networking setup. Requires that <see cref="UseManagedWebSockets" /> is set to <c>true</c>.
142
        /// </remarks>
143
        public Action<ClientWebSocketOptions>? OnSyncWebSocketConnection { get; set; }
1,051✔
144

145
        /// <summary>
146
        /// Gets or sets a value indicating whether the .NET WebSocket client or the built-in Realm WebSocket client
147
        /// will be used for Sync traffic.
148
        /// </summary>
149
        /// <value><c>true</c> to use <see cref="ClientWebSocket"/>; <c>false</c> to use the built-in Realm WebSocket client.</value>
150
        /// <remarks>The default value is <c>false</c>, but this will change in a future version.</remarks>
151
        /// <seealso cref="OnSyncWebSocketConnection" />
152
        public bool UseManagedWebSockets { get; set; }
1,051✔
153

154
        /// <summary>
155
        /// Gets or sets the options for the assorted types of connection timeouts for sync connections
156
        /// opened for this app.
157
        /// </summary>
158
        /// <value>The sync timeout options applied to synchronized Realms.</value>
159
        public SyncTimeoutOptions SyncTimeoutOptions { get; set; } = new();
2,110✔
160

161
        /// <summary>
162
        /// Gets or sets a value indicating whether to cache app instances created with this configuration.
163
        /// </summary>
164
        /// <remarks>
165
        /// When an app is created using <see cref="App.Create(AppConfiguration)"/>, the default behavior is
166
        /// to get or add the <see cref="App"/> instance from a cache keyed on the app id. This has certain
167
        /// performance benefits when calling <see cref="App.Create(AppConfiguration)"/> multiple times.
168
        /// </remarks>
169
        /// <value><c>true</c> if the app should be cached; <c>false</c> otherwise. Default value is <c>true</c>.</value>
170
        public bool UseAppCache { get; set; } = true;
2,110✔
171

172
        /// <summary>
173
        /// Initializes a new instance of the <see cref="AppConfiguration"/> class with the specified <paramref name="appId"/>.
174
        /// </summary>
175
        /// <param name="appId">The Atlas App Services App id.</param>
176
        public AppConfiguration(string appId)
1,054✔
177
        {
1,054✔
178
            Argument.NotNullOrEmpty(appId, nameof(appId));
1,054✔
179

180
            AppId = appId;
1,054✔
181
        }
1,054✔
182
    }
183
}
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