本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFSCreateOptions类的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFSCreateOptions类的具体用法?C# MongoGridFSCreateOptions怎么用?C# MongoGridFSCreateOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoGridFSCreateOptions类属于MongoDB.Driver.GridFS命名空间,在下文中一共展示了MongoGridFSCreateOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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());
}
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:32,代码来源:MongoGridFSFileInfoTests.cs
示例2: CopyTo
public void CopyTo() {
gridFS.Delete(Query.Null);
gridFS.Chunks.Count().Should().Be(0);
gridFS.Files.Count().Should().Be(0);
var uploadStream = new MemoryStream(ContentBytes);
var createOptions = new MongoGridFSCreateOptions
{
Aliases = new[] { "애국가", "HelloWorld" },
ChunkSize = gridFS.Settings.ChunkSize,
ContentType = "text/plain",
Id = ObjectId.GenerateNewId(),
Metadata = new BsonDocument { { "a", 1 }, { "b", 2 } },
UploadDate = DateTime.UtcNow
};
var fileInfo = gridFS.Upload(uploadStream, "HelloWorld.txt", createOptions);
fileInfo.Should().Not.Be.Null();
var copyInfo = fileInfo.CopyTo("HelloWorld2.txt");
copyInfo.Should().Not.Be.Null();
gridFS.Chunks.Count().Should().Be(2); // 하나의 파일 크기가 ChunkSize 보다 작으므로
gridFS.Files.Count().Should().Be(2);
copyInfo.Aliases.Should().Be.Null(); // Alias는 복사되지 않습니다.
copyInfo.ChunkSize.Should().Be(fileInfo.ChunkSize);
copyInfo.ContentType.Should().Be(fileInfo.ContentType);
copyInfo.Id.Should().Not.Be(fileInfo.Id);
copyInfo.Length.Should().Be(fileInfo.Length);
copyInfo.MD5.Should().Be(fileInfo.MD5);
Assert.AreEqual(fileInfo.Metadata, copyInfo.Metadata);
copyInfo.Name.Should().Be("HelloWorld2.txt");
copyInfo.UploadDate.Should().Be(fileInfo.UploadDate);
}
开发者ID:debop,项目名称:NFramework,代码行数:34,代码来源:MongoGridFSFixture.cs
示例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);
}
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:27,代码来源:MongoGridFSFileInfoTests.cs
示例4: 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);
}
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:26,代码来源:MongoGridFSFileInfoTests.cs
示例5: Upload
/// <summary>
/// Store a file in the database
/// </summary>
/// <param name="stream">The stream of the files content</param>
/// <param name="fileName">The remote filename</param>
/// <param name="contentType">The file's content type</param>
/// <returns>GridFS File Info</returns>
public MongoGridFSFileInfo Upload(Stream stream, string fileName, string contentType)
{
MongoGridFS fs = new MongoGridFS(this.store);
MongoGridFSCreateOptions options = new MongoGridFSCreateOptions();
options.ContentType = contentType;
return fs.Upload(stream, fileName, options);
}
开发者ID:gazeth,项目名称:Bullet,代码行数:14,代码来源:GridFS.cs
示例6: TestCopyTo
public void TestCopyTo()
{
_gridFS.Delete(Query.Null);
Assert.AreEqual(0, _gridFS.Chunks.Count());
Assert.AreEqual(0, _gridFS.Files.Count());
var contents = "Hello World";
var bytes = Encoding.UTF8.GetBytes(contents);
var uploadStream = new MemoryStream(bytes);
var createOptions = new MongoGridFSCreateOptions
{
Aliases = new[] { "HelloWorld", "HelloUniverse" },
ChunkSize = _gridFS.Settings.ChunkSize,
ContentType = "text/plain",
Id = ObjectId.GenerateNewId(),
Metadata = new BsonDocument { { "a", 1 }, { "b", 2 } },
UploadDate = DateTime.UtcNow
};
var fileInfo = _gridFS.Upload(uploadStream, "HelloWorld.txt", createOptions);
var copyInfo = fileInfo.CopyTo("HelloWorld2.txt");
Assert.AreEqual(2, _gridFS.Chunks.Count());
Assert.AreEqual(2, _gridFS.Files.Count());
Assert.IsNull(copyInfo.Aliases);
Assert.AreEqual(fileInfo.ChunkSize, copyInfo.ChunkSize);
Assert.AreEqual(fileInfo.ContentType, copyInfo.ContentType);
Assert.AreNotEqual(fileInfo.Id, copyInfo.Id);
Assert.AreEqual(fileInfo.Length, copyInfo.Length);
Assert.AreEqual(fileInfo.MD5, copyInfo.MD5);
Assert.AreEqual(fileInfo.Metadata, copyInfo.Metadata);
Assert.AreEqual("HelloWorld2.txt", copyInfo.Name);
Assert.AreEqual(fileInfo.UploadDate, copyInfo.UploadDate);
}
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:32,代码来源:MongoGridFSTests.cs
示例7: 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());
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:33,代码来源:MongoGridFSFileInfoTests.cs
示例8: Add
/// <summary>
/// 添加本地文件
/// </summary>
/// <param name="filePath">本地文件路径</param>
/// <param name="remoteFile">服务Id</param>
/// <returns></returns>
public MetaInfo Add(string filePath, string remoteFile)
{
try
{
_logger.DebugFormat("Add File filePath:{0}, remoteId:{1}", filePath, remoteFile);
MongoGridFSCreateOptions option = new MongoGridFSCreateOptions
{
Id = remoteFile,
UploadDate = DateTime.Now,
ContentType = MimeMapper.GetMimeMapping(filePath),
};
using (var stream = new FileStream(filePath, FileMode.Open))
{
MongoGridFS fs = new MongoGridFS(_context.DataBase);
var info = fs.Upload(stream, remoteFile, option);
return new MetaInfo
{
fileName = remoteFile,
MD5 = info.MD5,
MimeType = info.ContentType,
};
}
}
catch (Exception ex)
{
_logger.Error(ex.Message);
_logger.Error(ex.StackTrace);
throw;
}
}
开发者ID:ideayapai,项目名称:docviewer,代码行数:40,代码来源:MongoPolicy.cs
示例9: UploadFile
public static MongoGridFSFileInfo UploadFile(this IMongoRepository repository, string remoteFilename, Stream stream,
MongoGridFSCreateOptions createOptions) {
stream.ShouldNotBeNull("stream");
remoteFilename.ShouldNotBeWhiteSpace("remoteFilename");
return repository.GridFS.Upload(stream, remoteFilename, createOptions);
}
开发者ID:debop,项目名称:NFramework,代码行数:7,代码来源:MongoRepository.GridFS.cs
示例10: AttachFile
public ActionResult AttachFile(HttpPostedFileBase file)
{
var options = new MongoGridFSCreateOptions
{
ContentType = file.ContentType
};
var fileInfo = mongoContext.Database.GridFS.Upload(file.InputStream, file.FileName, options);
return Json(fileInfo, JsonRequestBehavior.AllowGet);
}
开发者ID:marcobradley,项目名称:MongoDB,代码行数:9,代码来源:HomeController.cs
示例11: ImportFile
public MongoGridFSFileInfo ImportFile(Stream stream, string fileName, MongoGridFSCreateOptions createOptions)
{
if (stream == null) throw new ArgumentNullException("stream");
if (fileName == null) throw new ArgumentNullException("fileName");
if (createOptions == null) throw new ArgumentNullException("createOptions");
if(createOptions.Id == null) throw new NullReferenceException("createOptions.Id");
if (createOptions.UploadDate == null) throw new NullReferenceException("createOptions.UploadDate");
if (createOptions.ContentType == null) throw new NullReferenceException("createOptions.ContentType");
return _mongoGridFS.Upload(stream, fileName, createOptions);
}
开发者ID:vmaron,项目名称:Arcnet.MongoDB.Framework,代码行数:10,代码来源:GridFS.cs
示例12: UploadImageToDish
public static MongoGridFSFileInfo UploadImageToDish(this Dish dishWithImages, MongoGridFS gridFS, System.IO.Stream fs, string imageName, string contentType)
{
log.DebugFormat("[UploadImageToDish] This RestaurantBasicData.Id={0}, MongoGridFS, imageName={1}, contentType={2}.", dishWithImages.Id, gridFS.ToString(), imageName, contentType);
MongoGridFSCreateOptions gridFSOption = new MongoGridFSCreateOptions();
gridFSOption.ContentType = contentType;
var gridFsInfo = gridFS.Upload(fs, imageName, gridFSOption);
ImageData convertedValue = ImageServices.ConvertToImageData(gridFsInfo);
dishWithImages.Image = convertedValue;
//dishWithImages.Images[0] = convertedValue;
var fileId = gridFsInfo.Id;
return gridFsInfo;
}
开发者ID:pashkov,项目名称:Spontaneous,代码行数:13,代码来源:ImageServices.cs
示例13: AttachImage
public ActionResult AttachImage(string id, HttpPostedFileBase file)
{
var rental = GetRental(id);
var imageId = ObjectId.GenerateNewId();
rental.ImageId = imageId.ToString();
Context.Rentals.Save(rental);
var options = new MongoGridFSCreateOptions
{
Id = imageId,
ContentType = file.ContentType
};
Context.Database.GridFS.Upload(file.InputStream, file.FileName);
return RedirectToAction("Index");
}
开发者ID:helmy204,项目名称:RealEstate,代码行数:14,代码来源:RentalsController.cs
示例14: MongoGridFSFileInfo
public MongoGridFSFileInfo(
MongoGridFS gridFS,
string remoteFileName,
MongoGridFSCreateOptions createOptions
)
{
this.gridFS = gridFS;
this.aliases = createOptions.Aliases;
this.chunkSize = createOptions.ChunkSize;
this.contentType = createOptions.ContentType;
this.id = createOptions.Id;
this.metadata = createOptions.Metadata;
this.name = remoteFileName;
this.uploadDate = createOptions.UploadDate;
this.cached = true; // prevent values from being overwritten by automatic Refresh
}
开发者ID:jenrom,项目名称:mongo-csharp-driver,代码行数:16,代码来源:MongoGridFSFileInfo.cs
示例15: UploadImageToRestaurant
public static MongoGridFSFileInfo UploadImageToRestaurant(this RestaurantBasicData rest, MongoGridFS gridFS, System.IO.Stream fs, string imageName, string contentType)
{
//resize picture 100 * 100
//save to profile
//on output implement logic of presentation - if we have image let's display it
//copy all images that we have on links to gridFS
//Upload images from backoffice.
log.DebugFormat("[UploadImageToRestaurant] This RestaurantBasicData.Id={0}, MongoGridFS, imageName={1}.", rest.Id, gridFS.ToString(), imageName);
MongoGridFSCreateOptions gridFSOption = new MongoGridFSCreateOptions();
gridFSOption.ContentType = contentType;
var gridFsInfo = gridFS.Upload(fs, imageName, gridFSOption);
ImageData convertedValue = ImageServices.ConvertToImageData(gridFsInfo);
rest.Image = convertedValue;
var fileId = gridFsInfo.Id;
return gridFsInfo;
}
开发者ID:vaduha,项目名称:Spontaneous,代码行数:18,代码来源:ImageServices.cs
示例16: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
MongoGridFS g = Config.Current.Plugins.Get<MongoReaderPlugin>().GridFS;
//Loop through each uploaded file
foreach (string fileKey in HttpContext.Current.Request.Files.Keys) {
HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
if (file.ContentLength <= 0) continue; //Skip unused file controls.
//Resize to a memory stream, max 2000x2000 jpeg
MemoryStream temp = new MemoryStream(4096);
new ImageJob(file.InputStream,temp,new ResizeSettings("width=2000;height=2000;mode=max;format=jpg")).Build();
//Reset the stream
temp.Seek(0, SeekOrigin.Begin);
MongoGridFSCreateOptions opts = new MongoGridFSCreateOptions();
opts.ContentType = file.ContentType;
MongoGridFSFileInfo fi = g.Upload(temp, Path.GetFileName(file.FileName), opts);
lit.Text += "<img src=\"" + ResolveUrl("~/gridfs/id/") + fi.Id + ".jpg?width=100&height=100\" />";
}
}
开发者ID:stukalin,项目名称:ImageResizer,代码行数:23,代码来源:Default.aspx.cs
示例17: 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();
}
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoGridFS.cs
示例18: Open
/// <summary>
/// Opens a GridFS file with the specified mode, access and create options.
/// </summary>
/// <param name="remoteFileName">The remote file name.</param>
/// <param name="mode">The mode.</param>
/// <param name="access">The access.</param>
/// <param name="createOptions">The create options.</param>
/// <returns>A stream.</returns>
public MongoGridFSStream Open(
string remoteFileName,
FileMode mode,
FileAccess access,
MongoGridFSCreateOptions createOptions
) {
var fileInfo = new MongoGridFSFileInfo(this, remoteFileName, createOptions);
return fileInfo.Open(mode, access);
}
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:17,代码来源:MongoGridFS.cs
示例19: 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
) {
var fileInfo = new MongoGridFSFileInfo(this, remoteFileName, createOptions);
return fileInfo.CreateText();
}
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoGridFS.cs
示例20: CopyTo
/// <summary>
/// Copies a GridFS file.
/// </summary>
/// <param name="sourceFileName">The source file name.</param>
/// <param name="destFileName">The destination file name.</param>
/// <param name="createOptions">The create options.</param>
/// <returns>The file info of the new GridFS file.</returns>
public MongoGridFSFileInfo CopyTo(
string sourceFileName,
string destFileName,
MongoGridFSCreateOptions createOptions
) {
var fileInfo = FindOne(sourceFileName);
if (fileInfo == null) {
var message = string.Format("GridFS file '{0}' not found.", sourceFileName);
throw new FileNotFoundException(message);
}
return fileInfo.CopyTo(destFileName, createOptions);
}
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:19,代码来源:MongoGridFS.cs
注:本文中的MongoDB.Driver.GridFS.MongoGridFSCreateOptions类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论