Пример #1
0
        /// <summary>
        /// Insert a new file content inside datafile in _files collection
        /// </summary>
        public LiteFileInfo Upload(LiteFileInfo file, Stream stream)
        {
            if (file == null) throw new ArgumentNullException("id");
            if (stream == null) throw new ArgumentNullException("stream");

            // no transaction allowed
            if (this.Database.Transaction.IsInTransaction) throw LiteException.InvalidTransaction();

            file.UploadDate = DateTime.Now;

            // insert file in _files collections with 0 file length
            this.Files.Insert(file.AsDocument);

            // for each chunk, insert as a chunk document
            foreach (var chunk in file.CreateChunks(stream))
            {
                this.Chunks.Insert(chunk);

                // clear extend pages in cache to avoid too many use of memory in big files
                this.Database.Cache.RemoveExtendPages();
            }

            // update fileLength to confirm full file length stored in disk
            this.Files.Update(file.AsDocument);

            return file;
        }
Пример #2
0
        /// <summary>
        /// Insert a new file content inside datafile in _files collection
        /// </summary>
        public LiteFileInfo Upload(LiteFileInfo file, Stream stream)
        {
            if (file == null)
            {
                throw new ArgumentNullException("id");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            file.UploadDate = DateTime.Now;

            // insert file in _files collections with 0 file length
            _engine.Insert(FILES, new BsonDocument[] { file.AsDocument });

            // for each chunk, insert as a chunk document
            foreach (var chunk in file.CreateChunks(stream))
            {
                _engine.Insert(CHUNKS, new BsonDocument[] { chunk });
            }

            // update fileLength/chunks to confirm full file length stored in disk
            _engine.Update(FILES, new BsonDocument[] { file.AsDocument });

            return(file);
        }
Пример #3
0
        /// <summary>
        /// Insert a new file content inside datafile in _files collection
        /// </summary>
        public LiteFileInfo Upload(LiteFileInfo file, Stream stream)
        {
            if (file == null) throw new ArgumentNullException("id");
            if (stream == null) throw new ArgumentNullException("stream");

            file.UploadDate = DateTime.Now;

            // insert file in _files collections with 0 file length
            _engine.Insert(FILES, new BsonDocument[] { file.AsDocument });

            // for each chunk, insert as a chunk document
            foreach (var chunk in file.CreateChunks(stream))
            {
                _engine.Insert(CHUNKS, new BsonDocument[] { chunk });
            }

            // update fileLength/chunks to confirm full file length stored in disk
            _engine.Update(FILES, new BsonDocument[] { file.AsDocument });

            return file;
        }
Пример #4
0
        /// <summary>
        /// Insert a new file content inside datafile in _files collection
        /// </summary>
        public LiteFileInfo Upload(LiteFileInfo file, Stream stream)
        {
            if (file == null)
            {
                throw new ArgumentNullException("id");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // no transaction allowed
            if (this.Database.Transaction.IsInTransaction)
            {
                throw LiteException.InvalidTransaction();
            }

            file.UploadDate = DateTime.Now;

            // insert file in _files collections with 0 file length
            this.Files.Insert(file.AsDocument);

            // for each chunk, insert as a chunk document
            foreach (var chunk in file.CreateChunks(stream))
            {
                this.Chunks.Insert(chunk);

                // clear extend pages in cache to avoid too many use of memory in big files
                this.Database.Cache.RemoveExtendPages();
            }

            // update fileLength to confirm full file length stored in disk
            this.Files.Update(file.AsDocument);

            return(file);
        }