Skip to content

Commit

Permalink
add wiki weapon page
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Nov 29, 2022
1 parent 8f273e6 commit e051787
Show file tree
Hide file tree
Showing 63 changed files with 1,545 additions and 258 deletions.
48 changes: 25 additions & 23 deletions src/Snap.Hutao/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[*.cs]
charset = utf-8-bom

[*.cs]

# SA1101: Prefix local calls with this
dotnet_diagnostic.SA1101.severity = none
Expand Down Expand Up @@ -76,31 +78,31 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.non_field_members.required_modifiers =

# 命名样式

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_diagnostic.SA1629.severity = none
dotnet_diagnostic.SA1642.severity = none
Expand Down Expand Up @@ -185,29 +187,29 @@ dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.类型.required_modifiers =
dotnet_naming_symbols.类型.required_modifiers =

dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method
dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.非字段成员.required_modifiers =
dotnet_naming_symbols.非字段成员.required_modifiers =

# 命名样式

dotnet_naming_style.以_i_开始.required_prefix = I
dotnet_naming_style.以_i_开始.required_suffix =
dotnet_naming_style.以_i_开始.word_separator =
dotnet_naming_style.以_i_开始.required_suffix =
dotnet_naming_style.以_i_开始.word_separator =
dotnet_naming_style.以_i_开始.capitalization = pascal_case

dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case

dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class HttpClientGenerator : ISourceGenerator

private const string PrimaryHttpMessageHandlerAttributeName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.PrimaryHttpMessageHandlerAttribute";
private const string DynamicSecretAttributeName = "Snap.Hutao.Web.Hoyolab.DynamicSecret.UseDynamicSecretAttribute";
private const string IgnoreSetCookieAttributeName = "Snap.Hutao.Web.Hoyolab.Annotation.IgnoreSetCookieAttribute";

/// <inheritdoc/>
public void Initialize(GeneratorInitializationContext context)
Expand Down Expand Up @@ -54,7 +53,6 @@ public void Execute(GeneratorExecutionContext context)
// This class is generated by Snap.Hutao.SourceGeneration
using Microsoft.Extensions.DependencyInjection;
using Snap.Hutao.Web.Hoyolab;
using Snap.Hutao.Web.Hoyolab.DynamicSecret;
using System.Net.Http;
Expand Down Expand Up @@ -83,10 +81,7 @@ private static void FillWithInjectionServices(HttpClientSyntaxContextReceiver re

foreach (INamedTypeSymbol classSymbol in receiver.Classes)
{
lineBuilder
.Clear()
.Append("\r\n");

lineBuilder.Clear().Append(Environment.NewLine);
lineBuilder.Append(@" services.AddHttpClient<");
lineBuilder.Append($"{classSymbol.ToDisplayString()}>(");

Expand Down Expand Up @@ -139,11 +134,6 @@ private static void FillWithInjectionServices(HttpClientSyntaxContextReceiver re
lineBuilder.Append(".AddHttpMessageHandler<DynamicSecretHandler>()");
}

if (classSymbol.GetAttributes().Any(attr => attr.AttributeClass!.ToDisplayString() == IgnoreSetCookieAttributeName))
{
lineBuilder.Append(".AddHttpMessageHandler<IgnoreSetCookieHandler>()");
}

lineBuilder.Append(";");

lines.Add(lineBuilder.ToString());
Expand Down
2 changes: 2 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
<shmmc:AvatarSideIconConverter x:Key="AvatarSideIconConverter"/>
<shmmc:DescParamDescriptor x:Key="DescParamDescriptor"/>
<shmmc:ElementNameIconConverter x:Key="ElementNameIconConverter"/>
<shmmc:EquipIconConverter x:Key="EquipIconConverter"/>
<shmmc:GachaAvatarImgConverter x:Key="GachaAvatarImgConverter"/>
<shmmc:GachaAvatarIconConverter x:Key="GachaAvatarIconConverter"/>
<shmmc:GachaEquipIconConverter x:Key="GachaEquipIconConverter"/>
<shmmc:ItemIconConverter x:Key="ItemIconConverter"/>
<shmmc:PropertyInfoDescriptor x:Key="PropertyDescriptor"/>
<shmmc:QualityColorConverter x:Key="QualityColorConverter"/>
Expand Down
30 changes: 29 additions & 1 deletion src/Snap.Hutao/Snap.Hutao/Context/Database/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ namespace Snap.Hutao.Context.Database;
/// <summary>
/// 应用程序数据库上下文
/// </summary>
public class AppDbContext : DbContext
public sealed class AppDbContext : DbContext
{
private readonly Guid contextId;
private readonly ILogger<AppDbContext>? logger;

/// <summary>
/// 构造一个新的应用程序数据库上下文
/// </summary>
Expand All @@ -21,6 +24,19 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
{
}

/// <summary>
/// 构造一个新的应用程序数据库上下文
/// </summary>
/// <param name="options">选项</param>
/// <param name="logger">日志器</param>
public AppDbContext(DbContextOptions<AppDbContext> options, ILogger<AppDbContext> logger)
: this(options)
{
contextId = Guid.NewGuid();
this.logger = logger;
logger.LogInformation("AppDbContext[{id}] created.", contextId);
}

/// <summary>
/// 设置
/// </summary>
Expand Down Expand Up @@ -66,6 +82,11 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
/// </summary>
public DbSet<DailyNoteEntry> DailyNotes { get; set; } = default!;

/// <summary>
/// 对象缓存
/// </summary>
public DbSet<ObjectCacheEntry> ObjectCache { get; set; } = default!;

/// <summary>
/// 构造一个临时的应用程序数据库上下文
/// </summary>
Expand All @@ -76,6 +97,13 @@ public static AppDbContext Create(string sqlConnectionString)
return new(new DbContextOptionsBuilder<AppDbContext>().UseSqlite(sqlConnectionString).Options);
}

/// <inheritdoc/>
public override void Dispose()
{
base.Dispose();
logger?.LogInformation("AppDbContext[{id}] disposed.", contextId);
}

/// <inheritdoc/>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Snap.Hutao/Snap.Hutao/Core/Caching/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Snap.Hutao.Core.Logging;
using System.Collections.Immutable;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -236,10 +237,11 @@ private async Task DownloadFileAsync(Uri uri, StorageFile baseFile)
}
}
}
else
else if (message.StatusCode == HttpStatusCode.TooManyRequests)
{
retryCount++;
TimeSpan delay = message.Headers.RetryAfter?.Delta ?? RetryCountToDelay[retryCount];
logger.LogInformation("Retry after {delay}.", delay);
await Task.Delay(delay).ConfigureAwait(false);
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Extension/LoggerExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

namespace Snap.Hutao.Extension;

/// <summary>
/// 日志器扩展
/// </summary>
[SuppressMessage("", "CA2254")]
public static class LoggerExtension
{
/// <inheritdoc cref="LoggerExtensions.LogInformation(ILogger, string?, object?[])"/>
public static T LogInformation<T>(this ILogger logger, string message, params object?[] param)
{
logger.LogInformation(message, param);
return default!;
}

/// <inheritdoc cref="LoggerExtensions.LogWarning(ILogger, string?, object?[])"/>
public static T LogWarning<T>(this ILogger logger, string message, params object?[] param)
{
logger.LogWarning(message, param);
return default!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public static StringBuilder AppendIfElse(this StringBuilder sb, bool condition,
{
return condition ? sb.Append(trueValue) : sb.Append(falseValue);
}
}
}
Loading

0 comments on commit e051787

Please sign in to comment.