2022-05-20 03:23:16 +00:00
|
|
|
using System;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2022-05-16 22:14:52 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using ReactiveUI;
|
|
|
|
using Wabbajack.DTOs.Interventions;
|
2022-05-20 03:23:16 +00:00
|
|
|
using Wabbajack.UserIntervention;
|
2022-05-16 22:14:52 +00:00
|
|
|
|
|
|
|
namespace Wabbajack.Interventions;
|
|
|
|
|
2022-05-20 03:23:16 +00:00
|
|
|
public class UserInteventionHandler : IUserInterventionHandler
|
2022-05-16 22:14:52 +00:00
|
|
|
{
|
2022-05-20 03:23:16 +00:00
|
|
|
private readonly ILogger<UserInteventionHandler> _logger;
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
2022-05-16 22:14:52 +00:00
|
|
|
|
2022-05-20 03:23:16 +00:00
|
|
|
public UserInteventionHandler(ILogger<UserInteventionHandler> logger, IServiceProvider serviceProvider)
|
2022-05-16 22:14:52 +00:00
|
|
|
{
|
|
|
|
_logger = logger;
|
2022-05-20 03:23:16 +00:00
|
|
|
_serviceProvider = serviceProvider;
|
2022-05-16 22:14:52 +00:00
|
|
|
}
|
|
|
|
public void Raise(IUserIntervention intervention)
|
|
|
|
{
|
2022-05-19 03:21:38 +00:00
|
|
|
switch (intervention)
|
|
|
|
{
|
|
|
|
// Recast these or they won't be properly handled by the message bus
|
|
|
|
case ManualDownload md:
|
2022-05-20 03:23:16 +00:00
|
|
|
var view = new BrowserWindow();
|
|
|
|
var provider = _serviceProvider.GetRequiredService<ManualDownloadHandler>();
|
|
|
|
view.DataContext = provider;
|
|
|
|
provider.Intervention = md;
|
|
|
|
view.Show();
|
2022-05-19 03:21:38 +00:00
|
|
|
break;
|
|
|
|
case ManualBlobDownload bd:
|
|
|
|
MessageBus.Current.SendMessage(bd);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_logger.LogError("No handler for user intervention: {Type}", intervention);
|
|
|
|
break;
|
|
|
|
}
|
2022-05-16 22:14:52 +00:00
|
|
|
}
|
|
|
|
}
|