| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /* Copyright 2015-present MongoDB Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- using MongoDB.Bson.Serialization;
- using MongoDB.Driver.Core.Misc;
- namespace MongoDB.Driver.GridFS
- {
- /// <summary>
- /// Represents mutable options for a GridFS instance.
- /// </summary>
- public class GridFSBucketOptions
- {
- // fields
- private string _bucketName;
- private int _chunkSizeBytes;
- private bool _disableMD5 = false;
- private ReadConcern _readConcern;
- private ReadPreference _readPreference;
- private WriteConcern _writeConcern;
- // constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="GridFSBucketOptions"/> class.
- /// </summary>
- public GridFSBucketOptions()
- : this(ImmutableGridFSBucketOptions.Defaults)
- {
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="GridFSBucketOptions"/> class.
- /// </summary>
- /// <param name="other">The other <see cref="GridFSBucketOptions"/> from which to copy the values.</param>
- public GridFSBucketOptions(GridFSBucketOptions other)
- {
- Ensure.IsNotNull(other, nameof(other));
- _bucketName = other.BucketName;
- _chunkSizeBytes = other.ChunkSizeBytes;
- _disableMD5 = other.DisableMD5;
- _readConcern = other.ReadConcern;
- _readPreference = other.ReadPreference;
- _writeConcern = other.WriteConcern;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="GridFSBucketOptions"/> class.
- /// </summary>
- /// <param name="other">The other <see cref="ImmutableGridFSBucketOptions"/> from which to copy the values.</param>
- public GridFSBucketOptions(ImmutableGridFSBucketOptions other)
- {
- Ensure.IsNotNull(other, nameof(other));
- _bucketName = other.BucketName;
- _chunkSizeBytes = other.ChunkSizeBytes;
- _disableMD5 = other.DisableMD5;
- _readConcern = other.ReadConcern;
- _readPreference = other.ReadPreference;
- _writeConcern = other.WriteConcern;
- }
- // properties
- /// <summary>
- /// Gets or sets the bucket name.
- /// </summary>
- /// <value>
- /// The bucket name.
- /// </value>
- public string BucketName
- {
- get { return _bucketName; }
- set
- {
- Ensure.IsNotNullOrEmpty(value, nameof(value));
- _bucketName = value;
- }
- }
- /// <summary>
- /// Gets or sets the chunk size in bytes.
- /// </summary>
- /// <value>
- /// The chunk size in bytes.
- /// </value>
- public int ChunkSizeBytes
- {
- get { return _chunkSizeBytes; }
- set
- {
- Ensure.IsGreaterThanZero(value, nameof(value));
- _chunkSizeBytes = value;
- }
- }
-
- /// <summary>
- /// Gets or sets whether to disable MD5 checksum computation when uploading a GridFS file.
- /// </summary>
- /// <value>
- /// Whether MD5 checksum computation is disabled when uploading a GridFS file.
- /// </value>
- public bool DisableMD5
- {
- get { return _disableMD5; }
- set { _disableMD5 = value; }
- }
- /// <summary>
- /// Gets or sets the read concern.
- /// </summary>
- /// <value>
- /// The read concern.
- /// </value>
- public ReadConcern ReadConcern
- {
- get { return _readConcern; }
- set { _readConcern = value; }
- }
- /// <summary>
- /// Gets or sets the read preference.
- /// </summary>
- /// <value>
- /// The read preference.
- /// </value>
- public ReadPreference ReadPreference
- {
- get { return _readPreference; }
- set { _readPreference = value; }
- }
- /// <summary>
- /// Gets or sets the write concern.
- /// </summary>
- /// <value>
- /// The write concern.
- /// </value>
- public WriteConcern WriteConcern
- {
- get { return _writeConcern; }
- set { _writeConcern = value; }
- }
- }
- /// <summary>
- /// Represents immutable options for a GridFS instance.
- /// </summary>
- public class ImmutableGridFSBucketOptions
- {
- #region static
- // static fields
- private static readonly ImmutableGridFSBucketOptions __defaults = new ImmutableGridFSBucketOptions();
- // static properties
- /// <summary>
- /// Gets the default GridFSBucketOptions.
- /// </summary>
- /// <value>
- /// The default GridFSBucketOptions.
- /// </value>
- public static ImmutableGridFSBucketOptions Defaults
- {
- get { return __defaults; }
- }
- #endregion
- // fields
- private readonly string _bucketName;
- private readonly int _chunkSizeBytes;
- private readonly bool _disableMD5 = false;
- private readonly ReadConcern _readConcern;
- private readonly ReadPreference _readPreference;
- private readonly WriteConcern _writeConcern;
- // constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="ImmutableGridFSBucketOptions"/> class.
- /// </summary>
- public ImmutableGridFSBucketOptions()
- {
- _bucketName = "fs";
- _chunkSizeBytes = 255 * 1024;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="ImmutableGridFSBucketOptions" /> class.
- /// </summary>
- /// <param name="other">The other <see cref="GridFSBucketOptions"/> from which to copy the values.</param>
- public ImmutableGridFSBucketOptions(GridFSBucketOptions other)
- {
- Ensure.IsNotNull(other, nameof(other));
- _bucketName = other.BucketName;
- _chunkSizeBytes = other.ChunkSizeBytes;
- _disableMD5 = other.DisableMD5;
- _readConcern = other.ReadConcern;
- _readPreference = other.ReadPreference;
- _writeConcern = other.WriteConcern;
- }
- // properties
- /// <summary>
- /// Gets the bucket name.
- /// </summary>
- /// <value>
- /// The bucket name.
- /// </value>
- public string BucketName
- {
- get { return _bucketName; }
- }
- /// <summary>
- /// Gets the chunk size in bytes.
- /// </summary>
- /// <value>
- /// The chunk size in bytes.
- /// </value>
- public int ChunkSizeBytes
- {
- get { return _chunkSizeBytes; }
- }
-
- /// <summary>
- /// Gets or sets whether to disable MD5 checksum computation when uploading a GridFS file.
- /// </summary>
- /// <value>
- /// Whether MD5 checksum computation is disabled when uploading a GridFS file.
- /// </value>
- public bool DisableMD5
- {
- get { return _disableMD5; }
- }
- /// <summary>
- /// Gets the read concern.
- /// </summary>
- /// <value>
- /// The read concern.
- /// </value>
- public ReadConcern ReadConcern
- {
- get { return _readConcern; }
- }
- /// <summary>
- /// Gets the read preference.
- /// </summary>
- /// <value>
- /// The read preference.
- /// </value>
- public ReadPreference ReadPreference
- {
- get { return _readPreference; }
- }
- /// <summary>
- /// Gets the serializer registry.
- /// </summary>
- /// <value>
- /// The serializer registry.
- /// </value>
- public IBsonSerializerRegistry SerializerRegistry
- {
- get { return BsonSerializer.SerializerRegistry; }
- }
- /// <summary>
- /// Gets the write concern.
- /// </summary>
- /// <value>
- /// The write concern.
- /// </value>
- public WriteConcern WriteConcern
- {
- get { return _writeConcern; }
- }
- }
- }
|