private void ThrowIfInvalidCoin(string coin) { if (coin.IsEmpty() || !CoinValidator.IsValid(coin)) { throw new CoinbinException($"{coin} isn't a valid coin"); } }
public DeviceForm(CoinValidator device, ILogger logger) { //Set the associated device this.Device = device; //Set the logger this.logger = logger; InitializeComponent(); }
/// <summary> /// Removes a CoinValidator device from the list of connected devices and closes its form /// </summary> /// <param name="device"></param> public void RemoveDevice(CoinValidator device) { //Find the device in the list of already connected devices var deviceForm = DeviceForms.Where(c => c.Device.SerialNumber == device.SerialNumber).FirstOrDefault(); //If it exists if (deviceForm != null) { //Invoke from UI thread this.Invoke(new Action(() => { //Close the form deviceForm.Close(); })); //And remove it from connected devices list DeviceForms.Remove(deviceForm); } }
} //Quantidade de moedas do conjunto public CoinSet(decimal value, int quantity) { if (!CoinValidator.IsValid(value)) { throw new InvalidCoinValueException(value); } else if (quantity < 0) { throw new InvalidCoinQuantityException(quantity); } else { Value = value; Quantity = quantity; } }
/// <summary> /// Adds a CoinValidator device to the list of connected devices, initailizes and displays its form /// </summary> /// <param name="device">The CoinValidator device to add</param> public void AddDevice(CoinValidator device) { //Find the device in the list of already connected devices var deviceForm = DeviceForms.Where(c => c.Device.SerialNumber == device.SerialNumber).FirstOrDefault(); //If it doesn't exists if (deviceForm == null) { //Invoke from UI thread this.Invoke(new Action(() => { //Initialize and display device form deviceForm = new DeviceForm((CoinValidator)device, logger); deviceForm.MdiParent = this; DeviceForms.Add(deviceForm); deviceForm.Show(); })); } }