示例#1
0
        private void OpenCreate()
        {
            _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
            };

            _gridFS.Files.Insert(file);
            _length   = 0;
            _position = 0;
        }
        private void OpenCreate()
        {
            if (fileInfo.Id == null)
            {
                fileInfo.SetId(ObjectId.GenerateNewId());
            }
            else
            {
                throw new InvalidOperationException("OpenCreate called and FileInfo.Id already has a value");
            }

            var file = new BsonDocument {
                { "_id", fileInfo.Id },
                { "filename", fileInfo.Name },
                { "length", 0 },
                { "chunkSize", fileInfo.ChunkSize },
                { "uploadDate", fileInfo.UploadDate },
                { "contentType", fileInfo.ContentType, !string.IsNullOrEmpty(fileInfo.ContentType) }, // optional
                { "aliases", BsonArray.Create((IEnumerable <string>)fileInfo.Aliases), fileInfo.Aliases != null && fileInfo.Aliases.Length > 0 } // optional
            };

            gridFS.Files.Insert(file);
            length   = 0;
            position = 0;
        }
示例#3
0
        private void OpenCreate()
        {
            if (fileInfo.Id == null)
            {
                fileInfo.SetId(ObjectId.GenerateNewId());
            }

            var file = new BsonDocument {
                { "_id", fileInfo.Id },
                { "filename", 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", BsonArray.Create(fileInfo.Aliases), fileInfo.Aliases != null && fileInfo.Aliases.Length > 0 }, // optional
                { "metadata", fileInfo.Metadata } // optional
            };

            gridFS.Files.Insert(file);
            length   = 0;
            position = 0;
        }
        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;
            }
        }