-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathLocalComposerService.cs
49 lines (45 loc) · 1.74 KB
/
LocalComposerService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Samples.Blazor.Abstractions;
using Stl.Fusion.Authentication;
namespace Samples.Blazor.UI.Services;
public class LocalComposerService : ILocalComposerService
{
protected ILogger Log { get; }
private ITimeService TimeService { get; }
private ISumService SumService { get; }
private IChatService ChatService { get; }
private IAuth Auth { get; }
public LocalComposerService(
ITimeService timeService,
ISumService sumService,
IChatService chatService,
IAuth auth,
ILogger<LocalComposerService>? log = null)
{
Log = log ?? NullLogger<LocalComposerService>.Instance;
TimeService = timeService;
SumService = sumService;
ChatService = chatService;
Auth = auth;
}
public virtual async Task<ComposedValue> GetComposedValue(
Session session, string parameter,
CancellationToken cancellationToken)
{
var chatTail = await ChatService.GetChatTail(1, cancellationToken);
var uptime = await TimeService.GetUptime(10, cancellationToken);
var sum = (double?) null;
if (double.TryParse(parameter, out var value))
sum = await SumService.GetSum(new [] { value }, true, cancellationToken);
var lastChatMessage = chatTail.Messages.SingleOrDefault()?.Text ?? "(no messages)";
var user = await Auth.GetUser(session, cancellationToken);
var activeUserCount = await ChatService.GetActiveUserCount(cancellationToken);
return new ComposedValue() {
Parameter = $"{parameter} - local",
Uptime = uptime,
Sum = sum,
LastChatMessage = lastChatMessage,
User = user,
ActiveUserCount = activeUserCount
};
}
}