Skip to content
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
Original file line number Diff line number Diff line change
@@ -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([email protected]) Website: https://www.blazor.zone

namespace BootstrapBlazor.Server.Components.Samples.Tutorials;

/// <summary>
/// Contributor
/// </summary>
public sealed class Contributor
{
/// <summary>
/// Gets or sets Name
/// </summary>
public string? Name { get; set; }

/// <summary>
/// Gets or sets Avatar
/// </summary>
public string? Avatar { get; set; }

/// <summary>
/// Gets or sets Description
/// </summary>
public string? Description { get; set; }

/// <summary>
/// Gets or sets Sheet data
/// </summary>
public UniverSheetData? Data { get; set; }
}
Original file line number Diff line number Diff line change
@@ -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([email protected]) Website: https://www.blazor.zone

namespace BootstrapBlazor.Server.Components.Samples.Tutorials;

static class MockOnlineContributor
{
public static void Trigger(IDispatchService<Contributor> dispatchService)
{
dispatchService.Dispatch(new DispatchEntry<Contributor>()
{
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 更新此单元格"
}
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ protected override void OnInitialized()
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
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;
Expand All @@ -63,7 +79,7 @@ private async Task Dispatch(DispatchEntry<Contributor> entry)
return;
}

if (entry.Entry != null)
if (entry is { Name: "OnlineSheet-Demo", Entry: not null })
{
await ToastService.Show(new ToastOption()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ public static IServiceCollection AddBootstrapBlazorServerService(this IServiceCo
// 增加 SignalR 服务数据传输大小限制配置
services.Configure<HubOptions>(option => option.MaximumReceiveMessageSize = null);

#if !DEBUG
// 增加后台任务服务
services.AddTaskServices();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider replacing the open-generic AddTaskServices registration with explicit service registrations or a small factory to improve clarity and maintainability.

Suggested change
services.AddTaskServices();
The call to `services.AddTaskServices()` is hiding an open‐generic/reflection‐based scan that can make it hard to see exactly which `IDispatchService<T>` implementations are wired up. You can simplify by registering each dispatch service explicitly (or with a tiny factory) while preserving all existing behavior. For example:
```csharp
// instead of: services.AddTaskServices();
services.AddScoped<IDispatchService<Order>, OrderDispatchService>();
services.AddScoped<IDispatchService<Invoice>, InvoiceDispatchService>();
services.AddScoped<IDispatchService<Customer>, CustomerDispatchService>();
// …repeat for each T…

Or, if you still want a single registration point, use a small factory delegate:

services.AddSingleton<Func<Type, object>>(sp => serviceType =>
{
    if (serviceType == typeof(IDispatchService<Order>))
        return sp.GetRequiredService<OrderDispatchService>();
    if (serviceType == typeof(IDispatchService<Invoice>))
        return sp.GetRequiredService<InvoiceDispatchService>();
    if (serviceType == typeof(IDispatchService<Customer>))
        return sp.GetRequiredService<CustomerDispatchService>();
    throw new KeyNotFoundException($"No dispatch service for {serviceType}");
});

This keeps the registrations explicit—no hidden assembly scans—and makes it obvious which dispatch services are available.

services.AddHostedService<ClearTempFilesService>();
services.AddHostedService<MockOnlineContributor>();
#endif
services.AddHostedService<MockReceiveSocketServerService>();
services.AddHostedService<MockSendReceiveSocketServerService>();
services.AddHostedService<MockCustomProtocolSocketServerService>();
Expand Down
71 changes: 0 additions & 71 deletions src/BootstrapBlazor.Server/Services/MockOnlineContributor.cs

This file was deleted.

Loading