void AnnounceInsideFactory(ShipmentUnpackedInCargoBay theEvent) { // The Factory uses a Dictionary<string, int> InventoryOfPartsOnShelf // to track all of its inventory of parts // loop through all inventoryItems that were unpacked and add to official inventory foreach (var inventoryItem in theEvent.ItemsUnpackedAndInventoried) { // See if this type of item is already in the Inventory System if (InventoryOfPartsOnShelf.ContainsKey(inventoryItem.Key)) { // this item type is already known in the inventory system, just change quantity InventoryOfPartsOnShelf[inventoryItem.Key] = InventoryOfPartsOnShelf[inventoryItem.Key] + inventoryItem.Value; } else { // brand new Inventory Item, add it to the Inventory System InventoryOfPartsOnShelf.Add(inventoryItem.Key, inventoryItem.Value); } } // Rule: All Shipments in the CargoBay are deemed unpacked and inventoried when this Event happens // So set the number of Shipments in the CargoBay to "0" by clearning the list. ShipmentsWaitingToBeUnpacked.Clear(); // Rule: an Employee can only unpack all Shipments in the cargo bay once a day // so remember who just did it EmployeesWhoHaveUnpackedCargoBayToday.Add(theEvent.EmployeeName); }
public static string Message(ShipmentUnpackedInCargoBay e) { var builder = new StringBuilder(); builder.AppendFormat("{0} unload:", e.EmployeeName).AppendLine(); foreach (var inventoryShipment in e.InventoryShipments) { builder.AppendFormat("\tshipment name '{0}' and parts:\r\n", inventoryShipment.Name); foreach (var carPart in inventoryShipment.Cargo) builder.AppendFormat("\t\t{0} {1} pcs", carPart.Name, carPart.Quantity).AppendLine(); } return builder.ToString(); }
public void When(ShipmentUnpackedInCargoBay theEvent) { foreach (var shipmentInCargoBay in theEvent.InventoryShipments) { ShipmentsWaitingToBeUnpacked.Remove(shipmentInCargoBay.Name); foreach (var part in shipmentInCargoBay.Cargo) { if (!_availableParts.ContainsKey(part.Name)) _availableParts.Add(part.Name, part.Quantity); else _availableParts[part.Name] += part.Quantity; } } // Rule: an Employee can only unpack shipments in the cargo bay once a day // so remember who just did it EmployeesWhoHaveUnpackedCargoBayToday.Add(theEvent.EmployeeName); }
public void When(ShipmentUnpackedInCargoBay theEvent) { foreach (var shipmentInCargoBay in theEvent.InventoryShipments) { ShipmentsWaitingToBeUnpacked.Remove(shipmentInCargoBay.Name); foreach (var part in shipmentInCargoBay.Cargo) { if (!_availableParts.ContainsKey(part.Name)) { _availableParts.Add(part.Name, part.Quantity); } else { _availableParts[part.Name] += part.Quantity; } } } // Rule: an Employee can only unpack shipments in the cargo bay once a day // so remember who just did it EmployeesWhoHaveUnpackedCargoBayToday.Add(theEvent.EmployeeName); }
public void When(ShipmentUnpackedInCargoBay e) { Factories[e.Id].PartsInCargoBay -= e.InventoryShipments.Sum(s => s.Cargo.Sum(p => p.Quantity)); }