namespace EEMSCenter.Hubs; internal partial class ClientsHub : HubBase { private static ConcurrentDictionary Streams { get; } = []; public Task FilePack(Guid guid, byte[] buffer, int current, int total) { if (!Streams.TryGetValue(guid, out MemoryStream? stream) || stream is null) { if (current != 1) return Task.FromResult(false); stream = new(); Streams[guid] = stream; Timer timer = new(FileCleanerTimerCallback, guid, 600000, Timeout.Infinite); } stream.Write(buffer); if (current != total) return Task.FromResult(true); if (!Compressor.DecompressZipFile(Environment.CurrentDirectory, stream)) return Task.FromResult(false); if (Streams.TryRemove(guid, out MemoryStream? memoryStream) && memoryStream is not null) memoryStream.Dispose(); return Task.FromResult(true); } private void FileCleanerTimerCallback(object? state) { if (state is not Guid guid) return; if (Streams.TryRemove(guid, out MemoryStream? memoryStream) && memoryStream is not null) memoryStream.Dispose(); } }