本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFSCreateOptions类的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFSCreateOptions类的具体用法?C# MongoGridFSCreateOptions怎么用?C# MongoGridFSCreateOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoGridFSCreateOptions类属于MongoDB.Driver.GridFS命名空间,在下文中一共展示了MongoGridFSCreateOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
示例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: 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);
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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");
}
示例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
}
示例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;
}