Initial commit
This commit is contained in:
81
BMS/Common/Settings.vb
Normal file
81
BMS/Common/Settings.vb
Normal file
@@ -0,0 +1,81 @@
|
||||
Imports System
|
||||
Imports System.Xml
|
||||
Imports System.Data
|
||||
|
||||
Public Class Settings
|
||||
|
||||
#Region "Members"
|
||||
|
||||
Dim _settings As XmlDocument
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "Consts"
|
||||
|
||||
Private Const DSN_DECRYPT_PASSWORD As String = "HutterundMueller"
|
||||
|
||||
#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>Gets the first matching value of a property</summary>
|
||||
'''<param name="propertyName"></param>
|
||||
'''<returns></returns>
|
||||
Public Function GetSettingValue(ByVal propertyName As String) As String
|
||||
Try
|
||||
Dim nodes As XmlNodeList = _settings.GetElementsByTagName(propertyName)
|
||||
If (nodes.Count > 0) Then
|
||||
Return nodes(0).InnerText
|
||||
Else
|
||||
Return ""
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'''<summary>Sets the first matching value of a property</summary>
|
||||
'''<param name="xpath"></param>
|
||||
'''<param name="value"></param>
|
||||
Public Sub SetSettingsValue(ByVal xpath As String, ByVal value As String)
|
||||
Try
|
||||
_settings.SelectSingleNode(xpath).InnerText = value
|
||||
_settings.Save(AppDomain.CurrentDomain.BaseDirectory + "settings.xml")
|
||||
Catch ex As Exception
|
||||
Throw ex
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'''<summary>Return the descripted dsn string</summary>
|
||||
'''<returns></returns>
|
||||
Public Function GetDecryptedDSN() As String
|
||||
Try
|
||||
Dim reader As System.IO.StreamReader
|
||||
Dim s As String
|
||||
|
||||
reader = System.IO.File.OpenText(AppDomain.CurrentDomain.BaseDirectory & "bms_conn.cfg")
|
||||
s = reader.ReadLine
|
||||
|
||||
Return ZpCryptography.DsnCrypto.Decrypt(s, DSN_DECRYPT_PASSWORD)
|
||||
Catch ex As Exception
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
End Class
|
||||
Reference in New Issue
Block a user