-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
executable file
·66 lines (55 loc) · 2.27 KB
/
Program.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
60
61
62
63
64
65
66
using System;
using System.Threading.Tasks;
using ConsoleApplication.Aggregate;
using ConsoleApplication.Events;
using ConsoleApplication.EventStore;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var main = MainAsync(args);
try
{
main.Wait();
}
catch(Exception ex)
{
Console.Error.WriteLine("Something screwed up: {0}", ex);
}
}
private static NumberOfOrdersProjection NumberOfOrders = new NumberOfOrdersProjection();
private static AverageDeliveryTimeProjection AverageDeliveryTime = new AverageDeliveryTimeProjection();
private static async Task MainAsync(string[] args)
{
var aggregate = await GetAggregateAsync();
Console.WriteLine($"OrderId: {aggregate.OrderId}");
Console.WriteLine($"Order status: {aggregate.Status}");
Console.WriteLine($"Delivery time: {aggregate.DeliveredTimestamp.Value - aggregate.SubmittedTimestamp.Value}");
Console.WriteLine($"Items in cart: {aggregate.Cart.Count}");
foreach(var cartItem in aggregate.Cart)
{
Console.WriteLine($"Ordered {cartItem.Value.Quantity} of {cartItem.Value.ItemId} for ${cartItem.Value.Price}");
}
Console.WriteLine($"Number of orders from projection: {NumberOfOrders.NumberOfOrders}");
Console.WriteLine($"AverageDeliveryTime: {AverageDeliveryTime.AverageDeliveryMilliseconds}");
}
public static async Task<OrderAggregate> GetAggregateAsync()
{
EventStore.EventStore.RegisterProjection(NumberOfOrders);
EventStore.EventStore.RegisterProjection(AverageDeliveryTime);
foreach(var @event in EventStore.EventStore.GetEventPayloads(Guid.NewGuid()))
{
EventStore.EventStore.CommitEvent(@event);
}
var messages = EventStore.EventStore.GetEvents();
var aggregate = new OrderAggregate();
foreach(var m in messages)
{
await aggregate.Apply(m.Payload);
}
return aggregate;
}
}
}