From 65ca872d6b8c7b0d4ba6b25f8b27d9e4b76364cb Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 12:43:24 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=E8=BF=87=E6=BB=A4=E6=8E=89?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Services/WebClientService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Services/WebClientService.cs b/src/BootstrapBlazor/Services/WebClientService.cs index 9b4ad06dfad..2c466e69f5b 100644 --- a/src/BootstrapBlazor/Services/WebClientService.cs +++ b/src/BootstrapBlazor/Services/WebClientService.cs @@ -46,8 +46,9 @@ public async Task GetClientInfo() // 等待 SetData 方法执行完毕 try { - await _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(1)); + await _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(3)); } + catch (TimeoutException) { } catch (Exception ex) { logger.LogError(ex, "method GetClientInfo failed"); From df965b1b7f7fdf87ea2cd6ea1b1a1c124986e80c Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 14:26:06 +0800 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Affix/Affix.razor.cs | 2 +- src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs index bd5e4606755..35861567f7a 100644 --- a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs +++ b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs @@ -41,7 +41,7 @@ public partial class Affix private string? StyleString => CssBuilder.Default("position: sticky;") .AddStyle("z-index", $"{ZIndex}", ZIndex.HasValue) - .AddStyle($"{Position.ToDescriptionString()}", $"{Offset}px") + .AddStyle(Position.ToDescriptionString(), $"{Offset}px") .AddStyleFromAttributes(AdditionalAttributes) .Build(); } diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index cf3e86aba3a..a4e32e5ad83 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -19,7 +19,7 @@ public partial class Drawer .Build(); private string? StyleString => CssBuilder.Default() - .AddStyle("--bb-drawer-position", $"{Position}", !string.IsNullOrEmpty(Position)) + .AddStyle("--bb-drawer-position", Position) .AddStyleFromAttributes(AdditionalAttributes) .Build(); @@ -27,8 +27,8 @@ public partial class Drawer /// 获得 抽屉 Style 字符串 /// private string? DrawerStyleString => CssBuilder.Default() - .AddStyle("--bb-drawer-width", $"{Width}", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) - .AddStyle("--bb-drawer-height", $"{Height}", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) + .AddStyle("--bb-drawer-width", Width, Placement != Placement.Top && Placement != Placement.Bottom) + .AddStyle("--bb-drawer-height", Height, Placement == Placement.Top || Placement == Placement.Bottom) .Build(); /// From 63af32a5062929d2be642a90919d0bedfc722bc6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Feb 2025 08:42:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/WebClientServiceTest.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Services/WebClientServiceTest.cs b/test/UnitTest/Services/WebClientServiceTest.cs index 6d7bf64861a..35ff8cdcb36 100644 --- a/test/UnitTest/Services/WebClientServiceTest.cs +++ b/test/UnitTest/Services/WebClientServiceTest.cs @@ -59,11 +59,17 @@ public async Task WebClientOptions_Ok() } [Fact] - public async Task Timeout_Ok() + public async Task GetClientInfo_Error() { var service = Context.Services.GetRequiredService(); var client = await service.GetClientInfo(); + + // TimeoutException Assert.Null(client.Ip); + + // Exception + Context.JSInterop.SetupVoid("ping", _ => true).SetException(new Exception("test-exception")); + client = await service.GetClientInfo(); } [Fact] From 63f99e6054ad906862e38018883218a6ba5122cc Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Feb 2025 08:45:45 +0800 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Services/WebClientService.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/BootstrapBlazor/Services/WebClientService.cs b/src/BootstrapBlazor/Services/WebClientService.cs index 2c466e69f5b..d545a21967b 100644 --- a/src/BootstrapBlazor/Services/WebClientService.cs +++ b/src/BootstrapBlazor/Services/WebClientService.cs @@ -39,13 +39,14 @@ public async Task GetClientInfo() { RequestUrl = navigation.Uri }; - _jsModule ??= await runtime.LoadModule("./_content/BootstrapBlazor/modules/client.js"); - _interop ??= DotNetObjectReference.Create(this); - await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData)); - // 等待 SetData 方法执行完毕 try { + _jsModule ??= await runtime.LoadModuleByName("client"); + _interop ??= DotNetObjectReference.Create(this); + await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData)); + + // 等待 SetData 方法执行完毕 await _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(3)); } catch (TimeoutException) { } From 3eb3f4e97e0149c1d3f226ee3f9a67bdd46ec716 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Feb 2025 11:02:29 +0800 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Services/WebClientService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Services/WebClientService.cs b/src/BootstrapBlazor/Services/WebClientService.cs index d545a21967b..34c25d1b0ee 100644 --- a/src/BootstrapBlazor/Services/WebClientService.cs +++ b/src/BootstrapBlazor/Services/WebClientService.cs @@ -42,7 +42,7 @@ public async Task GetClientInfo() try { - _jsModule ??= await runtime.LoadModuleByName("client"); + _jsModule ??= await runtime.LoadModule("./_content/BootstrapBlazor/modules/client.js"); _interop ??= DotNetObjectReference.Create(this); await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData));