本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFSSettings类的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFSSettings类的具体用法?C# MongoGridFSSettings怎么用?C# MongoGridFSSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoGridFSSettings类属于MongoDB.Driver.GridFS命名空间,在下文中一共展示了MongoGridFSSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEquals
public void TestEquals()
{
var a = new MongoGridFSSettings(123, "root", SafeMode.True);
var b = new MongoGridFSSettings(123, "root", SafeMode.True);;
var c = new MongoGridFSSettings(345, "root", SafeMode.True);
var n = (SafeMode) null;
Assert.IsTrue(object.Equals(a, b));
Assert.IsFalse(object.Equals(a, c));
Assert.IsFalse(a.Equals(n));
Assert.IsFalse(a.Equals(null));
Assert.IsTrue(a == b);
Assert.IsFalse(a == c);
Assert.IsFalse(a == null);
Assert.IsFalse(null == a);
Assert.IsTrue(n == null);
Assert.IsTrue(null == n);
Assert.IsFalse(a != b);
Assert.IsTrue(a != c);
Assert.IsTrue(a != null);
Assert.IsTrue(null != a);
Assert.IsFalse(n != null);
Assert.IsFalse(null != n);
}
示例2: ConstructorFeezesSettingsTest
public void ConstructorFeezesSettingsTest() {
var settings = new MongoGridFSSettings();
settings.IsFrozen.Should().Be.False();
var gridFS = new MongoGridFS(Database, settings);
gridFS.Settings.IsFrozen.Should().Be.True();
}
示例3: TestAppendTextWithSecondaryReadPreference
public void TestAppendTextWithSecondaryReadPreference()
{
_gridFS.Delete(Query.Null);
Assert.IsFalse(_gridFS.Exists("HelloWorld.txt"));
var settings = new MongoGridFSSettings() { ReadPreference = ReadPreference.Secondary };
var gridFS = _database.GetGridFS(settings);
using (var writer = gridFS.AppendText("HelloWorld.txt"))
{
Assert.IsFalse(writer.BaseStream.CanRead);
Assert.IsTrue(writer.BaseStream.CanSeek);
Assert.IsTrue(writer.BaseStream.CanWrite);
writer.Write("Hello");
}
Assert.IsTrue(_gridFS.Exists("HelloWorld.txt"));
using (var writer = gridFS.AppendText("HelloWorld.txt"))
{
writer.Write(" World");
}
var memoryStream = new MemoryStream();
_gridFS.Download(memoryStream, "HelloWorld.txt");
var bytes = memoryStream.ToArray();
Assert.AreEqual(0xEF, bytes[0]); // the BOM
Assert.AreEqual(0xBB, bytes[1]);
Assert.AreEqual(0xBF, bytes[2]);
var text = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3);
Assert.AreEqual("Hello World", text);
}
示例4: PurgeOrphanedBlobs
private static void PurgeOrphanedBlobs(HashSet<String> blobsToDelete, String connectionString, String format)
{
Console.WriteLine("Found {0} orphaned blobs in BlobStorage named {1}", blobsToDelete.Count, format);
if (blobsToDelete.Count > 0)
{
Console.WriteLine("Press y if you want to delete them, any other key to list without deletion");
var key = Console.ReadKey();
Console.WriteLine();
if (Char.ToLower(key.KeyChar) == 'y')
{
var uri = new MongoUrl(ConfigurationManager.AppSettings[connectionString]);
var client = new MongoClient(uri);
var database = client.GetServer().GetDatabase(uri.DatabaseName);
var settings = new MongoGridFSSettings()
{
Root = format
};
var gridfs = database.GetGridFS(settings);
foreach (var blobToDelete in blobsToDelete)
{
gridfs.DeleteById(blobToDelete);
Console.WriteLine("Deleted {0} in database {1}", blobToDelete, ConfigurationManager.AppSettings[connectionString]);
}
}
else
{
foreach (var blobToDelete in blobsToDelete)
{
Console.WriteLine("Blob {0} in database {1} is orphaned", blobToDelete, ConfigurationManager.AppSettings[connectionString]);
}
}
}
}
示例5: MongoReaderPlugin
/// <summary>
/// Create a MongoReaderPlugin with an existing MongoDatabase and specific settings for GridFS
/// </summary>
/// <param name="prefix">The virtual folder representing GridFS assets</param>
/// <param name="db">An existing MongoDatabase instance</param>
/// <param name="gridSettings">
/// Settings for the GridFS connection
/// <see href="http://api.mongodb.org/csharp/1.8/html/7a3abd48-0532-8e7f-3c05-6c9812eb06f8.htm" />
/// </param>
public MongoReaderPlugin(string prefix, MongoDatabase db, MongoGridFSSettings gridSettings)
{
_db = db;
_gridSettings = gridSettings;
_grid = _db.GetGridFS(gridSettings);
VirtualFilesystemPrefix = prefix;
}
示例6: TestCreateWithRemoteFileNameAndCreateOptions
public void TestCreateWithRemoteFileNameAndCreateOptions()
{
var aliases = new string[] { "a", "b" };
var uploadDate = new DateTime(2011, 11, 10, 19, 57, 0, DateTimeKind.Utc);
var metadata = new BsonDocument("x", 1);
var createOptions = new MongoGridFSCreateOptions()
{
Aliases = aliases,
ChunkSize = 123,
ContentType = "content",
Id = 1,
Metadata = metadata,
UploadDate = uploadDate
};
var settings = new MongoGridFSSettings();
var info = new MongoGridFSFileInfo(_server, _server.Primary, _database.Name, settings, "filename", createOptions);
Assert.IsTrue(aliases.SequenceEqual(info.Aliases));
Assert.AreEqual(123, info.ChunkSize);
Assert.AreEqual("content", info.ContentType);
Assert.AreEqual(1, info.Id.AsInt32);
Assert.AreEqual(0, info.Length);
Assert.AreEqual(null, info.MD5);
Assert.AreEqual(metadata, info.Metadata);
Assert.AreEqual("filename", info.Name);
Assert.AreEqual(uploadDate, info.UploadDate);
}
示例7: TestConstructorFreezesSettings
public void TestConstructorFreezesSettings()
{
var settings = new MongoGridFSSettings();
Assert.False(settings.IsFrozen);
var gridFS = new MongoGridFS(_server, _database.Name, settings);
Assert.True(gridFS.Settings.IsFrozen);
}
示例8: MongoGridFS
/// <summary>
/// Initializes a new instance of the MongoGridFS class.
/// </summary>
/// <param name="database">The database containing the GridFS collections.</param>
/// <param name="settings">The GridFS settings.</param>
public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)
{
_database = database;
_settings = settings.FrozenCopy();
_chunks = database[settings.ChunksCollectionName, settings.SafeMode];
_files = database[settings.FilesCollectionName, settings.SafeMode];
}
示例9: MongoGridFS
/// <summary>
/// Initializes a new instance of the MongoGridFS class.
/// </summary>
/// <param name="database">The database containing the GridFS collections.</param>
/// <param name="settings">The GridFS settings.</param>
public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)
{
_database = database;
_settings = settings.FrozenCopy();
_chunks = database.GetCollection(settings.ChunksCollectionName);
_files = database.GetCollection(settings.FilesCollectionName);
}
示例10: TestEquals
public void TestEquals()
{
var settings = new MongoGridFSSettings();
var createOptions = new MongoGridFSCreateOptions { ChunkSize = 123 };
var a1 = new MongoGridFSFileInfo(_server, _server.Primary, _database.Name, settings, "f", createOptions);
var a2 = new MongoGridFSFileInfo(_server, _server.Primary, _database.Name, settings, "f", createOptions);
var a3 = a2;
var b = new MongoGridFSFileInfo(_server, _server.Primary, _database.Name, settings, "g", createOptions);
var null1 = (MongoGridFSFileInfo)null;
var null2 = (MongoGridFSFileInfo)null;
Assert.AreNotSame(a1, a2);
Assert.AreSame(a2, a3);
Assert.IsTrue(a1.Equals((object)a2));
Assert.IsFalse(a1.Equals((object)null));
Assert.IsFalse(a1.Equals((object)"x"));
Assert.IsTrue(a1 == a2);
Assert.IsTrue(a2 == a3);
Assert.IsFalse(a1 == b);
Assert.IsFalse(a1 == null1);
Assert.IsFalse(null1 == a1);
Assert.IsTrue(null1 == null2);
Assert.IsFalse(a1 != a2);
Assert.IsFalse(a2 != a3);
Assert.IsTrue(a1 != b);
Assert.IsTrue(a1 != null1);
Assert.IsTrue(null1 != a1);
Assert.IsFalse(null1 != null2);
Assert.AreEqual(a1.GetHashCode(), a2.GetHashCode());
}
示例11: MongoGridFS
/// <summary>
/// Initializes a new instance of the MongoGridFS class.
/// </summary>
/// <param name="database">The database containing the GridFS collections.</param>
/// <param name="settings">The GridFS settings.</param>
public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)
{
this.database = database;
this.settings = settings.FrozenCopy();
this.chunks = database[settings.ChunksCollectionName, settings.SafeMode];
this.files = database[settings.FilesCollectionName, settings.SafeMode];
}
示例12: TestConstructorFeezesSettings
public void TestConstructorFeezesSettings()
{
var settings = new MongoGridFSSettings();
Assert.IsFalse(settings.IsFrozen);
var gridFS = new MongoGridFS(_database, settings);
Assert.IsTrue(gridFS.Settings.IsFrozen);
}
示例13: TestFixtureSetup
public void TestFixtureSetup() {
server = MongoServer.Create("mongodb://localhost/?safe=true");
database = server["onlinetests"];
var settings = new MongoGridFSSettings {
ChunkSize = 16,
SafeMode = SafeMode.True
};
gridFS = database.GetGridFS(settings);
}
示例14: MongoGridFSStreamTests
public MongoGridFSStreamTests()
{
_database = LegacyTestConfiguration.Database;
var settings = new MongoGridFSSettings
{
ChunkSize = 16,
WriteConcern = WriteConcern.Acknowledged
};
_gridFS = _database.GetGridFS(settings);
}
示例15: TestDefaults
public void TestDefaults()
{
var settings = new MongoGridFSSettings(_database);
Assert.IsFalse(settings.IsFrozen);
Assert.AreEqual("fs.chunks", settings.ChunksCollectionName);
Assert.AreEqual(256 * 1024, settings.ChunkSize);
Assert.AreEqual("fs.files", settings.FilesCollectionName);
Assert.AreEqual("fs", settings.Root);
Assert.AreEqual(WriteConcern.Errors, settings.WriteConcern);
}