diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/Contributor.cs b/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/Contributor.cs
new file mode 100644
index 00000000000..90298a43945
--- /dev/null
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/Contributor.cs
@@ -0,0 +1,32 @@
+// 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(argo@live.ca) Website: https://www.blazor.zone
+
+namespace BootstrapBlazor.Server.Components.Samples.Tutorials;
+
+///
+/// Contributor
+///
+public sealed class Contributor
+{
+ ///
+ /// Gets or sets Name
+ ///
+ public string? Name { get; set; }
+
+ ///
+ /// Gets or sets Avatar
+ ///
+ public string? Avatar { get; set; }
+
+ ///
+ /// Gets or sets Description
+ ///
+ public string? Description { get; set; }
+
+ ///
+ /// Gets or sets Sheet data
+ ///
+ public UniverSheetData? Data { get; set; }
+}
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/MockOnlineContributor.cs b/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/MockOnlineContributor.cs
new file mode 100644
index 00000000000..478ab44ffec
--- /dev/null
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/MockOnlineContributor.cs
@@ -0,0 +1,32 @@
+// 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(argo@live.ca) Website: https://www.blazor.zone
+
+namespace BootstrapBlazor.Server.Components.Samples.Tutorials;
+
+static class MockOnlineContributor
+{
+ public static void Trigger(IDispatchService dispatchService)
+ {
+ dispatchService.Dispatch(new DispatchEntry()
+ {
+ Name = "OnlineSheet-Demo",
+ Entry = new Contributor()
+ {
+ Name = "Argo Zhang",
+ Avatar = "/images/Argo-C.png",
+ Description = "正在更新单元格 A8",
+ Data = new UniverSheetData()
+ {
+ CommandName = "UpdateRange",
+ Data = new
+ {
+ Range = "A8",
+ Value = $"{DateTime.Now: yyyy-MM-dd HH:mm:ss} Argo 更新此单元格"
+ }
+ }
+ }
+ });
+ }
+}
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.razor.cs
index 7b76104aec4..90ac066baaf 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.razor.cs
@@ -49,6 +49,22 @@ protected override void OnInitialized()
}
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ protected override async Task OnAfterRenderAsync(bool firstRender)
+ {
+ await base.OnAfterRenderAsync(firstRender);
+
+ if (firstRender)
+ {
+ await Task.Delay(5000);
+ MockOnlineContributor.Trigger(DispatchService);
+ }
+ }
+
private async Task OnReadyAsync()
{
_inited = true;
@@ -63,7 +79,7 @@ private async Task Dispatch(DispatchEntry entry)
return;
}
- if (entry.Entry != null)
+ if (entry is { Name: "OnlineSheet-Demo", Entry: not null })
{
await ToastService.Show(new ToastOption()
{
diff --git a/src/BootstrapBlazor.Server/Extensions/ServiceCollectionExtensions.cs b/src/BootstrapBlazor.Server/Extensions/ServiceCollectionExtensions.cs
index a39e37ffae9..e0f9fc56317 100644
--- a/src/BootstrapBlazor.Server/Extensions/ServiceCollectionExtensions.cs
+++ b/src/BootstrapBlazor.Server/Extensions/ServiceCollectionExtensions.cs
@@ -35,12 +35,9 @@ public static IServiceCollection AddBootstrapBlazorServerService(this IServiceCo
// 增加 SignalR 服务数据传输大小限制配置
services.Configure(option => option.MaximumReceiveMessageSize = null);
-#if !DEBUG
// 增加后台任务服务
services.AddTaskServices();
services.AddHostedService();
- services.AddHostedService();
-#endif
services.AddHostedService();
services.AddHostedService();
services.AddHostedService();
diff --git a/src/BootstrapBlazor.Server/Services/MockOnlineContributor.cs b/src/BootstrapBlazor.Server/Services/MockOnlineContributor.cs
deleted file mode 100644
index 0a60295454c..00000000000
--- a/src/BootstrapBlazor.Server/Services/MockOnlineContributor.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-// 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(argo@live.ca) Website: https://www.blazor.zone
-
-using Longbow.Tasks;
-
-namespace BootstrapBlazor.Server.Services;
-
-class MockOnlineContributor(IDispatchService dispatchService) : BackgroundService
-{
- ///
- /// 运行任务
- ///
- ///
- ///
- protected override Task ExecuteAsync(CancellationToken stoppingToken)
- {
- TaskServicesManager.GetOrAdd("OnlineSheet", (provider, token) =>
- {
- dispatchService.Dispatch(new DispatchEntry()
- {
- Name = "OnlineSheet-Demo",
- Entry = new Contributor()
- {
- Name = "Argo Zhang",
- Avatar = "/images/Argo-C.png",
- Description = "正在更新单元格 A8",
- Data = new UniverSheetData()
- {
- CommandName = "UpdateRange",
- Data = new
- {
- Range = "A8",
- Value = $"{DateTime.Now: yyyy-MM-dd HH:mm:ss} Argo 更新此单元格"
- }
- }
- }
- });
- return Task.CompletedTask;
- }, TriggerBuilder.Build(Cron.Secondly(5)));
-
- return Task.CompletedTask;
- }
-}
-
-///
-/// Contributor
-///
-public class Contributor
-{
- ///
- /// Gets or sets Name
- ///
- public string? Name { get; set; }
-
- ///
- /// Gets or sets Avatar
- ///
- public string? Avatar { get; set; }
-
- ///
- /// Gets or sets Description
- ///
- public string? Description { get; set; }
-
- ///
- /// Gets or sets Sheet data
- ///
- public UniverSheetData? Data { get; set; }
-}