| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- namespace EEMSCenter.Hubs;
- internal partial class ClientsHub : HubBase
- {
- private static ConcurrentDictionary<Guid, MemoryStream> Streams { get; } = [];
- public Task<bool> 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();
- }
- }
|