You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

Imports System
Imports System.Xml
Imports System.Data
'''<summary>Lädt und schreibt Einstellungen in settings file</summary>
Public Class Settings
#Region "Members"
Private _settings As XmlDocument
#End Region
#Region "Constructor"
Public Sub New()
Try
_settings = New XmlDocument
_settings.Load(AppDomain.CurrentDomain.BaseDirectory + "settings.xml")
Catch ex As Exception
Throw ex
End Try
End Sub
#End Region
#Region "Public methods"
'''<summary>Lädt ein Wert für ein setting aus dem config file</summary>
'''<param name="xPath">Der node xPath</param>
'''<param name="attributeName">Attribut name der zurückgegeben werden soll</param>
'''<returns>Der Wert des Attributes</returns>
Public Function GetValueByXPath(ByVal xPath As String, ByVal attributeName As String) As String
Try
Dim node As XmlNode = _settings.SelectSingleNode(xPath)
If Not node Is Nothing Then
'node exisitiert
Return node.Attributes(attributeName).Value
Else
Return ""
End If
Catch ex As Exception
Throw ex
End Try
End Function
'''<summary>Gibt eine Liste aller XmlNodes zurück, welche unter dem angegebenen xPath existieren</summary>
'''<param name="xPath"></param>
'''<returns></returns>
Public Function GetNodeByXPath(ByVal xPath As String) As XmlNode
Try
Return _settings.SelectSingleNode(xPath)
Catch ex As Exception
Throw ex
End Try
End Function
'''<summary>Gibt das SqlTimeout für queries zurück</summary>
'''<returns></returns>
Public Function GetSqlTimeout() As Integer
Try
Return Convert.ToDouble(_settings.SelectSingleNode("root/config/SqlTimeout").Attributes("seconds").InnerText)
Catch ex As Exception
Throw ex
End Try
End Function
#End Region
End Class