本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFSFileInfo类的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFSFileInfo类的具体用法?C# MongoGridFSFileInfo怎么用?C# MongoGridFSFileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoGridFSFileInfo类属于MongoDB.Driver.GridFS命名空间,在下文中一共展示了MongoGridFSFileInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 info = new MongoGridFSFileInfo(_gridFS, "filename", createOptions);
Assert.IsTrue(aliases.SequenceEqual(info.Aliases));
Assert.AreEqual(123, info.ChunkSize);
Assert.AreEqual("content", info.ContentType);
Assert.AreEqual(_gridFS, info.GridFS);
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);
}
示例2: TestEquals
public void TestEquals()
{
var createOptions = new MongoGridFSCreateOptions { ChunkSize = 123 };
var a1 = new MongoGridFSFileInfo(_gridFS, "f", createOptions);
var a2 = new MongoGridFSFileInfo(_gridFS, "f", createOptions);
var a3 = a2;
var b = new MongoGridFSFileInfo(_gridFS, "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());
}
示例3: TestEquals
public void TestEquals()
{
var createOptions = new MongoGridFSCreateOptions { ChunkSize = 123 };
var a = new MongoGridFSFileInfo(gridFS, "f", createOptions);
var b = new MongoGridFSFileInfo(gridFS, "f", createOptions);
var c = new MongoGridFSFileInfo(gridFS, "g", createOptions);
var n = (MongoCredentials) 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);
}
示例4: MongoGridFSStream
public MongoGridFSStream(
MongoGridFSFileInfo fileInfo,
FileMode mode
)
: this(fileInfo, mode, FileAccess.ReadWrite)
{
}
示例5: 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.NotSame(a1, a2);
Assert.Same(a2, a3);
Assert.True(a1.Equals((object)a2));
Assert.False(a1.Equals((object)null));
Assert.False(a1.Equals((object)"x"));
Assert.True(a1 == a2);
Assert.True(a2 == a3);
Assert.False(a1 == b);
Assert.False(a1 == null1);
Assert.False(null1 == a1);
Assert.True(null1 == null2);
Assert.False(a1 != a2);
Assert.False(a2 != a3);
Assert.True(a1 != b);
Assert.True(a1 != null1);
Assert.True(null1 != a1);
Assert.False(null1 != null2);
Assert.Equal(a1.GetHashCode(), a2.GetHashCode());
}
示例6: MongoStorageFile
internal MongoStorageFile(MongoGridFSFileInfo fileInfo )
{
if (fileInfo == null)
throw new ArgumentNullException("fileInfo");
this.fileInfo = fileInfo;
}
示例7: GridFsBlobDescriptor
public GridFsBlobDescriptor(BlobId blobId, MongoGridFSFileInfo mongoGridFsFileInfo)
{
if (mongoGridFsFileInfo == null) throw new ArgumentNullException("mongoGridFsFileInfo");
_mongoGridFsFileInfo = mongoGridFsFileInfo;
BlobId = blobId;
FileNameWithExtension = new FileNameWithExtension(_mongoGridFsFileInfo.Name);
}
示例8: FileModelFromGridFSMetadata
public static FileModel FileModelFromGridFSMetadata(MongoGridFSFileInfo gfs_entry)
{
var file_model = new FileModel();
file_model.Filename = gfs_entry.Metadata["Filename"].AsString;
file_model.PatientID = gfs_entry.Metadata["PatientID"].AsString;
file_model.ID = gfs_entry.Id.AsObjectId;
return file_model;
}
示例9: SetMetadata
/// <summary>
/// Sets the metadata for an existing GridFS file.
/// </summary>
/// <param name="fileInfo">The GridFS file.</param>
/// <param name="metadata">The metadata.</param>
public void SetMetadata(MongoGridFSFileInfo fileInfo, BsonValue metadata)
{
var database = GetDatabase(ReadPreference.Primary);
var filesCollection = GetFilesCollection(database);
var query = Query.EQ("_id", fileInfo.Id);
var update = (metadata == null) ? Update.Unset("metadata") : Update.Set("metadata", metadata);
filesCollection.Update(query, update, _settings.WriteConcern);
}
示例10: CreateText
/// <summary>
/// Creates or opens a GridFS file for writing UTF-8 encoded text.
/// </summary>
/// <param name="remoteFileName">The remote file name.</param>
/// <param name="createOptions">The create options.</param>
/// <returns>A stream writer.</returns>
public StreamWriter CreateText(string remoteFileName, MongoGridFSCreateOptions createOptions)
{
if (_settings.ReadPreference != ReadPreference.Primary)
{
var gridFS = GetPrimaryGridFSSettings();
return gridFS.CreateText(remoteFileName, createOptions);
}
using (_server.RequestStart(null, ReadPreference.Primary))
{
var serverInstance = _server.RequestConnection.ServerInstance;
var fileInfo = new MongoGridFSFileInfo(_server, serverInstance, _databaseName, _settings, remoteFileName, createOptions);
return fileInfo.CreateText();
}
}
示例11: SetContentType
/// <summary>
/// Sets the content type for an existing GridFS file.
/// </summary>
/// <param name="fileInfo">The GridFS file.</param>
/// <param name="contentType">The content type.</param>
public void SetContentType(MongoGridFSFileInfo fileInfo, string contentType)
{
var database = GetDatabase(ReadPreference.Primary);
var filesCollection = GetFilesCollection(database);
var query = Query.EQ("_id", fileInfo.Id);
var update = (contentType == null) ? Update.Unset("contentType") : Update.Set("contentType", contentType);
filesCollection.Update(query, update, _settings.WriteConcern);
}
示例12: OpenWrite
/// <summary>
/// Opens an existing GridFS file for writing.
/// </summary>
/// <param name="remoteFileName">The remote file name.</param>
/// <param name="createOptions">The create options.</param>
/// <returns>A stream.</returns>
public MongoGridFSStream OpenWrite(
string remoteFileName,
MongoGridFSCreateOptions createOptions
) {
var fileInfo = new MongoGridFSFileInfo(this, remoteFileName, createOptions);
return fileInfo.OpenWrite();
}
示例13: SetContentType
/// <summary>
/// Sets the content type for an existing GridFS file.
/// </summary>
/// <param name="fileInfo">The GridFS file.</param>
/// <param name="contentType">The content type.</param>
public void SetContentType(
MongoGridFSFileInfo fileInfo,
string contentType
) {
var query = Query.EQ("_id", fileInfo.Id);
var update = (contentType == null) ? Update.Unset("contentType") : Update.Set("contentType", contentType);
files.Update(query, update);
}
示例14: OpenText
/// <summary>
/// Opens an existing UTF-8 encoded text GridFS file for reading.
/// </summary>
/// <param name="remoteFileName">The remote file name.</param>
/// <returns>A stream reader.</returns>
public StreamReader OpenText(
string remoteFileName
) {
var fileInfo = new MongoGridFSFileInfo(this, remoteFileName);
return fileInfo.OpenText();
}
示例15: Open
/// <summary>
/// Opens a GridFS file with the specified mode.
/// </summary>
/// <param name="remoteFileName">The remote file name.</param>
/// <param name="mode">The mode.</param>
/// <returns>A stream.</returns>
public MongoGridFSStream Open(
string remoteFileName,
FileMode mode
) {
var fileInfo = new MongoGridFSFileInfo(this, remoteFileName);
return fileInfo.Open(mode);
}