-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathMessages.cs
59 lines (45 loc) · 1.65 KB
/
Messages.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
50
51
52
53
54
55
56
57
58
59
using System.Collections.Immutable;
namespace AkkaWordCounter2.App;
/// <summary>
/// Value type for enforcing absolute uris
/// </summary>
public record struct AbsoluteUri
{
public AbsoluteUri(Uri value)
{
Value = value;
if (!value.IsAbsoluteUri)
throw new ArgumentException("Value must be an absolute URL", nameof(value));
}
public Uri Value { get; }
public override string ToString() => Value.ToString();
}
public interface IWithDocumentId
{
AbsoluteUri DocumentId { get; }
}
public static class DocumentCommands
{
public sealed record ScanDocument(AbsoluteUri DocumentId) : IWithDocumentId;
public sealed record ScanDocuments(IReadOnlyList<AbsoluteUri> DocumentIds);
}
public static class DocumentEvents
{
public sealed record DocumentScanFailed(AbsoluteUri DocumentId, string Reason) : IWithDocumentId;
public sealed record WordsFound(AbsoluteUri DocumentId, IReadOnlyList<string> Tokens) : IWithDocumentId;
public sealed record EndOfDocumentReached(AbsoluteUri DocumentId) : IWithDocumentId;
public sealed record CountsTabulatedForDocument(AbsoluteUri DocumentId, ImmutableDictionary<string, int> WordFrequencies)
: IWithDocumentId;
public sealed record CountsTabulatedForDocuments(
IReadOnlyList<AbsoluteUri> Documents,
IImmutableDictionary<string, int> WordFrequencies);
}
public static class DocumentQueries
{
public sealed record FetchCounts(AbsoluteUri DocumentId) : IWithDocumentId;
public sealed class SubscribeToAllCounts
{
public static readonly SubscribeToAllCounts Instance = new();
private SubscribeToAllCounts(){}
}
}