MS
This commit is contained in:
179
app/VERSION_CHECKER/ModuleMySettings.vb
Normal file
179
app/VERSION_CHECKER/ModuleMySettings.vb
Normal file
@@ -0,0 +1,179 @@
|
||||
Imports System.IO
|
||||
Imports System.Xml
|
||||
Imports DD_LIB_Standards
|
||||
Module ModuleMySettings
|
||||
Public PATH_FileExclusions As String = Path.Combine(Application.UserAppDataPath(), "FileExclusions.xml")
|
||||
Dim ConfigPath As String = Path.Combine(Application.UserAppDataPath(), "UserConfig.xml")
|
||||
|
||||
Public DTEXCLUDE_FILES As DataTable
|
||||
Public USER_USERNAME As String = ""
|
||||
Public USER_GUID As Integer
|
||||
|
||||
Public MyConnectionString As String = ""
|
||||
Public MyServer_UpdatePath As String = ""
|
||||
Public VERSION_SERVER As String = ""
|
||||
Public VERSION_USER As String = "1.0.0.0"
|
||||
Public FOLDER_TEMP As String
|
||||
Public LogErrorsOnly As Boolean = True
|
||||
|
||||
Public Function LoadFileExclusion()
|
||||
Dim rowresult As String = ""
|
||||
Try
|
||||
'if file doesn't exist, create the file with its default xml table
|
||||
If Not File.Exists(path_FileExclusions) Then
|
||||
DTEXCLUDE_FILES = CreateExclusionTable()
|
||||
DTEXCLUDE_FILES.WriteXml(path_FileExclusions)
|
||||
End If
|
||||
DTEXCLUDE_FILES = GetTablefromXML(PATH_FileExclusions)
|
||||
|
||||
'For Each Row As DataRow In DT.Rows
|
||||
' rowresult &= Row.Item("FILE_CONTAIN")
|
||||
' Select Case Row.Item("FILE_CONTAIN")
|
||||
|
||||
' End Select
|
||||
|
||||
'Next
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in LoadFileExclusion" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
|
||||
End Function
|
||||
Private Function CreateExclusionTable() As DataTable
|
||||
Try
|
||||
' Create sample Customers table, in order
|
||||
' to demonstrate the behavior of the DataTableReader.
|
||||
Dim table As New DataTable
|
||||
table.TableName = "TBEXCLUSION"
|
||||
|
||||
' Create two columns, ID and Name.
|
||||
table.Columns.Add("FILE_CONTAIN", GetType(System.String))
|
||||
Dim newRow As DataRow = table.NewRow()
|
||||
newRow("FILE_CONTAIN") = "Thumbs"
|
||||
table.Rows.Add(newRow)
|
||||
Dim newRow1 As DataRow = table.NewRow()
|
||||
newRow1("FILE_CONTAIN") = "\~$"
|
||||
table.Rows.Add(newRow1)
|
||||
Dim newRow2 As DataRow = table.NewRow()
|
||||
newRow2("FILE_CONTAIN") = ".db"
|
||||
table.Rows.Add(newRow2)
|
||||
Dim newRow3 As DataRow = table.NewRow()
|
||||
newRow3("FILE_CONTAIN") = "desktop.ini"
|
||||
table.Rows.Add(newRow3)
|
||||
table.AcceptChanges()
|
||||
Return table
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in CreateExclusionTable" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
Public Function MySettings_Load()
|
||||
Try
|
||||
Dim rowresult As String = ""
|
||||
Dim DT As DataTable
|
||||
ConfigPath = ConfigPath.Replace("VERSION_CHECKER\VersionCheck", "Digital Data\ADDI - Akte der Dinge")
|
||||
'if file doesn't exist, create the file with its default xml table
|
||||
If Not File.Exists(ConfigPath) Then
|
||||
Return False
|
||||
End If
|
||||
DT = GetTablefromXML(ConfigPath)
|
||||
If DT Is Nothing Then
|
||||
MsgBox("Configuration could not be loaded!! Check LogFile!", MsgBoxStyle.Critical)
|
||||
Return False
|
||||
End If
|
||||
For Each Row As DataRow In DT.Rows
|
||||
rowresult &= Row.Item("ConfigName")
|
||||
Select Case Row.Item("ConfigName")
|
||||
Case "MyConnectionString"
|
||||
Dim connstring As String
|
||||
'Den ConnectonString mit verschlüsseltem PW laden
|
||||
Dim csb As New SqlClient.SqlConnectionStringBuilder
|
||||
csb.ConnectionString = Row.Item("Value")
|
||||
If Not csb.ConnectionString = "" Then
|
||||
If csb.ConnectionString.Contains("Password=") Then
|
||||
'sa-
|
||||
'Jetzt das Passwort entschlüsseln
|
||||
Dim PWplainText As String
|
||||
Dim wrapper As New clsEncryption("!35452didalog=")
|
||||
' DecryptData throws if the wrong password is used.
|
||||
Try
|
||||
PWplainText = wrapper.DecryptData(csb.Password)
|
||||
connstring = Row.Item("Value").ToString.Replace(csb.Password, PWplainText)
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add("- the Password '" & csb.Password & "' could not be decrypted", False)
|
||||
connstring = ""
|
||||
End Try
|
||||
|
||||
Else
|
||||
'Windows-Auth
|
||||
connstring = Row.Item("Value").ToString
|
||||
End If
|
||||
|
||||
MyConnectionString = connstring
|
||||
Else
|
||||
MyConnectionString = ""
|
||||
End If
|
||||
Case "LogErrorsOnly"
|
||||
LogErrorsOnly = CBool(Row.Item("Value"))
|
||||
clsCURRENT.LOG_ERRORS_ONLY = LogErrorsOnly
|
||||
End Select
|
||||
Next
|
||||
LoadFileExclusion()
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in LoadMyConfig" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
ClassLogger.Add("Error in LoadMyConfig: " & ex.Message, True)
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
|
||||
End Function
|
||||
Private Function GetTablefromXML(path As String)
|
||||
Try
|
||||
Dim DS As New DataSet
|
||||
DS.ReadXml(path)
|
||||
Return DS.Tables(0)
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in GetTablefromXML" & vbNewLine & ex.Message & vbNewLine & "ConfigPath: " & vbNewLine & path, MsgBoxStyle.Critical)
|
||||
ClassLogger.Add("Error in GetTablefromXML: " & ex.Message, True)
|
||||
ClassLogger.Add(">> ConfigPath: " & ConfigPath, False)
|
||||
Return Nothing
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
Private Function CreateConfigTable() As DataTable
|
||||
Try
|
||||
' Create sample Customers table, in order
|
||||
' to demonstrate the behavior of the DataTableReader.
|
||||
Dim table As New DataTable
|
||||
table.TableName = "MyConfig"
|
||||
|
||||
' Create two columns, ID and Name.
|
||||
Dim idColumn As DataColumn = table.Columns.Add("ID", _
|
||||
GetType(System.Int32))
|
||||
|
||||
idColumn.AutoIncrement = True
|
||||
idColumn.AutoIncrementSeed = 0
|
||||
idColumn.AutoIncrementStep = 1
|
||||
table.Columns.Add("ConfigName", GetType(System.String))
|
||||
table.Columns.Add("Value", GetType(System.String))
|
||||
'Set the ID column as the primary key column.
|
||||
table.PrimaryKey = New DataColumn() {idColumn}
|
||||
Dim newRow As DataRow = table.NewRow()
|
||||
newRow("ConfigName") = "MyConnectionString"
|
||||
newRow("Value") = ""
|
||||
table.Rows.Add(newRow)
|
||||
Dim newRow1 As DataRow = table.NewRow()
|
||||
newRow1("ConfigName") = "LogErrorsOnly"
|
||||
newRow1("Value") = "True"
|
||||
table.Rows.Add(newRow1)
|
||||
table.AcceptChanges()
|
||||
Return table
|
||||
Catch ex As Exception
|
||||
MsgBox("Error in CreateConfigTable" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Module
|
||||
Reference in New Issue
Block a user