2025-12-03 18:32:27 -06:00
|
|
|
using LANCommander.SDK;
|
2025-12-03 02:22:37 -06:00
|
|
|
using LANCommander.Server.ImportExport.Models;
|
2025-04-12 20:05:32 -05:00
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
namespace LANCommander.Server.ImportExport.Services;
|
2025-04-12 20:05:32 -05:00
|
|
|
|
2025-07-25 17:57:33 -05:00
|
|
|
public class ImportService : IDisposable
|
2025-04-12 20:05:32 -05:00
|
|
|
{
|
2025-12-03 18:32:27 -06:00
|
|
|
public AsyncEventHandler<ImportStatusUpdate> OnImportStarted = new();
|
|
|
|
|
public AsyncEventHandler<ImportStatusUpdate> OnImportComplete = new();
|
|
|
|
|
public AsyncEventHandler<ImportStatusUpdate> OnImportStatusUpdate = new();
|
|
|
|
|
public AsyncEventHandler<ImportStatusUpdate> OnImportError = new();
|
2025-12-03 02:22:37 -06:00
|
|
|
|
|
|
|
|
private Dictionary<Guid, ImportContext> _importContexts = new();
|
2025-04-12 20:05:32 -05:00
|
|
|
|
2025-12-03 02:22:37 -06:00
|
|
|
public Guid AddContext(ImportContext context)
|
2025-04-12 20:05:32 -05:00
|
|
|
{
|
2025-07-25 17:57:33 -05:00
|
|
|
var id = Guid.NewGuid();
|
2025-04-12 20:05:32 -05:00
|
|
|
|
2025-12-03 02:22:37 -06:00
|
|
|
context.SetId(id);
|
|
|
|
|
|
|
|
|
|
_importContexts.Add(id, context);
|
|
|
|
|
|
2025-12-03 18:32:27 -06:00
|
|
|
context.OnImportStarted = OnImportStarted;
|
|
|
|
|
context.OnImportComplete = OnImportComplete;
|
|
|
|
|
context.OnImportStatusUpdate = OnImportStatusUpdate;
|
|
|
|
|
context.OnImportError = OnImportError;
|
2025-07-25 17:57:33 -05:00
|
|
|
|
|
|
|
|
return id;
|
2025-04-12 20:05:32 -05:00
|
|
|
}
|
|
|
|
|
|
2025-12-03 02:22:37 -06:00
|
|
|
public void RemoveContext(Guid id)
|
|
|
|
|
{
|
|
|
|
|
_importContexts.Remove(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ImportContext> GetContexts()
|
|
|
|
|
{
|
|
|
|
|
return _importContexts.Values;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:57:33 -05:00
|
|
|
public ImportContext GetContext(Guid id)
|
2025-04-12 20:05:32 -05:00
|
|
|
{
|
2025-12-03 02:22:37 -06:00
|
|
|
if (_importContexts.TryGetValue(id, out var context))
|
2025-07-25 17:57:33 -05:00
|
|
|
return context;
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-12 20:05:32 -05:00
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
// TODO release managed resources here
|
|
|
|
|
}
|
|
|
|
|
}
|