/// <summary>
        /// Delete a file inside datafile and all metadata related
        /// </summary>
        public bool Delete(string id)
        {
            if (id.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("id");
            }

            // remove file reference in _files
            var deleted = _engine.Delete(FILES, id);

            // if not found, just return false
            if (!deleted)
            {
                return(false);
            }

            // delete all files chunks based on _id string
            var index = 0;

            // delete one-by-one to avoid all pages files dirty in memory
            while (deleted)
            {
                deleted = _engine.Delete(CHUNKS, LiteFileStream.GetChunckId(id, index++)); // index zero based
            }

            return(true);
        }
Example #2
0
        public bool RemoveById(string _id)
        {
            if (!Opened)
            {
                return(false);
            }
            var result = _engine.Delete(_LITEDB_CONST.COLLECTION_NAME, new BsonValue(new ObjectId(_id)));

            return(result);
        }
Example #3
0
        internal LiteFileStream(LiteEngine engine, LiteFileInfo file, FileAccess mode)
        {
            _engine = engine;
            _file   = file;
            _mode   = mode;

            if (mode == FileAccess.Read)
            {
                // initialize first data block
                _currentChunkData = this.GetChunkData(_currentChunkIndex);
            }
            else if (mode == FileAccess.Write)
            {
                _buffer = new MemoryStream(MAX_CHUNK_SIZE);

                // delete chunks content if needed
                if (file.Length > 0)
                {
                    _engine.Delete(LiteStorage.CHUNKS, Query.StartsWith("_id", _file.Id + "\\"));
                }

                // clear size counters
                file.Length = 0;
                file.Chunks = 0;
            }
        }
Example #4
0
        internal LiteFileStream(LiteEngine engine, LiteFileInfo file, FileAccess mode)
        {
            _engine = engine;
            _file = file;
            _mode = mode;

            if(mode == FileAccess.Read)
            {
                // initialize first data block
                _currentChunkData = this.GetChunkData(_currentChunkIndex);
            }
            else if(mode == FileAccess.Write)
            {
                _buffer = new MemoryStream(MAX_CHUNK_SIZE);

                // delete chunks content if needed
                if (file.Length > 0)
                {
                    _engine.Delete(LiteStorage.CHUNKS, Query.StartsWith("_id", _file.Id + "\\"));
                }

                // clear size counters
                file.Length = 0;
                file.Chunks = 0;
            }
        }
        internal LiteFileStream(LiteEngine engine, LiteFileInfo file, FileAccess mode)
        {
            _engine = engine;
            _file   = file;
            _mode   = mode;

            if (mode == FileAccess.Read)
            {
                // initialize first data block
                _currentChunkData = this.GetChunkData(_currentChunkIndex);
            }
            else if (mode == FileAccess.Write)
            {
                _buffer = new MemoryStream(MAX_CHUNK_SIZE);

                // delete chunks content if needed
                if (file.Length > 0)
                {
                    var index   = 0;
                    var deleted = true;

                    // delete one-by-one to avoid all pages files dirty in memory
                    while (deleted)
                    {
                        deleted = _engine.Delete(LiteStorage.CHUNKS, LiteFileStream.GetChunckId(_file.Id, index++)); // index zero based
                    }
                }

                // clear size counters
                file.Length = 0;
                file.Chunks = 0;
            }
        }
Example #6
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);
            }

            // delete all files content based on _id string
            _engine.Delete(LiteStorage.CHUNKS, Query.StartsWith("_id", id + "\\"));

            return(true);
        }
Example #7
0
        public int Delete(string collection, IEnumerable <BsonValue> ids)
        {
            this.OpenDatabase();

            try
            {
                return(_engine.Delete(collection, ids));
            }
            finally
            {
                this.CloseDatabase();
            }
        }