Bind import UI events
This commit is contained in:
parent
09eae10935
commit
2ddcd75c19
2 changed files with 29 additions and 13 deletions
|
|
@ -39,6 +39,8 @@ namespace LANCommander.Launcher.Services
|
|||
{
|
||||
try
|
||||
{
|
||||
OnImportStarted?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
await ImportLibraryAsync();
|
||||
|
||||
OnImportComplete?.Invoke(this, EventArgs.Empty);
|
||||
|
|
@ -54,6 +56,8 @@ namespace LANCommander.Launcher.Services
|
|||
var remoteLibrary = await libraryClient.GetAsync();
|
||||
|
||||
Logger?.LogInformation("Starting library import");
|
||||
|
||||
OnImportStarted?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
var importContext = importContextFactory.Create();
|
||||
|
||||
|
|
@ -70,10 +74,14 @@ namespace LANCommander.Launcher.Services
|
|||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogError(ex, "Could not add game with ID {GameId} to import queue", game.Id);
|
||||
|
||||
OnImportError?.Invoke(this, ex);
|
||||
}
|
||||
}
|
||||
|
||||
await importContext.ImportQueueAsync();
|
||||
|
||||
OnImportComplete?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public async Task ImportGameAsync(Guid gameId)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
@using LANCommander.Launcher.Models
|
||||
@using LANCommander.Launcher.Services.Import
|
||||
@implements IDisposable
|
||||
@inject ImportManagerService ImportManagerService
|
||||
|
|
@ -30,9 +29,10 @@
|
|||
if (ImportService != null)
|
||||
{
|
||||
// Clear any existing handlers
|
||||
//ImportService.OnImportComplete -= OnImportCompleteHandler;
|
||||
//ImportService.OnImportFailed -= OnImportFailedHandler;
|
||||
//ImportService.OnImportUpdated -= OnImportUpdatedHandler;
|
||||
ImportService.OnImportStarted -= ImportStarted;
|
||||
ImportService.OnImportComplete -= OnImportComplete;
|
||||
ImportService.OnImportError -= OnImportFailed;
|
||||
ImportService.OnImportStatusUpdate -= OnImportStatusUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,14 +43,17 @@
|
|||
Logger?.LogInformation("Starting import process");
|
||||
|
||||
// Clear any existing handlers
|
||||
//ImportService.OnImportComplete -= OnImportCompleteHandler;
|
||||
//ImportService.OnImportFailed -= OnImportFailedHandler;
|
||||
//ImportService.OnImportUpdated -= OnImportUpdatedHandler;
|
||||
ImportService.OnImportStarted -= ImportStarted;
|
||||
ImportService.OnImportComplete -= OnImportComplete;
|
||||
ImportService.OnImportError -= OnImportFailed;
|
||||
ImportService.OnImportStatusUpdate -= OnImportStatusUpdate;
|
||||
|
||||
// Add our handlers
|
||||
//ImportService.OnImportComplete += OnImportCompleteHandler;
|
||||
//ImportService.OnImportFailed += OnImportFailedHandler;
|
||||
//ImportService.OnImportUpdated += OnImportUpdatedHandler;
|
||||
ImportService.OnImportStarted += ImportStarted;
|
||||
ImportService.OnImportComplete += OnImportComplete;
|
||||
ImportService.OnImportError += OnImportFailed;
|
||||
ImportService.OnImportStatusUpdate += OnImportStatusUpdate;
|
||||
|
||||
|
||||
// Now start the import process
|
||||
Importing = true;
|
||||
|
|
@ -80,8 +83,13 @@
|
|||
Total = ImportStatusTotal,
|
||||
});
|
||||
}
|
||||
|
||||
private void ImportStarted(object? sender, EventArgs e)
|
||||
{
|
||||
NotifyProgress(ImportProgressState.Importing);
|
||||
}
|
||||
|
||||
private async Task OnImportCompleteHandler()
|
||||
private async void OnImportComplete(object? sender, EventArgs e)
|
||||
{
|
||||
Logger?.LogInformation("Import Complete handler called");
|
||||
Importing = false;
|
||||
|
|
@ -92,7 +100,7 @@
|
|||
MessageService.Success(LocalizationService.GetString("ImportComplete"), 3);
|
||||
}
|
||||
|
||||
private async Task OnImportFailedHandler(Exception ex)
|
||||
private async void OnImportFailed(object? sender, Exception? ex)
|
||||
{
|
||||
Importing = false;
|
||||
ImportStatusIndex = 0;
|
||||
|
|
@ -102,7 +110,7 @@
|
|||
MessageService.Error(LocalizationService.GetString("ImportFailed"), 3);
|
||||
}
|
||||
|
||||
private async Task OnImportUpdatedHandler(ImportStatusUpdate status)
|
||||
private async void OnImportStatusUpdate(object? sender, ImportStatusUpdate? status)
|
||||
{
|
||||
Logger?.LogInformation("Import Update handler called: {Index}/{Total}", status.Index, status.Total);
|
||||
ImportStatusIndex = status.Index;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue