//=========This facade using Hardware settings and the CoinKinds list
 public PaymentFacade(HardwareFacade hardware, List <Cents> newCoinKinds)
 {
     this.Hardware  = hardware;
     this.coinKinds = newCoinKinds;
     funds          = new Cents(0);                                                    //initialize funds, funds is the amount of coins that inside the vending machine
     Hardware.CoinSlot.CoinAccepted += new EventHandler <CoinEventArgs>(coinAccepted); //Coin accepted event
 }
    /**
     * Creates a standard arrangement for the vending machine. All the
     * components are created and interconnected. The hardware is initially
     * empty. The product kind names and costs are initialized to &quot; &quot;
     * and 1 respectively.
     *
     * @param coinKinds
     *            The values (in cents) of each kind of coin. The order of the
     *            kinds is maintained. One coin rack is produced for each kind.
     *            Each kind must have a unique, positive value.
     * @param selectionButtonCount
     *            The number of selection buttons on the machine. Must be
     *            positive.
     * @param coinRackCapacity
     *            The maximum capacity of each coin rack in the machine. Must be
     *            positive.
     * @param productRackCapacity
     *            The maximum capacity of each product rack in the machine. Must
     *            be positive.
     * @param receptacleCapacity
     *            The maximum capacity of the coin receptacle, storage bin, and
     *            delivery chute. Must be positive.
     * @throws IllegalArgumentException
     *             If any of the arguments is null, or the size of productCosts
     *             and productNames differ.
     */
    public VendingMachine(Cents[] coinKinds, int selectionButtonCount, int coinRackCapacity, int productRackCapacity, int receptacleCapacity)
    {
        this.hardwareFacade = new HardwareFacade(coinKinds, selectionButtonCount, coinRackCapacity, productRackCapacity, receptacleCapacity);

        /* YOU CAN BUILD AND INSTALL THE HARDWARE HERE */
        this.hl = new BusinessLogic(this.hardwareFacade);
    }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hardware"></param>
        /// <returns>A tuple: [value of coins], [array of product names]</returns>
        public static Tuple <int, string[]> ExtractDelivery(HardwareFacade hardware)
        {
            var items    = hardware.DeliveryChute.RemoveItems();
            var cents    = items.OfType <Coin>().Sum(coin => coin.Value.Value);
            var products = items.OfType <Product>().Select(product => product.Name).ToArray();

            return(new Tuple <int, string[]>(cents, products));
        }
Beispiel #4
0
 //=========This facade using Hardware settings
 public CommunicationFacade(HardwareFacade hardware)
 {
     this.Hardware = hardware;
     for (int i = 0; i < Hardware.SelectionButtons.Count(); i++)
     {
         Hardware.SelectionButtons[i].Pressed += new EventHandler(notifyButtonPressed);
     }
 }
Beispiel #5
0
 /**
  * Creates a standard arrangement for the vending machine. All the
  * components are created and interconnected. The hardware is initially
  * empty. The product kind names and costs are initialized to &quot; &quot;
  * and 1 respectively.
  *
  * @param coinKinds
  *            The values (in cents) of each kind of coin. The order of the
  *            kinds is maintained. One coin rack is produced for each kind.
  *            Each kind must have a unique, positive value.
  * @param selectionButtonCount
  *            The number of selection buttons on the machine. Must be
  *            positive.
  * @param coinRackCapacity
  *            The maximum capacity of each coin rack in the machine. Must be
  *            positive.
  * @param productRackCapacity
  *            The maximum capacity of each product rack in the machine. Must
  *            be positive.
  * @param receptacleCapacity
  *            The maximum capacity of the coin receptacle, storage bin, and
  *            delivery chute. Must be positive.
  * @throws IllegalArgumentException
  *             If any of the arguments is null, or the size of productCosts
  *             and productNames differ.
  */
 public VendingMachine(Cents[] coinKinds, int selectionButtonCount, int coinRackCapacity, int productRackCapacity, int receptacleCapacity)
 {
     this.hardwareFacade      = new HardwareFacade(coinKinds, selectionButtonCount, coinRackCapacity, productRackCapacity, receptacleCapacity);
     this.communicationFacade = new CommunicationFacade(this.Hardware);
     this.paymentFacade       = new PaymentFacade(this.Hardware, coinKinds.ToList());
     this.productFacade       = new ProductFacade(this.Hardware);
     this.businessRule        = new BusinessRule(communicationFacade, paymentFacade, productFacade);
 }
Beispiel #6
0
 public CommsFacade(HardwareFacade hardware)
 {
     hardwareFacade = hardware;
     foreach (var button in this.hardwareFacade.SelectionButtons)
     {
         button.Pressed += new EventHandler(ButtonPress);
     }
 }
 public ProductFacade(HardwareFacade hardware)
 {
     this.Hardware = hardware;
     for (int i = 0; i < Hardware.ProductRacks.Count(); i++)
     {
         Hardware.ProductRacks[i].ProductAdded += new EventHandler <ProductEventArgs>(notifyProductsAdded);
     }
 }
Beispiel #8
0
    /**
     * Creates a standard arrangement for the vending machine. All the
     * components are created and interconnected. The hardware is initially
     * empty. The product kind names and costs are initialized to &quot; &quot;
     * and 1 respectively.
     *
     * @param coinKinds
     *            The values (in cents) of each kind of coin. The order of the
     *            kinds is maintained. One coin rack is produced for each kind.
     *            Each kind must have a unique, positive value.
     * @param selectionButtonCount
     *            The number of selection buttons on the machine. Must be
     *            positive.
     * @param coinRackCapacity
     *            The maximum capacity of each coin rack in the machine. Must be
     *            positive.
     * @param productRackCapacity
     *            The maximum capacity of each product rack in the machine. Must
     *            be positive.
     * @param receptacleCapacity
     *            The maximum capacity of the coin receptacle, storage bin, and
     *            delivery chute. Must be positive.
     * @throws IllegalArgumentException
     *             If any of the arguments is null, or the size of productCosts
     *             and productNames differ.
     */
    public VendingMachine(Cents[] coinKinds, int selectionButtonCount, int coinRackCapacity, int productRackCapacity, int receptacleCapacity)
    {
        this.hardwareFacade = new HardwareFacade(coinKinds, selectionButtonCount, coinRackCapacity, productRackCapacity, receptacleCapacity);

        CommunicationFacade cf  = new CommunicationFacade(this.hardwareFacade);
        ProductFacade       prf = new ProductFacade(this.hardwareFacade);
        PaymentFacade       paf = new PaymentFacade(this.hardwareFacade);

        BuisnessRule br = new BuisnessRule(cf, prf, paf);
    }
Beispiel #9
0
    public ProductFacade(HardwareFacade hf)
    {
        this.hf = hf;

        this.selectionButtonToIndex = new Dictionary <SelectionButton, int>();
        for (int i = 0; i < this.hf.SelectionButtons.Length; i++)
        {
            this.selectionButtonToIndex[this.hf.SelectionButtons[i]] = i;
        }
    }
Beispiel #10
0
    /**
     * Creates a standard arrangement for the vending machine. All the
     * components are created and interconnected. The hardware is initially
     * empty. The product kind names and costs are initialized to &quot; &quot;
     * and 1 respectively.
     *
     * @param coinKinds
     *            The values (in cents) of each kind of coin. The order of the
     *            kinds is maintained. One coin rack is produced for each kind.
     *            Each kind must have a unique, positive value.
     * @param selectionButtonCount
     *            The number of selection buttons on the machine. Must be
     *            positive.
     * @param coinRackCapacity
     *            The maximum capacity of each coin rack in the machine. Must be
     *            positive.
     * @param productRackCapacity
     *            The maximum capacity of each product rack in the machine. Must
     *            be positive.
     * @param receptacleCapacity
     *            The maximum capacity of the coin receptacle, storage bin, and
     *            delivery chute. Must be positive.
     * @throws IllegalArgumentException
     *             If any of the arguments is null, or the size of productCosts
     *             and productNames differ.
     */
    public VendingMachine(Cents[] coinKinds, int selectionButtonCount, int coinRackCapacity, int productRackCapacity, int receptacleCapacity)
    {
        this.hardwareFacade = new HardwareFacade(coinKinds, selectionButtonCount, coinRackCapacity, productRackCapacity, receptacleCapacity);

        this.paymentFacade = new PaymentFacade(this.hardwareFacade);
        this.commFacade    = new CommsFacade(this.hardwareFacade);
        this.productFacade = new ProductFacade(this.hardwareFacade);
        this.businessRule  = new BusinessRule(this.paymentFacade, this.productFacade, this.commFacade);
        /* YOU CAN BUILD AND INSTALL THE HARDWARE HERE */
    }
Beispiel #11
0
    public PaymentFacade(HardwareFacade hf)
    {
        this.hf = hf;

        this.productCost    = new Cents(0);
        this.availableFunds = new Cents(0);
        this.changeNeeded   = new Cents(0);
        this.credit         = new Cents(0);

        hf.CoinSlot.CoinAccepted += new EventHandler <CoinEventArgs>(insertSuccessful);
    }
Beispiel #12
0
 public void Initialize()
 {
     this.vm = new VendingMachine(new Cents[] { new Cents(5), new Cents(10), new Cents(25), new Cents(100) }, 3, 10, 10, 10);
     vm.Configure(new List <ProductKind>()
     {
         new ProductKind("Coke", new Cents(250)),
         new ProductKind("water", new Cents(250)),
         new ProductKind("stuff", new Cents(205))
     });
     this.hardware = vm.Hardware;
     this.hardware.LoadCoins(new int[] { 1, 1, 2, 0 });
     this.hardware.LoadProducts(new int[] { 1, 1, 1 });
 }
    // SETUP

    public ProductFacade(HardwareFacade hardwarefacade)
    {
        this.hw = hardwarefacade;

        // SUBSCRIBE to events relevant to this Facade

        // Subscribe to all the selection buttons
        this.selectionButtonToIndex = new Dictionary <SelectionButton, int>();
        for (int i = 0; i < this.hw.SelectionButtons.Length; i++)
        {
            this.hw.SelectionButtons[i].Pressed += new EventHandler(selectButtonPressed);
            this.selectionButtonToIndex[this.hw.SelectionButtons[i]] = i;
        }
    }
Beispiel #14
0
        public PaymentFacade(HardwareFacade hardware)
        {
            this.hardware  = hardware;
            availableFunds = 0;
            credit         = new Cents(0);

            this.hardware.CoinSlot.CoinAccepted += new EventHandler <CoinEventArgs>(InsertCoin);

            this.coinKindToCoinRackIndex = new Dictionary <Cents, int>();
            for (int i = 0; i < this.hardware.CoinRacks.Length; i++)
            {
                this.coinKindToCoinRackIndex[this.hardware.GetCoinKindForCoinRack(i)] = i;
            }
        }
    // This class talks to the facades
    public BusinessLogic(HardwareFacade hardwareFacade)
    {
        // Create Facades and pass the hardware facade to them so that they can subscribe to appropriate events
        this.payment = new PaymentFacade(hardwareFacade);
        this.comms   = new CommunicationFacade(hardwareFacade);
        this.prod    = new ProductFacade(hardwareFacade);

        // Detect if a selection was made
        this.comms.SelectionMade += new EventHandler <SelectionEventArgs>(initiate);

        // Detect errors from payment and product and pass it to the comms facade
        this.payment.error += new EventHandler <ErrorEventArgs>(sendError);
        this.prod.error    += new EventHandler <ErrorEventArgs>(sendError);
    }
Beispiel #16
0
    public CommunicationFacade(HardwareFacade hf)
    {
        this.hf = hf;
        foreach (ProductRack pr in this.hf.ProductRacks)
        {
            pr.ProductRemoved   += new EventHandler <ProductEventArgs>(ProductVendedHandler);
            pr.ProductRackEmpty += new EventHandler(OutOfStockHandler);
        }

        this.selectionButtonToIndex = new Dictionary <SelectionButton, int>();
        for (int i = 0; i < this.hf.SelectionButtons.Length; i++)
        {
            this.hf.SelectionButtons[i].Pressed += new EventHandler(SelectionMadeHandler);
            this.selectionButtonToIndex[this.hf.SelectionButtons[i]] = i;
        }
    }
Beispiel #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hardware"></param>
        /// <returns>A tuple: [value of coins in coinracks], [value of coins in storagebin], [array of product names remaining]</returns>
        public static Tuple <int, int, string[]> Unload(HardwareFacade hardware)
        {
            int centsInCoinRacks = 0;

            foreach (var coinRack in hardware.CoinRacks)
            {
                centsInCoinRacks += coinRack.Unload().Sum(coin => coin.Value.Value);
            }
            var centsInStorageBin = hardware.StorageBin.Unload().Sum(coin => coin.Value.Value);
            var remainingProducts = new List <Product>();

            foreach (var pr in hardware.ProductRacks)
            {
                remainingProducts.AddRange(pr.Unload());
            }

            return(new Tuple <int, int, string[]>(centsInCoinRacks, centsInStorageBin, remainingProducts.Select(product => product.Name).ToArray()));
        }
    // SETUP

    public CommunicationFacade(HardwareFacade hardwarefacade)
    {
        this.hw = hardwarefacade;

        // SUBSCRIBE to events relevant to this Facade

        // Subscribe to Accepted coin events
        this.hw.CoinSlot.CoinAccepted += new EventHandler <CoinEventArgs>(updateCurrentBalance);

        // Subscribe to all the selection buttons
        this.selectionButtonToIndex = new Dictionary <SelectionButton, int>();
        for (int i = 0; i < this.hw.SelectionButtons.Length; i++)
        {
            this.hw.SelectionButtons[i].Pressed += new EventHandler(selectButtonPressed);
            this.selectionButtonToIndex[this.hw.SelectionButtons[i]] = i;
        }

        // Subscribe to machine status events
        this.hw.OutOfOrderLight.Activated   += new EventHandler(setMachineNotActive);
        this.hw.OutOfOrderLight.Deactivated += new EventHandler(setMachineActive);
    }
    // SETUP

    public PaymentFacade(HardwareFacade hardwarefacade)
    {
        this.hw = hardwarefacade;

        // SUBSCRIBE to events relevant to this Facade

        // Subscribe to Accepted coin events
        this.hw.CoinSlot.CoinAccepted += new EventHandler <CoinEventArgs>(updateCurrentBalance);

        // Subscribe to all the selection buttons
        this.selectionButtonToIndex = new Dictionary <SelectionButton, int>();
        for (int i = 0; i < this.hw.SelectionButtons.Length; i++)
        {
            this.hw.SelectionButtons[i].Pressed += new EventHandler(selectButtonPressed);
            this.selectionButtonToIndex[this.hw.SelectionButtons[i]] = i;
        }

        // Setup all the coins racks value to their index to be used in DispenseChange()
        this.coinKindToCoinRackIndex = new Dictionary <int, int>();
        for (int i = 0; i < this.hw.CoinRacks.Length; i++)
        {
            this.coinKindToCoinRackIndex[this.hw.GetCoinKindForCoinRack(i).Value] = i;
        }
    }
Beispiel #20
0
 public ProductFacade(HardwareFacade hardware)
 {
     this.hardware = hardware;
 }
Beispiel #21
0
        public void Initialize()
        {
            VendingMachine vm = new VendingMachine(new Cents[] { new Cents(5), new Cents(10), new Cents(25), new Cents(100) }, 3, 10, 10, 10);

            this.hardware = vm.Hardware;
        }