当前位置: 首页>>代码示例>>C#>>正文


C# MongoGridFS.EnsureIndexes方法代码示例

本文整理汇总了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);
        }
开发者ID:coolya,项目名称:mongo.GridFS-Import,代码行数:17,代码来源:Program.cs

示例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;
            }
        }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoGridFSStream.cs

示例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;
            }
        }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:36,代码来源:MongoGridFSStream.cs

示例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;
            }
        }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoGridFSStream.cs

示例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();
        }
开发者ID:simi--,项目名称:mongo-csharp-driver,代码行数:70,代码来源:MongoGridFSStream.cs


注:本文中的MongoDB.Driver.GridFS.MongoGridFS.EnsureIndexes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。