static void Main(string[] args) { Cook ck = new Cook("Hank"); Cashier csh = new Cashier("Renee"); Waiter w = new Waiter("Bob", ck, csh); Client c = new Client("Fred", w); c.SeMetATable(w); Console.ReadLine(); }
static void Main(string[] args) { //Instanciation du personnel et du client Client fred = new Client("Fred"); Cook hank = new Cook("Hank"); Cashier renee = new Cashier("Renée"); Waiter bob = new Waiter(hank, renee, "Bob"); //Utilisation de la méthode SeatAtTable fred.SeatAtTable(bob); Console.ReadLine(); }
private static void GetOutstandingOrdersAndPay(Cashier cashier) { while (true) { var order = cashier.GetOutstandingOrders().FirstOrDefault(); if (order == null) { continue; } cashier.Pay(order.OrderNumber); Console.WriteLine("Order payed"); } }
static void Main(string[] args) { var bus = new TopicBasedPubSub(); var orderPrinter = new OrderPrinter(); var cashier = new Cashier(bus); var assitantManager = new QueuedHandle <PriceOrder>("AssistantManager", new AssistantManager(bus)); var db = new ConcurrentDictionary <Guid, OrderDocument>(); var jesse = new QueuedHandle <CookFood>("Cook:Jesse", new Cook("Jesse", 600, db, bus)); var walt = new QueuedHandle <CookFood>("Cook:Walt", new Cook("Walt", 700, db, bus)); var gus = new QueuedHandle <CookFood>("Cook:Gus", new Cook("Gus", 1500, db, bus)); var dispatcher = new MoreFairDispatcher <CookFood>("FairDispatcher", new[] { jesse, walt, gus }); var chaosMonkey = new ChaosMonkey <CookFood>(25, 25, dispatcher); var alarmClock = new AlarmClock(bus); var startables = new List <IStartable> { assitantManager, jesse, walt, gus, dispatcher, alarmClock }; var waiter = new Waiter("Heisenberg", bus); var house = new MinionHouse(bus); bus.Subscribe(chaosMonkey); bus.Subscribe(assitantManager); bus.Subscribe(cashier); bus.Subscribe <OrderPlaced>(house); bus.Subscribe <OrderCompleted>(house); bus.Subscribe(orderPrinter); bus.Subscribe(alarmClock); startables.ForEach(x => x.Start()); for (var i = 0; i < 50; i++) { waiter.PlaceOrder(new LineItem("Crystal Meth", 3)); Console.WriteLine("Order placed"); } Console.WriteLine("Getting outstanding orders"); Task.Run(() => GetOutstandingOrdersAndPay(cashier)); Task.Run(() => StartMonitoringQueueDepthsAsync(startables)); StartMonitoringMinionHouseAsync(house).Wait(); }
private static void HandlePays(Cashier cashier) { Task.Run( () => { while (true) { Thread.Sleep(10); var unpaidOrders = cashier.GetOutstandingOrders().ToList(); foreach (var orderId in unpaidOrders) { Console.WriteLine($"paying for {orderId}"); cashier.Pay(orderId); } } }); }
public void ServeFood(Cashier leCaissier) { Console.WriteLine("C'est pas trop tôt, j'avais faim"); leCaissier.Pay(); }
public Waiter(string n, Cook unCuisinier, Cashier leCaissier) : base(n) { this.leCaissier = leCaissier; this.monCuisinier = unCuisinier; }
private static void Main() { var publisher = new TopicBasedPubSub(); var alarmClock = new AlarmClock(publisher); var midgetHouse = new MidgetHouse(publisher); var midgetHouseHandler = new QueuedHandler <Message>("MidgetHouse", midgetHouse); midgetHouse.QueuedHandler = midgetHouseHandler; var cashier = new Cashier(publisher); var cashierQueue = new QueuedHandler <TakePayment>("Cashier", cashier); var assistantManager = new QueuedHandler <PriceOrdered>("AssistantManager", new FuzzyHandler <PriceOrdered>(new AssistantManager(publisher), 0, 20)); var seed = new Random(DateTime.Now.Millisecond); var cook1 = new QueuedHandler <CookFood>( "BogdanQueue", new TTLHandler <CookFood>(new FuzzyHandler <CookFood>(new Cook(seed.Next(1000), publisher), 10, 10))); var cook2 = new QueuedHandler <CookFood>( "RomanQueue", new TTLHandler <CookFood>(new FuzzyHandler <CookFood>(new Cook(seed.Next(1000), publisher), 95, 50))); var cook3 = new QueuedHandler <CookFood>( "WaclawQueue", new TTLHandler <CookFood>(new FuzzyHandler <CookFood>(new Cook(seed.Next(1000), publisher), 10, 20))); var dispatcher = new QueuedHandler <CookFood>( "MFDispatcher", new TTLHandler <CookFood>( new MFDispatcher <CookFood>( new List <QueuedHandler <CookFood> > { cook1, cook2, cook3 }))); StartQueues( new List <IStartable> { assistantManager, cashierQueue, dispatcher, cook1, cook2, cook3, midgetHouseHandler, alarmClock }); StartQueuePrinter( new List <IPrintable> { assistantManager, cashierQueue, dispatcher, cook1, cook2, cook3, midgetHouseHandler }); var waiter = new Waiter(publisher); publisher.Subscribe(dispatcher); publisher.Subscribe(assistantManager); publisher.Subscribe(cashier); publisher.Subscribe(alarmClock); publisher.Subscribe <OrderPlaced>(midgetHouse); PlaceOrders(waiter); HandlePays(cashier); Console.ReadKey(); }
static void Main(string[] args) { var es = new AtomDispatcher(); es.Start("az"); // es.PostMessage(new OrderPlaced(order), "az"); QueuedHandler printOrderHandler = new QueuedHandler(new PrintOrderHandler()); IEventHandler <IEvent> cashier = new Cashier(); QueuedHandler cashierProxy = new QueuedHandler(cashier); var assistingManager = new QueuedHandler(new AssistingManager("Diana")); var cook1 = new QueuedHandler(new TimeToLiveHandler(new Cook("John"))); var cook2 = new QueuedHandler(new TimeToLiveHandler(new Cook("Peter"))); var cook3 = new QueuedHandler(new TimeToLiveHandler(new Cook("Gregory"))); var betterHandler = new QueuedHandler(new Dropper(new TimeToLiveHandler(new BetterDispatcher(new[] { cook1, cook2, cook3 })))); TelephoneOperator telephoneOperator = new TelephoneOperator("PhoneMan"); Waiter waiter = new Waiter("Georgie"); var house = new MidgetHouse(Dispatcher.Instance); var houseQueue = new QueuedHandler(house); var clock = new AlarmClock(); Dispatcher.Instance.Subscribe(typeof(OrderPlaced), houseQueue); Dispatcher.Instance.Subscribe(typeof(FoodCooked), houseQueue); Dispatcher.Instance.Subscribe(typeof(OrderPriced), houseQueue); Dispatcher.Instance.Subscribe(typeof(PaymentTaken), houseQueue); Dispatcher.Instance.Subscribe(typeof(FirstCookRetry), houseQueue); Dispatcher.Instance.Subscribe(typeof(SecondCookRetry), houseQueue); Dispatcher.Instance.Subscribe(typeof(CookFood), betterHandler); Dispatcher.Instance.Subscribe(typeof(PriceOrder), assistingManager); Dispatcher.Instance.Subscribe(typeof(TakePayment), cashierProxy); Dispatcher.Instance.Subscribe(typeof(PrintOrder), printOrderHandler); Dispatcher.Instance.Subscribe(typeof(SendToMeIn), clock); IEnumerable <QueuedHandler> allHandlers = new List <QueuedHandler> { houseQueue, betterHandler, cashierProxy, assistingManager, cook1, cook2, cook3, printOrderHandler }; Monitor monitor = new Monitor(allHandlers, new [] { house }); monitor.Start(); foreach (IStartable handler in allHandlers) { handler.Start(); } clock.Start(); //waiter.PlaceOrder(new List<int> { 1, 2 }); //telephoneOperator.PlaceOrder(new List<int> { 1, 2 }); return; for (int i = 0; i < 1000; i++) { waiter.PlaceOrder(new List <int> { 1, 2 }); if (i % 3 == 0) { Thread.Sleep(50); telephoneOperator.PlaceOrder(new List <int> { 1, 2 }); } Thread.Sleep(50); } while (true) { foreach (string orderId in ((Cashier)cashier).GetOutstandingOrders()) { Console.WriteLine("Got outstanding order to pay, id " + orderId); ((Cashier)cashier).Pay(orderId, "123456"); } Thread.Sleep(1); } //Console.ReadLine(); }
private static void Main(string[] args) { var dispatcher = new Dispatcher(); var waiter = new Waiter(dispatcher); var assistant = new AssistantManager(dispatcher); var cashier = new Cashier(dispatcher); var timer = new TimerHandler(dispatcher); var house = new RunnerHouse(dispatcher); var serialHouse = new ThreadedHandler <Event>( "House", house); // set up the kitchen var cookedOrders = new ConcurrentDictionary <Guid, bool>(); var cooks = new List <Cook> { new Cook("James", 100, cookedOrders, dispatcher), new Cook("Emily", 50, cookedOrders, dispatcher), new Cook("Sarah", 500, cookedOrders, dispatcher) }; var threadedCooks = cooks.Select(c => new ThreadedHandler <CookFood>(c.Name, c)).ToList(); var kitchen = new ThreadedHandler <CookFood>( "Kitchen", new ScrewUp <CookFood>( new MorefairDispatcher <CookFood>( threadedCooks))); var numCompleted = 0; var numFailedImmediately = 0; var numFailedAfterRetry = 0; var numSucceededImmediately = 0; var numSucceededAfterRetry = 0; var onCompleted = new ThreadedHandler <OrderCompleted>( "OnCompleted", new Handler <OrderCompleted>(e => { numCompleted++; if (e.Success && e.Retried) { numSucceededAfterRetry++; } if (e.Success && !e.Retried) { numSucceededImmediately++; } if (!e.Success && e.Retried) { numFailedAfterRetry++; } if (!e.Success && !e.Retried) { numFailedImmediately++; } })); // subscribe everything dispatcher.Subscribe(kitchen); dispatcher.Subscribe(assistant); dispatcher.Subscribe(cashier); dispatcher.Subscribe(serialHouse); dispatcher.Subscribe(timer); dispatcher.Subscribe(onCompleted); // subscribe various printers //dispatcher.Subscribe(new Handler<CookFood>(e => Console.WriteLine($"{e.CorrelationId} Command: CookFood"))); //dispatcher.Subscribe(new Handler<PriceOrder>(e => Console.WriteLine($"{e.CorrelationId} Command: PriceOrder"))); //dispatcher.Subscribe(new Handler<TakePayment>(e => Console.WriteLine($"{e.CorrelationId} Command: TakePayment"))); //dispatcher.Subscribe(new Handler<PrintOrder>(e => Console.WriteLine($"{e.CorrelationId} Command: PrintOrder"))); //dispatcher.Subscribe(new Handler<Callback>(e => Console.WriteLine($"{e.CorrelationId} Command: Callback"))); //dispatcher.Subscribe(new Handler<OrderPlaced>(e => Console.WriteLine($"{e.CorrelationId} Ordered"))); //dispatcher.Subscribe(new Handler<FoodCooked>(e => Console.WriteLine($"{e.CorrelationId} Cooked"))); //dispatcher.Subscribe(new Handler<OrderPriced>(e => Console.WriteLine($"{e.CorrelationId} Priced"))); //dispatcher.Subscribe(new Handler<OrderPaid>(e => Console.WriteLine($"{e.CorrelationId} Paid"))); //dispatcher.Subscribe(new Handler<OrderCompleted>(e => Console.WriteLine($"{e.CorrelationId} OrderCompleted"))); //dispatcher.Subscribe(new Handler<CookFoodCalledBack>(e => Console.WriteLine($"{e.CorrelationId} CookFoodCalledBack"))); //dispatcher.Subscribe(new Handler<FailedToContactTheKitchen>(e => Console.WriteLine($"{e.CorrelationId} Failed"))); // start everything serialHouse.Start(); kitchen.Start(); foreach (var cook in threadedCooks) { cook.Start(); } onCompleted.Start(); var numOrders = 300; for (var i = 0; i < numOrders; i++) { waiter.PlaceOrder("Toby", 1, new List <Tuple <string, int> > { Tuple.Create("Meat", 2), Tuple.Create("Veg", 1) }); } Action print = () => { Console.WriteLine($"-----------------------------------------"); Console.WriteLine($"{kitchen.Name}: {kitchen.Count}"); foreach (var cook in threadedCooks) { Console.WriteLine($"{cook.Name}: {cook.Count}"); } Console.WriteLine($"{onCompleted.Name}: {onCompleted.Count}"); Console.WriteLine($"Timer {timer.Count}"); Console.WriteLine($"Runners {house.CountRunners}"); Console.WriteLine($"num Failed Immediately {numFailedImmediately}"); Console.WriteLine($"num Failed AfterRetry {numFailedAfterRetry}"); Console.WriteLine($"num Succeeded Immediately {numSucceededImmediately}"); Console.WriteLine($"num Succeeded AfterRetry {numSucceededAfterRetry}"); Console.WriteLine($"Complete {numCompleted}/{numOrders}"); Thread.Sleep(1000); }; while (numCompleted < numOrders) { print(); } print(); Console.WriteLine("All done"); }