コード例 #1
0
ファイル: factory.cs プロジェクト: quooston/btw-samples
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: FactoryState.cs プロジェクト: PeddleM/btw-samples
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public void When(ShipmentUnpackedInCargoBay e)
 {
     Factories[e.Id].PartsInCargoBay -= e.InventoryShipments.Sum(s => s.Cargo.Sum(p => p.Quantity));
 }