Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(IIPLocator): add JsonSerializerOptions Encoder config #2620

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/BootstrapBlazor.Server/Components/Layout/MainLayout.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
font-weight: 700;
}

::deep p {
line-height: 2;
::deep p:last-child {
margin-bottom: 0;
}

::deep p:last-child {
margin-bottom: 0;
}

::deep p code,
::deep li code {
display: inline-block;
padding: 0px 8px;
background-color: #e9ecef;
margin: 0;
border-radius: var(--bs-border-radius);
}
::deep p code,
::deep li code {
display: inline-block;
padding: 0px 8px;
background-color: #e9ecef;
margin: 0;
border-radius: var(--bs-border-radius);
}

::deep .code-label {
font-weight: bold;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
font-weight: 700;
}

::deep p {
line-height: 2;
}

::deep p:last-child {
margin-bottom: 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@

<p>@Localizer["NormalTip"]</p>
<p>@((MarkupString)Localizer["NormalTips1"].Value)</p>
<Pre>[Inject]
<Pre class="mb-3">[Inject]
[NotNull]
private IDispatchService&lt;GiteePostBody&gt;? DispatchService { get; set; }</Pre>
<p>@((MarkupString)Localizer["NormalTips2"].Value)</p>
<Pre>protected override void OnInitialized()
<Pre class="mb-3">protected override void OnInitialized()
{
// ...
DispatchService.Subscribe(Notify);
}</Pre>
<p>@((MarkupString)Localizer["NormalTips3"].Value)</p>
<Pre>private void Dispose(bool disposing)
<Pre class="mb-3">private void Dispose(bool disposing)
{
if (disposing)
{
DispatchService.UnSubscribe(Notify);
}
}</Pre>
<p>@((MarkupString)Localizer["NormalTips4"].Value)</p>
<Pre>private async Task Notify(DispatchEntry&lt;GiteePostBody&gt; payload)
<Pre class="mb-3">private async Task Notify(DispatchEntry&lt;GiteePostBody&gt; payload)
{
if (payload.Entry != null)
{
Expand Down
19 changes: 17 additions & 2 deletions src/BootstrapBlazor/Components/IPLocator/DefaultIPLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

using Microsoft.Extensions.Logging;
using System.Net.Http.Json;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;

namespace BootstrapBlazor.Components;

Expand All @@ -12,6 +15,18 @@ namespace BootstrapBlazor.Components;
/// </summary>
public class DefaultIPLocator : IIPLocator
{
private readonly JsonSerializerOptions _options;
/// <summary>
/// 构造函数
/// </summary>
public DefaultIPLocator()
{
_options = new JsonSerializerOptions()
{
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
}

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand All @@ -29,7 +44,7 @@ public class DefaultIPLocator : IIPLocator
/// </summary>
/// <param name="option"></param>
/// <returns></returns>
protected virtual async Task<string?> Locate<T>(IPLocatorOption option) where T : class
protected virtual async Task<string?> Locate<T>(IPLocatorOption option)
{
string? ret = null;
if (!string.IsNullOrEmpty(Url) && !string.IsNullOrEmpty(option.IP) && option.HttpClient != null)
Expand All @@ -38,7 +53,7 @@ public class DefaultIPLocator : IIPLocator
try
{
using var token = new CancellationTokenSource(option.RequestTimeout);
var result = await option.HttpClient.GetFromJsonAsync<T>(url, token.Token);
var result = await option.HttpClient.GetFromJsonAsync<T>(url, _options, token.Token);
if (result != null)
{
ret = result.ToString();
Expand Down