wabbajack/Wabbajack.App/Screens/CompilationViewModel.cs

51 lines
1.3 KiB
C#
Raw Normal View History

using System;
using System.Threading;
2021-10-12 05:19:13 +00:00
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
2021-10-12 05:19:13 +00:00
using Microsoft.Extensions.Logging;
using ReactiveUI;
using Wabbajack.App.Messages;
using Wabbajack.App.ViewModels;
2021-10-12 05:19:13 +00:00
using Wabbajack.Common;
using Wabbajack.Compiler;
namespace Wabbajack.App.Screens;
public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<StartCompilation>
{
private readonly IServiceProvider _provider;
private ACompiler _compiler;
2021-10-12 05:19:13 +00:00
private readonly ILogger<CompilationViewModel> _logger;
2021-10-12 05:19:13 +00:00
public CompilationViewModel(ILogger<CompilationViewModel> logger, IServiceProvider provider)
{
2021-10-12 05:19:13 +00:00
_logger = logger;
_provider = provider;
Activator = new ViewModelActivator();
}
public void Receive(StartCompilation val)
{
if (val.Settings is MO2CompilerSettings mo2)
{
var compiler = _provider.GetService<MO2Compiler>()!;
compiler.Settings = mo2;
_compiler = compiler;
}
2021-10-12 05:19:13 +00:00
Compile().FireAndForget();
}
2021-10-12 05:19:13 +00:00
public async Task Compile()
{
try
{
await _compiler.Begin(CancellationToken.None);
}
catch (Exception ex)
{
_logger.LogError(ex, "During Compilation: {Message}", ex.Message);
}
}
}