This refactor splits the import and export functionality out of the ImportContext and adds an ExportContext. This also introduced separate importer and exporter implementations. Additionally, adding archive, save, scripts, and server files to the final export archive has been implemented at the exporter implementation for each instead of handling it in the context. This should be a good pattern if other files need to be added down the road.
40 lines
No EOL
939 B
C#
40 lines
No EOL
939 B
C#
using LANCommander.Server.ImportExport.Importers;
|
|
|
|
namespace LANCommander.Server.ImportExport.Services;
|
|
|
|
public class ExportService : IDisposable
|
|
{
|
|
private Dictionary<Guid, ExportContext> ExportContexts = new();
|
|
|
|
public Guid EnqueueContext(ExportContext context)
|
|
{
|
|
var id = Guid.NewGuid();
|
|
|
|
ExportContexts.Add(id, context);
|
|
|
|
return id;
|
|
}
|
|
|
|
public ExportContext GetContext(Guid id)
|
|
{
|
|
if (ExportContexts.TryGetValue(id, out var context))
|
|
return context;
|
|
|
|
return null;
|
|
}
|
|
|
|
public async Task ExportAsync(Guid contextId, Stream outputStream)
|
|
{
|
|
if (ExportContexts.TryGetValue(contextId, out var context))
|
|
{
|
|
await context.ExportQueueAsync(outputStream);
|
|
|
|
ExportContexts.Remove(contextId);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// TODO release managed resources here
|
|
}
|
|
} |