This commit is contained in:
Timothy Baldridge 2021-10-11 23:19:13 -06:00
parent 6e52318dbb
commit 92240aab49
9 changed files with 78 additions and 22 deletions

View File

@ -5,13 +5,18 @@
xmlns:controls="clr-namespace:Wabbajack.App.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.LogView">
<Border>
<ListBox x:Name="Messages">
<ListBox.ItemTemplate>
<ScrollViewer ScrollChanged="ScrollViewer_OnScrollChanged" x:Name="ScrollViewer">
<ItemsControl x:Name="Messages">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:LogViewItem></controls:LogViewItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</UserControl>

View File

@ -1,3 +1,4 @@
using Avalonia.Controls;
using Avalonia.Controls.Mixins;
using Avalonia.ReactiveUI;
using Microsoft.Extensions.DependencyInjection;
@ -19,4 +20,8 @@ public partial class LogView : ReactiveUserControl<LogViewModel>
});
}
private void ScrollViewer_OnScrollChanged(object? sender, ScrollChangedEventArgs e)
{
ScrollViewer.ScrollToEnd();
}
}

View File

@ -4,5 +4,5 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.LogViewItem">
<TextBlock x:Name="Message"></TextBlock>
<TextBlock x:Name="Message" FontSize="10"></TextBlock>
</UserControl>

View File

@ -1,9 +1,12 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using Wabbajack.App.Messages;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.Compiler;
namespace Wabbajack.App.Screens;
@ -12,9 +15,11 @@ public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<St
{
private readonly IServiceProvider _provider;
private ACompiler _compiler;
private readonly ILogger<CompilationViewModel> _logger;
public CompilationViewModel(IServiceProvider provider)
public CompilationViewModel(ILogger<CompilationViewModel> logger, IServiceProvider provider)
{
_logger = logger;
_provider = provider;
Activator = new ViewModelActivator();
@ -29,7 +34,18 @@ public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<St
_compiler = compiler;
}
Compile().FireAndForget();
}
_compiler.Begin(CancellationToken.None);
public async Task Compile()
{
try
{
await _compiler.Begin(CancellationToken.None);
}
catch (Exception ex)
{
_logger.LogError(ex, "During Compilation: {Message}", ex.Message);
}
}
}

View File

@ -1,6 +1,12 @@
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Wabbajack.DTOs.Logins;
using Wabbajack.Networking.Http;
using Wabbajack.RateLimiter;
namespace Wabbajack.Common
{
@ -18,5 +24,16 @@ namespace Wabbajack.Common
return msg;
}
public static async Task<TValue?> GetFromJsonAsync<TValue>(this HttpClient client, IResource<HttpClient> limiter, HttpRequestMessage msg,
JsonSerializerOptions? options, CancellationToken cancellationToken = default)
{
using var job = await limiter.Begin($"HTTP Get JSON {msg.RequestUri}", 0, cancellationToken);
using var response = await client.SendAsync(msg, cancellationToken);
if (!response.IsSuccessStatusCode)
throw new HttpException(response);
await job.Report((int)response.Content.Headers.ContentLength!, cancellationToken);
return await response.Content.ReadFromJsonAsync<TValue>(options, cancellationToken);
}
}
}

View File

@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\Wabbajack.DTOs\Wabbajack.DTOs.csproj" />
<ProjectReference Include="..\Wabbajack.Networking.Http\Wabbajack.Networking.Http.csproj" />
<ProjectReference Include="..\Wabbajack.Paths.IO\Wabbajack.Paths.IO.csproj" />
</ItemGroup>

View File

@ -280,7 +280,7 @@ namespace Wabbajack.Compiler
_logger.LogInformation("Attempting to infer {count} metas from the server.", toFind.Count);
await toFind.PDo(_parallelOptions, async f =>
await toFind.PDoAll(async f =>
{
var vf = _vfs.Index.ByRootPath[f];

View File

@ -437,7 +437,7 @@ namespace Wabbajack.Installer
var existingfiles = _configuration.Install.EnumerateFiles().ToHashSet();
NextStep("Optimizing Modlist: Removing redundant directives", indexed.Count);
await indexed.Values.PMap<Directive, Directive?>(_parallelOptions, async d =>
await indexed.Values.PMapAll<Directive, Directive?>(async d =>
{
UpdateProgress(1);
// Bit backwards, but we want to return null for

View File

@ -11,12 +11,15 @@ using Wabbajack.Common;
using Wabbajack.DTOs;
using Wabbajack.DTOs.CDN;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.DTOs.Logins;
using Wabbajack.DTOs.ModListValidation;
using Wabbajack.DTOs.ServerResponses;
using Wabbajack.DTOs.Validation;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Networking.Http.Interfaces;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
@ -28,27 +31,35 @@ namespace Wabbajack.Networking.WabbajackClientApi
private readonly HttpClient _client;
private readonly Configuration _configuration;
private readonly ITokenProvider<WabbajackApiState> _token;
private readonly ILogger<Client> _logger;
private readonly DTOSerializer _dtos;
private readonly ParallelOptions _parallelOptions;
private readonly IResource<HttpClient> _limiter;
private readonly Configuration _configuration;
public Client(ILogger<Client> logger, HttpClient client, Configuration configuration, DTOSerializer dtos, ParallelOptions parallelOptions)
public Client(ILogger<Client> logger, HttpClient client, ITokenProvider<WabbajackApiState> token, DTOSerializer dtos, IResource<HttpClient> limiter, Configuration configuration)
{
_configuration = configuration;
_token = token;
_client = client;
_logger = logger;
_logger.LogInformation("File hash check (-42) {key}", _configuration.MetricsKey);
_dtos = dtos;
_parallelOptions = parallelOptions;
_limiter = limiter;
}
private async ValueTask<HttpRequestMessage> MakeMessage(HttpMethod method, Uri uri)
{
var msg = new HttpRequestMessage(method, uri);
var key = (await _token.Get())!;
msg.Headers.Add(_configuration.MetricsKeyHeader, key.MetricsKey);
return msg;
}
public async Task SendMetric(string action, string subject)
{
var msg = new HttpRequestMessage(HttpMethod.Get,
$"{_configuration.BuildServerUrl}metrics/{action}/{subject}");
msg.Headers.Add(_configuration.MetricsKeyHeader, _configuration.MetricsKey);
var msg = await MakeMessage(HttpMethod.Get, new Uri($"{_configuration.BuildServerUrl}metrics/{action}/{subject}"));
await _client.SendAsync(msg);
}
@ -83,8 +94,9 @@ namespace Wabbajack.Networking.WabbajackClientApi
public async Task<Archive[]> GetArchivesForHash(Hash hash)
{
return await _client.GetFromJsonAsync<Archive[]>(
$"{_configuration.BuildServerUrl}mod_files/by_hash/{hash.ToHex()}", _dtos.Options) ?? Array.Empty<Archive>();
var msg = await MakeMessage(HttpMethod.Get,
new Uri($"{_configuration.BuildServerUrl}mod_files/by_hash/{hash.ToHex()}"));
return await _client.GetFromJsonAsync<Archive[]>(_limiter, msg, _dtos.Options) ?? Array.Empty<Archive>();
}
public async Task<Uri?> GetMirrorUrl(Hash archiveHash)
@ -175,7 +187,7 @@ namespace Wabbajack.Networking.WabbajackClientApi
"https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/unlisted_modlists.json"})
.Take(includeUnlisted ? 3 : 2);
return await lists.PMap(_parallelOptions, async url => await _client.GetFromJsonAsync<ModlistMetadata[]>(url, _dtos.Options)!)
return await lists.PMapAll(async url => await _client.GetFromJsonAsync<ModlistMetadata[]>(_limiter, new HttpRequestMessage(HttpMethod.Get, url), _dtos.Options)!)
.SelectMany(x => x)
.ToArray();