Skip to content

Commit

Permalink
Fixed Blazor
Browse files Browse the repository at this point in the history
Fixed dotnet format
  • Loading branch information
Aragas committed May 12, 2023
1 parent aa424d5 commit 50073eb
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 68 deletions.
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"rollForward": "latestPatch"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<DataGridColumn TItem="TItem" Field="@Field" Caption="@Caption" Filterable="@Filterable" SortField="@SortField" Sortable="@Sortable" DisplayTemplate="@DisplayTemplate" @attributes="@AdditionalAttributes">
<FilterTemplate>
<TextEdit TextChanged="@(x => { context.TriggerFilterChange(x); })" Placeholder="@Placeholder" Debounce DebounceInterval="500" />
<TextEdit TextChanged="@(x => { context.TriggerFilterChange(x); })" Placeholder="@Placeholder" Debounce="true" DebounceInterval="500" />
</FilterTemplate>
</DataGridColumn>

Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.Site.NexusMods.Client/Models/GOGUserInfo2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.ServerClient;
using BUTR.Site.NexusMods.ServerClient;

namespace BUTR.Site.NexusMods.Client.Models
{
Expand Down
12 changes: 6 additions & 6 deletions src/BUTR.Site.NexusMods.Client/Services/Utils/PrismJSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,30 @@ public async Task Deinitialize()
await module.InvokeVoidAsync("deinit");
}
}

public async ValueTask HighlightAll()
{
var module = await _moduleTask.Value;

if (_tcs.Task.Status == TaskStatus.WaitingForActivation)
{
await Initialize();
}
await _tcs.Task;

await module.InvokeVoidAsync("highlightAll");
}

public async ValueTask<MarkupString> HighlightCIL(string code)
{
var module = await _moduleTask.Value;

if (_tcs.Task.Status == TaskStatus.WaitingForActivation)
{
await Initialize();
}
await _tcs.Task;

return new MarkupString(await module.InvokeAsync<string>("highlightCIL", code));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cexternalstorage/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Chttpclients/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Models.Database;
using BUTR.Site.NexusMods.Server.Models.Database;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
Expand Down
12 changes: 6 additions & 6 deletions src/BUTR.Site.NexusMods.Server/Controllers/DiscordController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public DiscordController(DiscordClient discordClient, IDiscordStorage discordSto
var refreshed = await _discordClient.GetOrRefreshTokens(tokens.Data, ct);
if (refreshed is null)
return APIResponseError<string>("Failed to unlink!");

if (tokens.Data.AccessToken != refreshed.AccessToken)
await _discordStorage.UpsertAsync(userId, tokens.ExternalId, refreshed);

if (!await _discordClient.PushMetadata(refreshed, new Metadata(0, 0, 0, 0), ct))
return APIResponseError<string>("Failed to unlink!");

Expand Down Expand Up @@ -114,10 +114,10 @@ public DiscordController(DiscordClient discordClient, IDiscordStorage discordSto
var refreshed = await _discordClient.GetOrRefreshTokens(tokens.Data, ct);
if (refreshed is null)
return APIResponse<DiscordUserInfo>(null);

if (tokens.Data.AccessToken != refreshed.AccessToken)
await _discordStorage.UpsertAsync(userId, tokens.ExternalId, refreshed);

var result = await _discordClient.GetUserInfo(refreshed, ct);
return APIResponse(result);
}
Expand All @@ -141,10 +141,10 @@ public DiscordController(DiscordClient discordClient, IDiscordStorage discordSto
var refreshed = await _discordClient.GetOrRefreshTokens(tokens.Data, ct);
if (refreshed is null)
return false;

if (tokens.Data.AccessToken != refreshed.AccessToken)
await _discordStorage.UpsertAsync(userId, tokens.ExternalId, refreshed);

return await _discordClient.PushMetadata(refreshed, new Metadata(
1,
role == ApplicationRoles.Moderator ? 1 : 0,
Expand Down
10 changes: 5 additions & 5 deletions src/BUTR.Site.NexusMods.Server/Controllers/GOGController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed record GOGUserInfo(
[ApiController, Route("api/v1/[controller]"), Authorize(AuthenticationSchemes = ButrNexusModsAuthSchemeConstants.AuthScheme)]
public sealed class GOGController : ControllerExtended
{

private readonly IGOGStorage _gogStorage;
private readonly AppDbContext _dbContext;
private readonly GOGAuthClient _gogAuthClient;
Expand Down Expand Up @@ -51,13 +51,13 @@ public GOGController(IGOGStorage gogStorage, AppDbContext dbContext, GOGAuthClie
var tokens = await _gogAuthClient.CreateTokens(code, ct);
if (tokens is null)
return APIResponseError<string>("Failed to link!");

var userId = HttpContext.GetUserId();

var games = await _gogEmbedClient.GetGames(tokens.AccessToken, ct);
if (games is null)
return APIResponseError<string>("Failed to link!");

var ownsBannerlord = games.Owned.Contains(1802539526) || games.Owned.Contains(1564781494);
if (ownsBannerlord)
{
Expand Down Expand Up @@ -108,10 +108,10 @@ public GOGController(IGOGStorage gogStorage, AppDbContext dbContext, GOGAuthClie
var refreshed = await _gogAuthClient.GetOrRefreshTokens(tokens.Data, ct);
if (refreshed is null)
return APIResponse<GOGUserInfo>(null);

if (tokens.Data.AccessToken != refreshed.AccessToken)
await _gogStorage.UpsertAsync(userId, refreshed.UserId, refreshed);

var result = await _gogEmbedClient.GetUserInfo(refreshed.AccessToken, ct);
return APIResponse(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public RecreateStacktraceController(ILogger<RecreateStacktraceController> logger
var currentMethods = crashReport.EnhancedStacktrace.SelectMany(x => x.Methods).Select(x => x.Method).ToArray();
var newMethods = recreatedStacktrace.Select(x => x.Method).ToHashSet();
var missingMethods = currentMethods.Except(newMethods).ToHashSet();

var methods = crashReport.EnhancedStacktrace.SelectMany(y => y.Methods).ToArray();
var ilOffsets = crashReport.EnhancedStacktrace.Select(x => x.Methods.Select(y => (x.ILOffset, y.Method))).SelectMany(x => x).DistinctBy(x => x.Method).ToDictionary(x => x.Method, x => x.ILOffset);
var recreatedStacktraceWithMissing = recreatedStacktrace.Concat(missingMethods.Select(x => new RecreatedStacktrace(x, $"No Code Available. IL Offset: {ilOffsets[x]}", 1)))
.OrderBy(x => Array.FindIndex(methods, y => y.Method == x.Method));

return APIResponse(recreatedStacktraceWithMissing);
}

[HttpGet("Html/{id}")]
[Produces("text/plain")]
public async Task<ActionResult<string>> Html(string id, CancellationToken ct)
Expand All @@ -69,12 +69,12 @@ public async Task<ActionResult<string>> Html(string id, CancellationToken ct)
var currentMethods = crashReport.EnhancedStacktrace.SelectMany(x => x.Methods).Select(x => x.Method).ToArray();
var newMethods = recreatedStacktrace.Select(x => x.Method).ToHashSet();
var missingMethods = currentMethods.Except(newMethods).ToHashSet();

var methods = crashReport.EnhancedStacktrace.SelectMany(y => y.Methods).ToArray();
var ilOffsets = crashReport.EnhancedStacktrace.Select(x => x.Methods.Select(y => (x.ILOffset, y.Method))).SelectMany(x => x).DistinctBy(x => x.Method).ToDictionary(x => x.Method, x => x.ILOffset);
var recreatedStacktraceWithMissing = recreatedStacktrace.Concat(missingMethods.Select(x => new RecreatedStacktrace(x, $"No Code Available. IL Offset: {ilOffsets[x]}", 1)))
.OrderBy(x => Array.FindIndex(methods, y => y.Method == x.Method));

static string GetEnhancedStacktraceHtml(IEnumerable<RecreatedStacktrace> stacktrace)
{
var sb = new StringBuilder();
Expand Down Expand Up @@ -113,7 +113,7 @@ static string GetEnhancedStacktraceHtml(IEnumerable<RecreatedStacktrace> stacktr

</script>
""";

var html = $"""
<html>
<head>
Expand All @@ -127,7 +127,7 @@ static string GetEnhancedStacktraceHtml(IEnumerable<RecreatedStacktrace> stacktr
</body>
</html>
""";

return Content(html, "text/html", Encoding.UTF8);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Text.Unicode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;

namespace BUTR.Site.NexusMods.Server.Extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Text.Unicode;
Expand All @@ -21,7 +21,7 @@ public static unsafe Span<char> GetStringUTF8Span(this MetadataReader metadataRe
Utf8.ToUtf16(utf8, data, out _, out _);
return data;
}

public static unsafe Span<byte> GetStringRawSpan(this MetadataReader metadataReader, StringHandle stringHandle)
{
var reader = metadataReader.GetBlobReader(stringHandle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Unicode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;

using System;

#nullable disable

Expand Down Expand Up @@ -48,4 +49,4 @@ protected override void Down(MigrationBuilder migrationBuilder)
name: "nexusmods_to_gog");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BUTR.Site.NexusMods.Server.Models.API
namespace BUTR.Site.NexusMods.Server.Models.API
{
public sealed record GOGOAuthUrlModel(string Url);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Services;
using BUTR.Site.NexusMods.Server.Services;

using System;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Services;
using BUTR.Site.NexusMods.Server.Services;

namespace BUTR.Site.NexusMods.Server.Models.Database
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Options;
using BUTR.Site.NexusMods.Server.Options;

using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
Expand All @@ -24,17 +24,17 @@ public BannerlordBinaryCache(SteamDepotDownloader steamDepotDownloader, IOptions
_options = options.Value;
_distributedCache = distributedCache;
}

public async Task<IEnumerable<string>> GetBranchAssemblyFiles(string branch, CancellationToken ct)
{
var path = Path.Combine(_options.DownloadPath, branch);

if (await _distributedCache.GetStringAsync(path, ct) is { } filesRaw)
return filesRaw.Split(';');

await _steamDepotDownloader.DownloadAsync(branch, path, CancellationToken.None);
var files = Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories).ToArray();

await _distributedCache.SetStringAsync(path, string.Join(';', files), new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(8)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Contexts;
using BUTR.Site.NexusMods.Server.Contexts;
using BUTR.Site.NexusMods.Server.Extensions;
using BUTR.Site.NexusMods.Server.Models.Database;

Expand Down Expand Up @@ -28,7 +28,7 @@ public abstract class BaseDatabaseStorage<TData, TExternalEntity, TNexusModsToEx
where TNexusModsToExternalEntity : class, INexusModsToExternalEntity
{
protected abstract string ExternalMetadataId { get; }

private readonly AppDbContext _dbContext;

protected BaseDatabaseStorage(AppDbContext dbContext)
Expand All @@ -37,7 +37,7 @@ protected BaseDatabaseStorage(AppDbContext dbContext)
}

protected abstract TData FromExternalEntity(TExternalEntity externalEntity);

protected abstract TNexusModsToExternalEntity? Upsert(int nexusModsUserId, string externalId, TNexusModsToExternalEntity? existing);
protected abstract TExternalEntity? Upsert(string externalId, TData data, TExternalEntity? existing);
private TNexusModsToExternalEntity? Remove(TNexusModsToExternalEntity? existing) => existing switch
Expand All @@ -48,8 +48,8 @@ protected BaseDatabaseStorage(AppDbContext dbContext)
{
_ => null
};


public async Task<TData?> GetAsync(string userId)
{
var entity = await _dbContext.FirstOrDefaultAsync<TExternalEntity>(x => x.UserId == userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BUTR.Site.NexusMods.Server.Services
namespace BUTR.Site.NexusMods.Server.Services
{
public class ExternalStorageConstants
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IDiscordStorage
public sealed class DatabaseDiscordStorage : BaseDatabaseStorage<DiscordOAuthTokens, DiscordLinkedRoleTokensEntity, NexusModsUserToDiscordEntity>, IDiscordStorage
{
protected override string ExternalMetadataId => ExternalStorageConstants.Discord;

public DatabaseDiscordStorage(AppDbContext dbContext) : base(dbContext) { }

protected override DiscordOAuthTokens FromExternalEntity(DiscordLinkedRoleTokensEntity externalEntity) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ public async Task<bool> SetGlobalMetadata(IReadOnlyList<DiscordGlobalMetadata> m
if (!response.IsSuccessStatusCode) return null;
var responseData = await JsonSerializer.DeserializeAsync<DiscordOAuthTokensResponse>(await response.Content.ReadAsStreamAsync(ct), cancellationToken: ct);
if (responseData is null) return null;

return new DiscordOAuthTokens(responseData.AccessToken, responseData.RefreshToken, DateTimeOffset.Now + TimeSpan.FromSeconds(responseData.ExpiresIn));
}

public async Task<DiscordUserInfo?> GetUserInfo(DiscordOAuthTokens tokens, CancellationToken ct)
{
using var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, "https://discord.com/api/v10/oauth2/@me")
Expand Down
Loading

0 comments on commit 50073eb

Please sign in to comment.