-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (54 loc) · 2.85 KB
/
Copy pathProgram.cs
File metadata and controls
67 lines (54 loc) · 2.85 KB
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
67
using Core.CQRS;
using Infrastructure.MassTransitBusAdapter;
using System;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using Warehouse.Messages.Commands;
using Warehouse.Messages.Events;
namespace Warehouse.Simulation
{
public class Program
{
// TODO: Move to config file
private const uint NUM_THREADS = 2;
private const string DOMAIN = "WarehouseSimulator";
private const string SERVER_NAME = "localhost";
private static IBus _bus;
static void Main(string[] args)
{
Console.WriteLine("Simulating warehouse activity...");
_bus = new MassTransitBusAdapter(SERVER_NAME, DOMAIN, NUM_THREADS);
const int numberToCreate = 10;
_bus.RegisterEventSubscriber<LocationCreated>((loc) => Console.WriteLine("Location {0} created.", loc.Name));
_bus.RegisterEventSubscriber<InventoryDefinitionCreated>((def) => Console.WriteLine("Inventory definition {0} created.", def.Name));
_bus.RegisterEventSubscriber<InventoryCreated>((inv) => Console.WriteLine("Inventory created."));
// TODO: wait for events has to happen after locations and item definitions are created
var locationCreated = _bus.AsObservable<LocationCreated>()
.Scan(0, (acc, cur) => ++acc)
.Where(x => x == numberToCreate);
var itemDefsCreated = _bus.AsObservable<InventoryDefinitionCreated>()
.Scan(0, (acc, cur) => ++acc)
.Where(x => x == numberToCreate);
locationCreated.Subscribe((x) => Console.WriteLine("All Locations created."));
itemDefsCreated.Subscribe((x) => Console.WriteLine("All item definitions created."));
var createLocations = Enumerable.Range(0, numberToCreate)
.Select(x => new CreateLocation(new Guid(), "Location" + x))
.SendTo(_bus);
var createItemDefs = Enumerable.Range(0, numberToCreate)
.Select(x => new CreateInventoryDefinition(new Guid(), "Item" + x))
.SendTo(_bus);
var warehouseCreated = locationCreated.And(itemDefsCreated).Then((x,y) => x);
var done = Observable.When(warehouseCreated);
done.Subscribe((created) =>
{
Console.WriteLine("Creating inventory at locations.");
var inventory = createLocations.Zip(createItemDefs, (loc, def) => new { loc.LocationId, def.InventoryDefinitionId }) //.Select(loc => loc.LocationId).Zip(createItemDefs.Select(def => def.InventoryDefinitionId)
.Select(x => new CreateInventory(x.LocationId, x.InventoryDefinitionId, 33))
.SendTo(_bus);
});
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}