/* 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
{
///
/// Represents mutable options for a GridFS instance.
///
public class GridFSBucketOptions
{
// fields
private string _bucketName;
private int _chunkSizeBytes;
private ReadConcern _readConcern;
private ReadPreference _readPreference;
private WriteConcern _writeConcern;
// constructors
///
/// Initializes a new instance of the class.
///
public GridFSBucketOptions()
: this(ImmutableGridFSBucketOptions.Defaults)
{
}
///
/// Initializes a new instance of the class.
///
/// The other from which to copy the values.
public GridFSBucketOptions(GridFSBucketOptions other)
{
Ensure.IsNotNull(other, nameof(other));
_bucketName = other.BucketName;
_chunkSizeBytes = other.ChunkSizeBytes;
_readConcern = other.ReadConcern;
_readPreference = other.ReadPreference;
_writeConcern = other.WriteConcern;
}
///
/// Initializes a new instance of the class.
///
/// The other from which to copy the values.
public GridFSBucketOptions(ImmutableGridFSBucketOptions other)
{
Ensure.IsNotNull(other, nameof(other));
_bucketName = other.BucketName;
_chunkSizeBytes = other.ChunkSizeBytes;
_readConcern = other.ReadConcern;
_readPreference = other.ReadPreference;
_writeConcern = other.WriteConcern;
}
// properties
///
/// Gets or sets the bucket name.
///
///
/// The bucket name.
///
public string BucketName
{
get { return _bucketName; }
set
{
Ensure.IsNotNullOrEmpty(value, nameof(value));
_bucketName = value;
}
}
///
/// Gets or sets the chunk size in bytes.
///
///
/// The chunk size in bytes.
///
public int ChunkSizeBytes
{
get { return _chunkSizeBytes; }
set
{
Ensure.IsGreaterThanZero(value, nameof(value));
_chunkSizeBytes = value;
}
}
///
/// Gets or sets the read concern.
///
///
/// The read concern.
///
public ReadConcern ReadConcern
{
get { return _readConcern; }
set { _readConcern = value; }
}
///
/// Gets or sets the read preference.
///
///
/// The read preference.
///
public ReadPreference ReadPreference
{
get { return _readPreference; }
set { _readPreference = value; }
}
///
/// Gets or sets the write concern.
///
///
/// The write concern.
///
public WriteConcern WriteConcern
{
get { return _writeConcern; }
set { _writeConcern = value; }
}
}
///
/// Represents immutable options for a GridFS instance.
///
public class ImmutableGridFSBucketOptions
{
#region static
// static fields
private static readonly ImmutableGridFSBucketOptions __defaults = new ImmutableGridFSBucketOptions();
// static properties
///
/// Gets the default GridFSBucketOptions.
///
///
/// The default GridFSBucketOptions.
///
public static ImmutableGridFSBucketOptions Defaults
{
get { return __defaults; }
}
#endregion
// fields
private readonly string _bucketName;
private readonly int _chunkSizeBytes;
private readonly ReadConcern _readConcern;
private readonly ReadPreference _readPreference;
private readonly WriteConcern _writeConcern;
// constructors
///
/// Initializes a new instance of the class.
///
public ImmutableGridFSBucketOptions()
{
_bucketName = "fs";
_chunkSizeBytes = 255 * 1024;
}
///
/// Initializes a new instance of the class.
///
/// The other from which to copy the values.
public ImmutableGridFSBucketOptions(GridFSBucketOptions other)
{
Ensure.IsNotNull(other, nameof(other));
_bucketName = other.BucketName;
_chunkSizeBytes = other.ChunkSizeBytes;
_readConcern = other.ReadConcern;
_readPreference = other.ReadPreference;
_writeConcern = other.WriteConcern;
}
// properties
///
/// Gets the bucket name.
///
///
/// The bucket name.
///
public string BucketName
{
get { return _bucketName; }
}
///
/// Gets the chunk size in bytes.
///
///
/// The chunk size in bytes.
///
public int ChunkSizeBytes
{
get { return _chunkSizeBytes; }
}
///
/// Gets the read concern.
///
///
/// The read concern.
///
public ReadConcern ReadConcern
{
get { return _readConcern; }
}
///
/// Gets the read preference.
///
///
/// The read preference.
///
public ReadPreference ReadPreference
{
get { return _readPreference; }
}
///
/// Gets the serializer registry.
///
///
/// The serializer registry.
///
public IBsonSerializerRegistry SerializerRegistry
{
get { return BsonSerializer.SerializerRegistry; }
}
///
/// Gets the write concern.
///
///
/// The write concern.
///
public WriteConcern WriteConcern
{
get { return _writeConcern; }
}
}
}