14
14
*/
15
15
16
16
using System ;
17
+ using System . Text ;
18
+ using MongoDB . Bson ;
17
19
18
20
namespace MongoDB . Driver . GridFS
19
21
{
@@ -28,10 +30,14 @@ public class MongoGridFSSettings : IEquatable<MongoGridFSSettings>
28
30
29
31
// private fields
30
32
private Setting < int > _chunkSize ;
33
+ private Setting < GuidRepresentation > _guidRepresentation ;
34
+ private Setting < UTF8Encoding > _readEncoding ;
35
+ private Setting < ReadPreference > _readPreference ;
31
36
private Setting < string > _root ;
32
37
private Setting < bool > _updateMD5 ;
33
38
private Setting < bool > _verifyMD5 ;
34
39
private Setting < WriteConcern > _writeConcern ;
40
+ private Setting < UTF8Encoding > _writeEncoding ;
35
41
36
42
private bool _isFrozen ;
37
43
private int _frozenHashCode ;
@@ -143,6 +149,19 @@ public string FilesCollectionName
143
149
get { return ( _root . Value == null ) ? null : _root . Value + ".files" ; }
144
150
}
145
151
152
+ /// <summary>
153
+ /// Gets or sets the GuidRepresentation.
154
+ /// </summary>
155
+ public GuidRepresentation GuidRepresentation
156
+ {
157
+ get { return _guidRepresentation . Value ; }
158
+ set
159
+ {
160
+ if ( _isFrozen ) { ThrowFrozen ( ) ; }
161
+ _guidRepresentation . Value = value ;
162
+ }
163
+ }
164
+
146
165
/// <summary>
147
166
/// Gets whether the settings are frozen.
148
167
/// </summary>
@@ -151,6 +170,36 @@ public bool IsFrozen
151
170
get { return _isFrozen ; }
152
171
}
153
172
173
+ /// <summary>
174
+ /// Gets or sets the read encoding.
175
+ /// </summary>
176
+ public UTF8Encoding ReadEncoding
177
+ {
178
+ get { return _readEncoding . Value ; }
179
+ set
180
+ {
181
+ if ( _isFrozen ) { ThrowFrozen ( ) ; }
182
+ _readEncoding . Value = value ;
183
+ }
184
+ }
185
+
186
+ /// <summary>
187
+ /// Gets or sets the ReadPreference.
188
+ /// </summary>
189
+ public ReadPreference ReadPreference
190
+ {
191
+ get { return _readPreference . Value ; }
192
+ set
193
+ {
194
+ if ( _isFrozen ) { ThrowFrozen ( ) ; }
195
+ if ( value == null )
196
+ {
197
+ throw new ArgumentNullException ( "value" ) ;
198
+ }
199
+ _readPreference . Value = value ;
200
+ }
201
+ }
202
+
154
203
/// <summary>
155
204
/// Gets or sets the root collection name (the files and chunks collection names are derived from the root).
156
205
/// </summary>
@@ -227,6 +276,19 @@ public WriteConcern WriteConcern
227
276
}
228
277
}
229
278
279
+ /// <summary>
280
+ /// Gets or sets the write encoding.
281
+ /// </summary>
282
+ public UTF8Encoding WriteEncoding
283
+ {
284
+ get { return _writeEncoding . Value ; }
285
+ set
286
+ {
287
+ if ( _isFrozen ) { ThrowFrozen ( ) ; }
288
+ _writeEncoding . Value = value ;
289
+ }
290
+ }
291
+
230
292
// public operators
231
293
/// <summary>
232
294
/// Compares two MongoGridFSSettings.
@@ -259,10 +321,14 @@ public MongoGridFSSettings Clone()
259
321
{
260
322
var clone = new MongoGridFSSettings ( ) ;
261
323
clone . _chunkSize = _chunkSize . Clone ( ) ;
324
+ clone . _guidRepresentation = _guidRepresentation . Clone ( ) ;
325
+ clone . _readEncoding = _readEncoding . Clone ( ) ;
326
+ clone . _readPreference = _readPreference . Clone ( ) ;
262
327
clone . _root = _root . Clone ( ) ;
263
328
clone . _updateMD5 = _updateMD5 . Clone ( ) ;
264
329
clone . _verifyMD5 = _verifyMD5 . Clone ( ) ;
265
330
clone . _writeConcern = _writeConcern . Clone ( ) ;
331
+ clone . _writeEncoding = _writeEncoding . Clone ( ) ;
266
332
return clone ;
267
333
}
268
334
@@ -276,10 +342,14 @@ public bool Equals(MongoGridFSSettings rhs)
276
342
if ( object . ReferenceEquals ( rhs , null ) || GetType ( ) != rhs . GetType ( ) ) { return false ; }
277
343
return
278
344
_chunkSize . Value == rhs . _chunkSize . Value &&
345
+ _guidRepresentation . Value == rhs . _guidRepresentation . Value &&
346
+ object . Equals ( _readEncoding . Value , rhs . _readEncoding . Value ) &&
347
+ _readPreference . Value == rhs . _readPreference . Value &&
279
348
_root . Value == rhs . _root . Value &&
280
349
_updateMD5 . Value == rhs . _updateMD5 . Value &&
281
350
_verifyMD5 . Value == rhs . _verifyMD5 . Value &&
282
- _writeConcern . Value == rhs . _writeConcern . Value ;
351
+ _writeConcern . Value == rhs . _writeConcern . Value &&
352
+ object . Equals ( _writeEncoding . Value , rhs . _writeEncoding . Value ) ;
283
353
}
284
354
285
355
/// <summary>
@@ -337,10 +407,14 @@ public override int GetHashCode()
337
407
// see Effective Java by Joshua Bloch
338
408
int hash = 17 ;
339
409
hash = 37 * hash + _chunkSize . Value . GetHashCode ( ) ;
410
+ hash = 37 * hash + _guidRepresentation . Value . GetHashCode ( ) ;
411
+ hash = 37 * hash + ( ( _readEncoding . Value == null ) ? 0 : _readEncoding . Value . GetHashCode ( ) ) ;
412
+ hash = 37 * hash + ( ( _readPreference . Value == null ) ? 0 : _readPreference . Value . GetHashCode ( ) ) ;
340
413
hash = 37 * hash + ( ( _root . Value == null ) ? 0 : _root . Value . GetHashCode ( ) ) ;
341
414
hash = 37 * hash + _updateMD5 . Value . GetHashCode ( ) ;
342
415
hash = 37 * hash + _verifyMD5 . Value . GetHashCode ( ) ;
343
416
hash = 37 * hash + ( ( _writeConcern . Value == null ) ? 0 : _writeConcern . Value . GetHashCode ( ) ) ;
417
+ hash = 37 * hash + ( ( _writeEncoding . Value == null ) ? 0 : _writeEncoding . Value . GetHashCode ( ) ) ;
344
418
return hash ;
345
419
}
346
420
@@ -351,6 +425,18 @@ internal void ApplyDefaultValues(MongoDatabaseSettings databaseSettings)
351
425
{
352
426
ChunkSize = __defaults . ChunkSize ;
353
427
}
428
+ if ( ! _guidRepresentation . HasBeenSet )
429
+ {
430
+ GuidRepresentation = databaseSettings . GuidRepresentation ;
431
+ }
432
+ if ( ! _readEncoding . HasBeenSet )
433
+ {
434
+ ReadEncoding = databaseSettings . ReadEncoding ;
435
+ }
436
+ if ( ! _readPreference . HasBeenSet )
437
+ {
438
+ ReadPreference = databaseSettings . ReadPreference ;
439
+ }
354
440
if ( ! _root . HasBeenSet )
355
441
{
356
442
Root = __defaults . Root ;
@@ -367,6 +453,62 @@ internal void ApplyDefaultValues(MongoDatabaseSettings databaseSettings)
367
453
{
368
454
WriteConcern = databaseSettings . WriteConcern ;
369
455
}
456
+ if ( ! _writeEncoding . HasBeenSet )
457
+ {
458
+ WriteEncoding = databaseSettings . ReadEncoding ;
459
+ }
460
+ }
461
+
462
+ internal void ApplyDefaultValues ( MongoServerSettings serverSettings )
463
+ {
464
+ if ( ! _chunkSize . HasBeenSet )
465
+ {
466
+ ChunkSize = __defaults . ChunkSize ;
467
+ }
468
+ if ( ! _guidRepresentation . HasBeenSet )
469
+ {
470
+ GuidRepresentation = serverSettings . GuidRepresentation ;
471
+ }
472
+ if ( ! _readEncoding . HasBeenSet )
473
+ {
474
+ ReadEncoding = serverSettings . ReadEncoding ;
475
+ }
476
+ if ( ! _readPreference . HasBeenSet )
477
+ {
478
+ ReadPreference = serverSettings . ReadPreference ;
479
+ }
480
+ if ( ! _root . HasBeenSet )
481
+ {
482
+ Root = __defaults . Root ;
483
+ }
484
+ if ( ! _updateMD5 . HasBeenSet )
485
+ {
486
+ UpdateMD5 = __defaults . UpdateMD5 ;
487
+ }
488
+ if ( ! _verifyMD5 . HasBeenSet )
489
+ {
490
+ VerifyMD5 = __defaults . VerifyMD5 ;
491
+ }
492
+ if ( ! _writeConcern . HasBeenSet )
493
+ {
494
+ WriteConcern = serverSettings . WriteConcern ;
495
+ }
496
+ if ( ! _writeEncoding . HasBeenSet )
497
+ {
498
+ WriteEncoding = serverSettings . ReadEncoding ;
499
+ }
500
+ }
501
+
502
+ internal MongoDatabaseSettings GetDatabaseSettings ( )
503
+ {
504
+ return new MongoDatabaseSettings
505
+ {
506
+ GuidRepresentation = _guidRepresentation . Value ,
507
+ ReadEncoding = _readEncoding . Value ,
508
+ ReadPreference = _readPreference . Value ,
509
+ WriteConcern = _writeConcern . Value ,
510
+ WriteEncoding = _writeEncoding . Value
511
+ } ;
370
512
}
371
513
372
514
// private methods
0 commit comments