本文整理汇总了C#中MongoDatabase.GetGridFS方法的典型用法代码示例。如果您正苦于以下问题:C# MongoDatabase.GetGridFS方法的具体用法?C# MongoDatabase.GetGridFS怎么用?C# MongoDatabase.GetGridFS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDatabase
的用法示例。
在下文中一共展示了MongoDatabase.GetGridFS方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: MongoGridFSStreamTests
public MongoGridFSStreamTests()
{
_database = LegacyTestConfiguration.Database;
var settings = new MongoGridFSSettings
{
ChunkSize = 16,
WriteConcern = WriteConcern.Acknowledged
};
_gridFS = _database.GetGridFS(settings);
}
示例4: TestFixtureSetup
public void TestFixtureSetup()
{
_server = Configuration.TestServer;
_database = Configuration.TestDatabase;
var settings = new MongoGridFSSettings
{
ChunkSize = 16,
SafeMode = SafeMode.True
};
_gridFS = _database.GetGridFS(settings);
}
示例5: TestFixtureSetup
public void TestFixtureSetup()
{
_server = Configuration.TestServer;
_database = Configuration.TestDatabase;
var settings = new MongoGridFSSettings(_database)
{
ChunkSize = 16,
WriteConcern = WriteConcern.Errors
};
_gridFS = _database.GetGridFS(settings);
}
示例6: GridFS
public GridFS(MongoDatabase database)
{
_mongoGridFS = database.GetGridFS(new MongoGridFSSettings());
}
示例7: DownloadFile
/// <summary>
/// 下载文件
/// </summary>
/// <param name="strLocalFileName"></param>
/// <param name="strRemoteFileName"></param>
/// <param name="mongoDb"></param>
public static void DownloadFile(string strLocalFileName, string strRemoteFileName, MongoDatabase mongoDb)
{
var gfs = mongoDb.GetGridFS(new MongoGridFSSettings());
gfs.Download(strLocalFileName, strRemoteFileName);
}
示例8: DelFile
/// <summary>
/// 删除文件
/// </summary>
/// <param name="strFileName"></param>
/// <param name="mongoDb"></param>
public static void DelFile(string strFileName, MongoDatabase mongoDb)
{
var gfs = mongoDb.GetGridFS(new MongoGridFSSettings());
gfs.Delete(strFileName);
}
示例9: UpLoadFile
/// <summary>
/// 上传文件
/// </summary>
/// <remarks>Mongo允许同名文件,因为id才是主键</remarks>
/// <param name="strFileName"></param>
/// <param name="option"></param>
/// <param name="mongoDb"></param>
public static UploadResult UpLoadFile(string strFileName, UpLoadFileOption option, MongoDatabase mongoDb)
{
var gfs = mongoDb.GetGridFS(new MongoGridFSSettings());
string remoteName;
if (option.FileNameOpt == EnumGfsFileName.Filename)
{
remoteName = new FileInfo(strFileName).Name;
}
else
{
remoteName = option.DirectorySeparatorChar != Path.DirectorySeparatorChar
? strFileName.Replace(Path.DirectorySeparatorChar, option.DirectorySeparatorChar)
: strFileName;
}
try
{
MongoHelper.OnActionDone(new ActionDoneEventArgs(remoteName + " Uploading "));
if (!gfs.Exists(remoteName))
{
gfs.Upload(strFileName, remoteName);
return UploadResult.Complete;
}
switch (option.AlreadyOpt)
{
case EnumGfsAlready.JustAddIt:
gfs.Upload(strFileName, remoteName);
return UploadResult.Complete;
case EnumGfsAlready.RenameIt:
var extendName = new FileInfo(strFileName).Extension;
var mainName = remoteName.Substring(0, remoteName.Length - extendName.Length);
var i = 1;
while (gfs.Exists(mainName + i + extendName))
{
i++;
}
gfs.Upload(strFileName, mainName + i + extendName);
return UploadResult.Complete;
case EnumGfsAlready.SkipIt:
return UploadResult.Skip;
case EnumGfsAlready.OverwriteIt:
gfs.Delete(remoteName);
gfs.Upload(strFileName, remoteName);
return UploadResult.Complete;
case EnumGfsAlready.Stop:
return UploadResult.Skip;
}
return UploadResult.Skip;
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex);
return UploadResult.Exception;
}
}
示例10: OpenFile
/// 在使用GirdFileSystem的时候,请注意:
/// 1.Windows 系统的文件名不区分大小写,不过,filename一定是区分大小写的,如果大小写不匹配的话,会发生无法找到文件的问题
/// 2.Download的时候,不能使用SlaveOk选项!
/// <summary>
/// 打开文件
/// </summary>
/// <param name="strRemoteFileName"></param>
/// <param name="mongoDb"></param>
public static void OpenFile(string strRemoteFileName, MongoDatabase mongoDb)
{
var gfs = mongoDb.GetGridFS(new MongoGridFSSettings());
var strLocalFileName = strRemoteFileName.Split(Path.DirectorySeparatorChar);
try
{
if (!Directory.Exists(TempFileFolder))
{
Directory.CreateDirectory(TempFileFolder);
}
var localFileName = TempFileFolder + Path.DirectorySeparatorChar +
strLocalFileName[strLocalFileName.Length - 1];
gfs.Download(localFileName, strRemoteFileName);
Process.Start(localFileName);
}
catch (Win32Exception ex)
{
Utility.ExceptionDeal(ex, "No Program can open this file");
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex, "Error", "Exception happend when open file");
}
}
示例11: TestFixtureSetup
public void TestFixtureSetup()
{
_database = Configuration.TestDatabase;
var settings = new MongoGridFSSettings
{
ChunkSize = 16,
WriteConcern = WriteConcern.Acknowledged
};
_gridFS = _database.GetGridFS(settings);
}
示例12: OpenFile
/// 在使用GirdFileSystem的时候,请注意:
/// 1.Windows 系统的文件名不区分大小写,不过,filename一定是区分大小写的,如果大小写不匹配的话,会发生无法找到文件的问题
/// 2.Download的时候,不能使用SlaveOk选项!
/// <summary>
/// 打开文件
/// </summary>
/// <param name="strRemoteFileName"></param>
/// <param name="mongoDb"></param>
public static void OpenFile(string strRemoteFileName, MongoDatabase mongoDb)
{
var gfs = mongoDb.GetGridFS(new MongoGridFSSettings());
var strLocalFileName = strRemoteFileName.Split(Path.DirectorySeparatorChar);
if (!Directory.Exists(TempFileFolder))
{
Directory.CreateDirectory(TempFileFolder);
}
var localFileName = TempFileFolder + Path.DirectorySeparatorChar +
strLocalFileName[strLocalFileName.Length - 1];
gfs.Download(localFileName, strRemoteFileName);
Process.Start(localFileName);
}