private Chunk RegisterChunk(int Start, int Length, int Id = 0)
        {
            if (Id == 0)
            {
                Id = GetNewChunkID();
            }
            Chunk NewChunk = new Chunk(Start, Length, 0, Id);

            EmptyChunks.Add(NewChunk.Id, NewChunk);
            EmptyChunksStart.Add(NewChunk.Start, NewChunk);
            EmptyChunksLength.Add(NewChunk.Length, NewChunk);
            return(NewChunk);
        }
        public void MarkChunkAsEmpty(int ChunkId, int FileId)
        {
            Logger.Debug($"M: MARK CHUNK {ChunkId} AS NOT WRITTEN BY {FileId}");
            Chunk Chunk = GetChunkByIdInternal(ChunkId);

            Chunk.SetNotWritten();
            if (!(Files.ContainsKey(FileId)))
            {
                throw new FileNotFoundException($"File {FileId} not found in Metadata");
            }
            Files[FileId].DeleteChunk(ChunkId);
            if (!(Chunk.IsWritten()))
            {
                if (WrittenChunks.ContainsKey(Chunk.Id))
                {
                    WrittenChunks.Remove(Chunk.Id);
                }
                try
                {
                    Chunk PreChunk = GetChunkBeforIfEmpty(Chunk);
                    Chunk = CombineChunks(PreChunk, Chunk);
                }
                catch (ChunkNotFoundException)
                {
                }
                try
                {
                    Chunk AfterChunk = GetChunkAfterIfEmpty(Chunk);
                    Chunk = CombineChunks(Chunk, AfterChunk);
                }
                catch (ChunkNotFoundException)
                {
                }
                if (!(EmptyChunks.ContainsKey(Chunk.Id)))
                {
                    EmptyChunks.Add(Chunk.Id, Chunk);
                    EmptyChunksStart.Add(Chunk.Start, Chunk);
                    EmptyChunksLength.Add(Chunk.Length, Chunk);
                }
            }
        }