|
''' <summary>
''' An convertor used to convert money instances from one currency to another.
''' </summary>
''' <remarks></remarks>
Public Class WebserviceXConvertor
Implements Hybrid.IMoneyConversionProvider
''' <summary>
''' Converts a money instance to another instance of the specified region.
''' </summary>
''' <param name="moneyFrom">Money instance that needs to be converted.</param>
''' <param name="toRegion">Region that the money needs to be converted to.</param>
''' <returns>New money instance containing the toRegion and the converted value.</returns>
''' <remarks>Uses the following WebService to perform the conversion. http://www.webservicex.net/CurrencyConvertor.asmx?WSDL</remarks>
''' <exception cref="ConversionFailedException">Thrown whenever the Web Service fails to return a converted value. See the inner exception for full details of cause.</exception>
Public Function Convert(ByVal moneyFrom As Money, ByVal toRegion As System.Globalization.RegionInfo) As Money Implements IMoneyConversionProvider.Convert
Dim x As New Convertor.CurrencyConvertor
Try
Dim e1 As Convertor.Currency
Dim e2 As Convertor.Currency
If [Enum].IsDefined(GetType(Convertor.Currency), moneyFrom.Region.ISOCurrencySymbol) Then
e1 = [Enum].Parse(GetType(Convertor.Currency), moneyFrom.Region.ISOCurrencySymbol)
End If
If [Enum].IsDefined(GetType(Convertor.Currency), toRegion.ISOCurrencySymbol) Then
e2 = [Enum].Parse(GetType(Convertor.Currency), toRegion.ISOCurrencySymbol)
End If
Dim rate As Double = x.ConversionRate(e1, e2)
Return New Hybrid.Money(moneyFrom.Value * rate, toRegion)
Catch ex As Exception
Throw New ConversionFailedException(ex)
End Try
End Function
End Class
''' <summary>
''' Represents errors that occur during conversion of Money instances using a WebService.
''' </summary>
''' <remarks></remarks>
Public Class ConversionFailedException
Inherits ApplicationException
Public Sub New(ByVal innerException As Exception)
MyBase.New("Failed to convert money value.", innerException)
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.