本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFS.EnsureIndexes方法的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFS.EnsureIndexes方法的具体用法?C# MongoGridFS.EnsureIndexes怎么用?C# MongoGridFS.EnsureIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.GridFS.MongoGridFS
的用法示例。
在下文中一共展示了MongoGridFS.EnsureIndexes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
string connectionString = "mongodb://localhost/?safe=true";
if (!string.IsNullOrEmpty(_server))
{
connectionString = string.Format("mongodb://{0}/?safe=true", _server);
}
var server = MongoServer.Create(connectionString);
var db = server.GetDatabase(_database);
var gridFs = new MongoGridFS(db);
gridFs.EnsureIndexes();
var dirInfo = new DirectoryInfo(_dir);
ImportDirectory(gridFs, dirInfo, _root, _recursive);
}
示例2: OpenTruncate
private void OpenTruncate()
{
EnsureServerInstanceIsPrimary();
using (_fileInfo.Server.RequestStart(null, _fileInfo.ServerInstance))
{
var gridFS = new MongoGridFS(_fileInfo.Server, _fileInfo.DatabaseName, _fileInfo.GridFSSettings);
gridFS.EnsureIndexes();
_fileIsDirty = true;
// existing chunks will be overwritten as needed and extra chunks will be removed on Close
_length = 0;
_position = 0;
}
}
示例3: OpenCreate
private void OpenCreate()
{
EnsureServerInstanceIsPrimary();
using (_fileInfo.Server.RequestStart(null, _fileInfo.ServerInstance))
{
var gridFS = new MongoGridFS(_fileInfo.Server, _fileInfo.DatabaseName, _fileInfo.GridFSSettings);
var database = gridFS.GetDatabase(ReadPreference.Primary);
var filesCollection = gridFS.GetFilesCollection(database);
gridFS.EnsureIndexes();
_fileIsDirty = true;
if (_fileInfo.Id == null)
{
_fileInfo.SetId(ObjectId.GenerateNewId());
}
var aliases = (_fileInfo.Aliases != null) ? new BsonArray(_fileInfo.Aliases) : null;
var file = new BsonDocument
{
{ "_id", _fileInfo.Id },
{ "filename", _fileInfo.Name, !string.IsNullOrEmpty(_fileInfo.Name) },
{ "length", 0 },
{ "chunkSize", _fileInfo.ChunkSize },
{ "uploadDate", _fileInfo.UploadDate },
{ "md5", BsonNull.Value }, // will be updated when the file is closed (unless UpdateMD5 is false)
{ "contentType", _fileInfo.ContentType, !string.IsNullOrEmpty(_fileInfo.ContentType) }, // optional
{ "aliases", aliases, aliases != null }, // optional
{ "metadata", _fileInfo.Metadata, _fileInfo.Metadata != null } // optional
};
filesCollection.Insert(file);
_length = 0;
_position = 0;
}
}
示例4: OpenAppend
private void OpenAppend()
{
EnsureServerInstanceIsPrimary();
using (_fileInfo.Server.RequestStart(null, _fileInfo.ServerInstance))
{
var gridFS = new MongoGridFS(_fileInfo.Server, _fileInfo.DatabaseName, _fileInfo.GridFSSettings);
gridFS.EnsureIndexes();
_length = _fileInfo.Length;
_position = _fileInfo.Length;
}
}
示例5: MongoGridFSStream
/// <summary>
/// Initializes a new instance of the MongoGridFSStream class.
/// </summary>
/// <param name="fileInfo">The GridFS file info.</param>
/// <param name="mode">The mode.</param>
/// <param name="access">The acess.</param>
public MongoGridFSStream(
MongoGridFSFileInfo fileInfo,
FileMode mode,
FileAccess access
) {
this.gridFS = fileInfo.GridFS;
this.fileInfo = fileInfo;
this.mode = mode;
this.access = access;
var exists = fileInfo.Exists;
string message;
switch (mode) {
case FileMode.Append:
if (exists) {
OpenAppend();
} else {
OpenCreate();
}
break;
case FileMode.Create:
if (exists) {
OpenTruncate();
} else {
OpenCreate();
}
break;
case FileMode.CreateNew:
if (exists) {
message = string.Format("File '{0}' already exists.", fileInfo.Name);
throw new IOException(message);
} else {
OpenCreate();
}
break;
case FileMode.Open:
if (exists) {
OpenExisting();
} else {
message = string.Format("File '{0}' not found.", fileInfo.Name);
throw new FileNotFoundException(message);
}
break;
case FileMode.OpenOrCreate:
if (exists) {
OpenExisting();
} else {
OpenCreate();
}
break;
case FileMode.Truncate:
if (exists) {
OpenTruncate();
} else {
message = string.Format("File '{0}' not found.", fileInfo.Name);
throw new FileNotFoundException(message);
}
break;
default:
message = string.Format("Invalid FileMode {0}.", mode);
throw new ArgumentException(message, "mode");
}
gridFS.EnsureIndexes();
}