-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(INetworkMonitorService): add INetworkMonitorService service #6407
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
14cbed5
doc: 移除 SDK 文本
ArgoZhang e71e6b0
doc: 增加网络状态菜单
ArgoZhang 7276b02
doc: 增加网络状态源码映射
ArgoZhang 2b7aecf
doc: 增加网络状态示例
ArgoZhang 5a7a8c5
doc: 增加指示器示例文档
ArgoZhang 4d58915
feat: 增加 INetworkMonitorService 服务
ArgoZhang 65d85ce
refactor: 实现 INetworkMonitorService 逻辑
ArgoZhang 7287e74
doc: 更新示例
ArgoZhang 4c7c660
refactor: 支持离线状态
ArgoZhang 655ce8e
doc: 更新文档
ArgoZhang ab14b19
refactor: 更新细节
ArgoZhang a03b0d7
test: 更新单元测试
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/BootstrapBlazor.Server/Components/Samples/NetworkMonitors.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| @page "/network-monitor" | ||
| @inject IStringLocalizer<NetworkMonitors> Localizer | ||
|
|
||
| <h3>@Localizer["NetworkMonitorTitle"]</h3> | ||
|
|
||
| <h4>@((MarkupString)Localizer["NetworkMonitorDescription"].Value)</h4> | ||
|
|
||
| <DemoBlock Title="@Localizer["NormalTitle"]" | ||
| Introduction="@Localizer["NormalIntro"]" | ||
| Name="Normal"> | ||
| <section ignore> | ||
| <ul class="ul-demo"> | ||
| <li><div class="demo-indicator demo-indicator-4g"></div> @Localizer["IndicatorLi1"]</li> | ||
| <li><div class="demo-indicator demo-indicator-3g"></div> @Localizer["IndicatorLi2"]</li> | ||
| <li><div class="demo-indicator demo-indicator-2g"></div> @Localizer["IndicatorLi3"]</li> | ||
| <li><div class="demo-indicator demo-indicator-offline"></div> @Localizer["IndicatorLi4"]</li> | ||
| </ul> | ||
| </section> | ||
| <NetworkMonitorIndicator></NetworkMonitorIndicator> | ||
| <section ignore> | ||
| <ConsoleLogger @ref="_logger"></ConsoleLogger> | ||
| </section> | ||
| </DemoBlock> |
50 changes: 50 additions & 0 deletions
50
src/BootstrapBlazor.Server/Components/Samples/NetworkMonitors.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples; | ||
|
|
||
| /// <summary> | ||
| /// NetworkMonitor Sample code | ||
| /// </summary> | ||
| public partial class NetworkMonitors : IDisposable | ||
| { | ||
| [Inject, NotNull] | ||
| private INetworkMonitorService? NetworkMonitorService { get; set; } | ||
|
|
||
| private ConsoleLogger _logger = null!; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| protected override async Task OnInitializedAsync() | ||
| { | ||
| await base.OnInitializedAsync(); | ||
|
|
||
| await NetworkMonitorService.RegisterStateChangedCallback(this, OnNetworkStateChanged); | ||
| } | ||
|
|
||
| private Task OnNetworkStateChanged(NetworkMonitorState state) | ||
| { | ||
| _logger.Log($"Online: NetworkType: {state.NetworkType} Downlink: {state.Downlink} RTT: {state.RTT}"); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private void Dispose(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| NetworkMonitorService.UnregisterStateChangedCallback(this); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| public void Dispose() | ||
| { | ||
| Dispose(true); | ||
| GC.SuppressFinalize(this); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/BootstrapBlazor.Server/Components/Samples/NetworkMonitors.razor.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| .ul-demo { | ||
| list-style: none; | ||
| padding-left: 0; | ||
| } | ||
|
|
||
| .demo-indicator { | ||
| cursor: pointer; | ||
| width: 0.5rem; | ||
| height: 0.5rem; | ||
| border-radius: 50%; | ||
| display: inline-block; | ||
| margin-inline-end: .5rem; | ||
| } | ||
|
|
||
| .demo-indicator-4g { | ||
| background-color: var(--bs-primary); | ||
| } | ||
|
|
||
| .demo-indicator-3g { | ||
| background-color: var(--bs-warning); | ||
| } | ||
|
|
||
| .demo-indicator-2g { | ||
| background-color: var(--bs-danger); | ||
| } | ||
|
|
||
| .demo-indicator-offline { | ||
| background-color: var(--bs-secondary); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
src/BootstrapBlazor/Components/NetworkMonitor/NetworkMonitor.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider simplifying the Dispose implementation by removing the Dispose(bool) pattern and finalizer suppression, and directly unregistering the callback in Dispose().