-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OneBot] Introduce WebServiceCollection
- Loading branch information
Linwenxuan
authored and
Linwenxuan
committed
Oct 27, 2023
1 parent
213229d
commit a4078b8
Showing
4 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
using Lagrange.OneBot.Core.Network.Service; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Lagrange.OneBot.Core.Network; | ||
|
||
public class LagrangeWebSvcCollection : List<ILagrangeWebService>, IHostedService | ||
{ | ||
public event EventHandler<MsgRecvEventArgs> OnMessageReceived = delegate { }; | ||
|
||
public LagrangeWebSvcCollection(IEnumerable<ILagrangeWebService> services) : base(services) | ||
{ | ||
foreach (var service in this) service.OnMessageReceived += OnMessageReceived.Invoke; | ||
} | ||
|
||
public async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
foreach (var service in this) await service.StartAsync(cancellationToken); | ||
} | ||
|
||
public async Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
foreach (var service in this) await service.StopAsync(cancellationToken); | ||
} | ||
|
||
public async Task SendJsonAsync<T>(T json, CancellationToken cancellationToken = default) | ||
{ | ||
foreach (var service in this) await service.SendJsonAsync(json, cancellationToken); | ||
} | ||
} |
This file contains 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 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