Пример #1
0
        /// <summary>
        /// Delete a file inside datafile and all metadata related
        /// </summary>
        public bool Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            // remove file reference in _files
            var d = _engine.Delete(FILES, Query.EQ("_id", id));

            // if not found, just return false
            if (d == 0)
            {
                return(false);
            }

            var index = 0;

            while (true)
            {
                var del = _engine.Delete(CHUNKS, Query.EQ("_id", LiteFileInfo.GetChunckId(id, index++)));

                if (del == 0)
                {
                    break;
                }
            }

            return(true);
        }
        private byte[] GetChunkData(int index)
        {
            // check if there is no more chunks in this file
            var chunk = _engine
                        .Find(LiteFileStorage.CHUNKS, Query.EQ("_id", LiteFileInfo.GetChunckId(FileInfo.Id, index)))
                        .FirstOrDefault();

            // if chunk is null there is no more chunks
            return(chunk == null ? null : chunk["data"].AsBinary);
        }
Пример #3
0
        private byte[] GetChunkData(int index)
        {
            // avoid too many extend pages on memory
            _db.Cache.RemoveExtendPages();

            // check if there is no more chunks in this file
            var chunks = _db.GetCollection("_chunks");

            var chunk = chunks.FindById(LiteFileInfo.GetChunckId(_file.Id, index));

            // if chunk is null there is no more chunks
            return(chunk == null ? null : chunk["data"].AsBinary);
        }
Пример #4
0
        /// <summary>
        /// Delete a file inside datafile and all metadata related
        /// </summary>
        public bool Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            if (this.Database.Transaction.IsInTransaction)
            {
                throw LiteException.InvalidTransaction();
            }

            // remove file reference in _files
            var d = this.Files.Delete(id);

            // if not found, just return false
            if (d == false)
            {
                return(false);
            }

            var index = 0;

            while (true)
            {
                var del = Chunks.Delete(LiteFileInfo.GetChunckId(id, index++));

                this.Database.Cache.RemoveExtendPages();

                if (del == false)
                {
                    break;
                }
            }

            return(true);
        }