當前位置: 首頁>>代碼示例>>C#>>正文


C# GridFS.MongoGridFSCreateOptions類代碼示例

本文整理匯總了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());
        }
開發者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


注:本文中的MongoDB.Driver.GridFS.MongoGridFSCreateOptions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。