/// <summary> /// Adds a Denomination to the currency's list. /// </summary> /// <param name="denom">The denomination to add.</param> public void AddDenomination(Denomination denom) { if (!Denominations.Contains(denom)) { Denominations.Add(denom); } }
/// <summary> /// Initializes a new instance of the Currency class. /// </summary> /// <param name="currency">The currency to copy.</param> public Currency(Currency currency) { RegionInfo = currency.RegionInfo; ExchangeRate = currency.ExchangeRate; IsDefault = currency.IsDefault; IsActive = currency.IsActive; Denominations = new List <Denomination>(); foreach (Denomination denom in currency.Denominations) { Denomination newDenom = new Denomination(denom); AddDenomination(newDenom); } }
/// <summary> /// Parses the response received from the server. /// </summary> protected override void UnpackResponse() { // Clear the list. m_currencies.Clear(); base.UnpackResponse(); // Create the streams we will be reading from. MemoryStream responseStream = new MemoryStream(m_responsePayload); BinaryReader responseReader = new BinaryReader(responseStream, Encoding.Unicode); // Try to unpack the data. try { // Seek past return code. responseReader.BaseStream.Seek(sizeof(int), SeekOrigin.Begin); // Get the count of currencies. ushort currencyCount = responseReader.ReadUInt16(); // Read all the currencies. for (ushort x = 0; x < currencyCount; x++) { // Currency ISO ushort stringLen = responseReader.ReadUInt16(); Currency currency = new Currency(new string(responseReader.ReadChars(stringLen))); // Is Default currency.IsDefault = responseReader.ReadBoolean(); // Is Active currency.IsActive = responseReader.ReadBoolean(); // Denom Count ushort denomCount = responseReader.ReadUInt16(); // Read all the denominations. for (ushort y = 0; y < denomCount; y++) { Denomination denom = new Denomination(); // Denom Id denom.Id = responseReader.ReadInt32(); // Denom Type denom.Type = (DenominationType)Enum.Parse(typeof(DenominationType), responseReader.ReadInt32().ToString(CultureInfo.InvariantCulture)); // Allow Acceptor denom.AllowAcceptor = responseReader.ReadBoolean(); // Is Active denom.IsActive = responseReader.ReadBoolean(); // Denom Name stringLen = responseReader.ReadUInt16(); denom.Name = new string(responseReader.ReadChars(stringLen)); // Denom Value stringLen = responseReader.ReadUInt16(); string tempDec = new string(responseReader.ReadChars(stringLen)); if (!string.IsNullOrEmpty(tempDec)) { denom.Value = decimal.Parse(tempDec, CultureInfo.InvariantCulture); } //Denom order US5380 denom.Order = responseReader.ReadInt16(); currency.AddDenomination(denom); } m_currencies.Add(currency); } } catch (EndOfStreamException e) { throw new MessageWrongSizeException(m_strMessageName, e); } catch (Exception e) { throw new ServerException(m_strMessageName, e); } // Close the streams. responseReader.Close(); }