2022-05-20 03:23:16 +00:00
|
|
|
using System;
|
2022-05-20 04:12:16 +00:00
|
|
|
using System.Reactive.Disposables;
|
|
|
|
using System.Windows.Threading;
|
2022-05-20 03:23:16 +00:00
|
|
|
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 04:12:16 +00:00
|
|
|
using Wabbajack.Messages;
|
2022-05-20 03:23:16 +00:00
|
|
|
using Wabbajack.UserIntervention;
|
2022-05-16 22:14:52 +00:00
|
|
|
|
|
|
|
namespace Wabbajack.Interventions;
|
|
|
|
|
2022-05-21 21:11:43 +00:00
|
|
|
public class UserIntreventionHandler : IUserInterventionHandler
|
2022-05-16 22:14:52 +00:00
|
|
|
{
|
2022-05-21 21:11:43 +00:00
|
|
|
private readonly ILogger<UserIntreventionHandler> _logger;
|
2022-05-20 03:23:16 +00:00
|
|
|
private readonly IServiceProvider _serviceProvider;
|
2022-05-16 22:14:52 +00:00
|
|
|
|
2022-05-21 21:11:43 +00:00
|
|
|
public UserIntreventionHandler(ILogger<UserIntreventionHandler> 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 04:12:16 +00:00
|
|
|
{
|
2022-05-20 03:23:16 +00:00
|
|
|
var provider = _serviceProvider.GetRequiredService<ManualDownloadHandler>();
|
|
|
|
provider.Intervention = md;
|
2022-05-20 04:12:16 +00:00
|
|
|
MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
|
2022-05-19 03:21:38 +00:00
|
|
|
break;
|
2022-05-20 04:12:16 +00:00
|
|
|
}
|
2022-05-19 03:21:38 +00:00
|
|
|
case ManualBlobDownload bd:
|
2022-05-20 04:12:16 +00:00
|
|
|
{
|
|
|
|
var provider = _serviceProvider.GetRequiredService<ManualBlobDownloadHandler>();
|
|
|
|
provider.Intervention = bd;
|
|
|
|
MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
|
2022-05-19 03:21:38 +00:00
|
|
|
break;
|
2022-05-20 04:12:16 +00:00
|
|
|
}
|
2022-05-19 03:21:38 +00:00
|
|
|
default:
|
|
|
|
_logger.LogError("No handler for user intervention: {Type}", intervention);
|
|
|
|
break;
|
2022-05-20 04:12:16 +00:00
|
|
|
|
2022-05-19 03:21:38 +00:00
|
|
|
}
|
2022-05-20 04:12:16 +00:00
|
|
|
|
2022-05-16 22:14:52 +00:00
|
|
|
}
|
|
|
|
}
|