-
Notifications
You must be signed in to change notification settings - Fork 3
/
Chef.cs
46 lines (42 loc) · 1.62 KB
/
Chef.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
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
namespace ClassLibrary4
{
public class Chef : Handles<Messages.PrepareFood>
{
static readonly Random random = new Random();
private static readonly IDictionary<string, string[]> BullshitRecipeDatabase = new Dictionary<string, string[]>
{
{"Pizza", new[]{"Ketchup", "Dough", "Pepperoni"}},
{"Miguitas", new[]{"Tortillas", "Ketchup", "Weenies"}},
{"Chicharron", new[]{"Skin", "Salsa Verde", "Cilantro"}}
};
private readonly IPublishEvents next;
private readonly double efficiency;
private readonly string name;
public Chef(IPublishEvents next, string name, double efficiency = 1)
{
this.next = next;
this.efficiency = efficiency;
this.name = name;
}
public void Handle(Messages.PrepareFood message)
{
foreach (var item in message.Order.Items)
{
item.Ingredients = BullshitRecipeDatabase[item.Plate];
}
var cookTime = TimeSpan.FromSeconds(random.NextDouble() / efficiency);
Thread.Sleep(cookTime);
message.Order.CookedOn = DateTime.UtcNow;
message.Order.Chef = name;
next.Publish(new Messages.FoodPrepared(message.Order, message.CorrelationId, message.MessageId, message.TimeToLive));
}
public override string ToString()
{
return "Chef " + name;
}
}
}