Example #1
0
        private void ProcessNextBatch(FileChunck batch)
        {
            if (batch == null)
            {
#pragma warning disable 618
                throw new Exception("missing - batch is null");//throw new GridFSChunkException(_idAsBsonValue, _nextChunkNumber, "missing");
#pragma warning restore
            }

            var previousBatch = _chunck;
            _chunck = batch;

            if (previousBatch != null)
            {
                _batchPosition += FileInfo.ChunkSize;
            }

            if (_chunck.N == _lastChunkNumber + 1 && _chunck.Data.Length == 0)
            {
                return;
            }

            var n     = _chunck.N;
            var bytes = _chunck.Data;

            if (n != _nextChunkNumber)
            {
#pragma warning disable 618
                throw new Exception($"missing the chunck {n} on file {FileInfo.Id}");//throw new GridFSChunkException(_idAsBsonValue, _nextChunkNumber, "missing");
#pragma warning restore
            }
            _nextChunkNumber++;

            var expectedChunkSize = n == _lastChunkNumber ? _lastChunkSize : FileInfo.ChunkSize;
            if (bytes.Length != expectedChunkSize)
            {
#pragma warning disable 618
                throw new Exception("the wrong size");//throw new GridFSChunkException(_idAsBsonValue, _nextChunkNumber, "the wrong size");
#pragma warning restore
            }

            if (_checkMD5)
            {
                _md5.AppendData(bytes, 0, bytes.Length);
            }
        }
Example #2
0
        private IEnumerable <FileChunck> CreateWriteBatchChunkDocuments()
        {
            var chunkDocuments = new List <FileChunck>();

            var n = (int)(_batchPosition / _chunkSizeBytes);

            foreach (var chunk in _batch)
            {
                var chunkDocument = new FileChunck
                {
                    Id      = Guid.NewGuid(),
                    FilesId = _id,
                    N       = n++,
                    Data    = chunk
                };
                chunkDocuments.Add(chunkDocument);

                _batchPosition += chunk.Length;
                //_md5.AppendData(chunk, 0, chunk.Length); //TODO CALCULATE THE MD5 or HASH
            }

            return(chunkDocuments);
        }