391 lines
19 KiB
VB.net
391 lines
19 KiB
VB.net
Imports DigitalData.Modules.Logging
|
|
Public Class ClassNIProfile
|
|
Private Shared _Logger As DigitalData.Modules.Logging.Logger
|
|
Private Shared _profiles() As ClassNIProfil
|
|
Public Shared _windream As New ClassWindream_allgemein(CURR_LogConfig)
|
|
Public Shared xmlConfigFile As String
|
|
Public Shared aktivesProfil As ClassNIProfil
|
|
Public Shared aktivesProfilAusProfileigenschaften As Boolean = False
|
|
|
|
Public Shared Sub Init()
|
|
Dim oConfigPath As String = My.Application.Info.DirectoryPath & "\" & My.Settings.vNIConfigDatei
|
|
CURR_Logger.Info("[ClassNIProfile] Loading config for NI from {0}", oConfigPath)
|
|
|
|
xmlConfigFile = oConfigPath
|
|
ClassNIProfile.LoadFromXmlFile()
|
|
' 3b. Windream initialisieren (Connection, Session, ... aufbauen)
|
|
_windream.Init()
|
|
End Sub
|
|
Public Shared Function IsXmlAccessable() As Boolean
|
|
Dim xml As New Xml.XmlDocument
|
|
Try
|
|
' XML-Datei laden und speichern um Zugriff zu testen
|
|
xml.Load(xmlConfigFile)
|
|
xml.Save(xmlConfigFile)
|
|
|
|
Return True
|
|
Catch ex As Exception
|
|
Try
|
|
CURR_Logger.Warn("[ClassNIProfile] Could not load config file, creating default.")
|
|
CURR_Logger.Error(ex)
|
|
|
|
Dim fw As System.IO.StreamWriter = New System.IO.StreamWriter(xmlConfigFile)
|
|
fw.WriteLine("<?xml version=""1.0"" encoding=""ISO-8859-1"" standalone=""yes""?>")
|
|
fw.WriteLine("<Settings>")
|
|
fw.WriteLine("<Profile>")
|
|
fw.WriteLine("</Profile>")
|
|
fw.WriteLine("</Settings>")
|
|
|
|
fw.Close()
|
|
Return True
|
|
Catch e2 As Exception
|
|
Return False
|
|
End Try
|
|
End Try
|
|
End Function
|
|
Public Shared Sub LoadFromXmlFile()
|
|
Try
|
|
Dim i As Integer = 0
|
|
Dim xml As Xml.XmlDocument
|
|
|
|
ClassNIProfile._profiles = Nothing
|
|
|
|
If xmlConfigFile Is Nothing Then Exit Sub
|
|
|
|
If Not xmlConfigFile = "" Then
|
|
'If System.IO.File.Exists(xmlConfigFile) Then
|
|
If ClassNIProfile.IsXmlAccessable() Then
|
|
|
|
xml = New Xml.XmlDocument()
|
|
xml.Load(xmlConfigFile)
|
|
'MsgBox(xmlConfigFile)
|
|
' Anzahl der Profilelemente in der XML-Datei zählen
|
|
Dim anzProfile = xml.SelectNodes("Settings/Profile/Profil").Count
|
|
|
|
' wenn mindestens ein Profilelement eingetragen ist
|
|
If anzProfile > 0 Then
|
|
|
|
' alle Profile laden
|
|
Dim xmlNodes As Xml.XmlNodeList = xml.SelectNodes("Settings/Profile/Profil")
|
|
|
|
' alle Profile der XML-Datei durchlaufen
|
|
For Each xmlProfil As Xml.XmlNode In xmlNodes
|
|
|
|
' prüfen ob ein Profilname angegeben wurde
|
|
If xmlProfil.Attributes("profilname") IsNot Nothing And xmlProfil.Attributes("dokumenttyp") IsNot Nothing And
|
|
xmlProfil.Attributes("windreamsuche") IsNot Nothing And xmlProfil.Attributes("dbArt") IsNot Nothing And
|
|
xmlProfil.Attributes("dataSource") IsNot Nothing Then
|
|
|
|
' ein Element an Items anhängen
|
|
ReDim Preserve ClassNIProfile._profiles(i)
|
|
|
|
ClassNIProfile._profiles(i) = New ClassNIProfil()
|
|
|
|
|
|
|
|
Dim initialCatalog As String = Nothing
|
|
Dim userId As String = Nothing
|
|
Dim password As String = Nothing
|
|
|
|
If xmlProfil.Attributes("userId") IsNot Nothing Then
|
|
userId = xmlProfil.Attributes("userId").Value
|
|
End If
|
|
|
|
If xmlProfil.Attributes("password") IsNot Nothing Then
|
|
password = xmlProfil.Attributes("password").Value
|
|
End If
|
|
|
|
If xmlProfil.Attributes("initialCatalog") IsNot Nothing Then
|
|
initialCatalog = xmlProfil.Attributes("initialCatalog").Value
|
|
End If
|
|
|
|
|
|
' das Profilobjekt erstellen
|
|
'profilname, dokumenttyp_string , windreamSuche, _
|
|
'NI_Art , xmlEnd , xmlfolder ,
|
|
'delete , dbArt , dataSource , userId , _
|
|
'password , initialCatalog , SQLAnweisung , windreamIndex , checkIndexSQL , indexValidation , _
|
|
'finalerIndex , aktiv , mrDAIndex , mrKDIndex
|
|
ClassNIProfile._profiles(i) = New ClassNIProfil(xmlProfil.Attributes("profilname").Value, xmlProfil.Attributes("dokumenttyp").Value, xmlProfil.Attributes("windreamsuche").Value,
|
|
xmlProfil.Attributes("ni_art").Value, xmlProfil.Attributes("xml_end").Value, xmlProfil.Attributes("folder").Value,
|
|
xmlProfil.Attributes("delete").Value, xmlProfil.Attributes("dbArt").Value, xmlProfil.Attributes("dataSource").Value,
|
|
userId,
|
|
password,
|
|
initialCatalog,
|
|
xmlProfil.Attributes("sqlanweisung").Value,
|
|
xmlProfil.Attributes("windreamIndex").Value,
|
|
xmlProfil.Attributes("checkIndexSQL").Value,
|
|
xmlProfil.Attributes("indexValidation").Value,
|
|
xmlProfil.Attributes("indexFehler").Value,
|
|
xmlProfil.Attributes("finalerIndex").Value,
|
|
xmlProfil.Attributes("aktiv").Value,
|
|
xmlProfil.Attributes("mr_DAIndex").Value,
|
|
xmlProfil.Attributes("mr_KDIndex").Value,
|
|
xmlProfil.Attributes("move2Folder").Value,
|
|
xmlProfil.Attributes("intervall").Value,
|
|
xmlProfil.Attributes("lastrun").Value,
|
|
xmlProfil.Attributes("NB_AD").Value,
|
|
xmlProfil.Attributes("getordneridx").Value,
|
|
xmlProfil.Attributes("ordnerType").Value,
|
|
xmlProfil.Attributes("ordnerType_eb").Value,
|
|
xmlProfil.Attributes("crfolderindex").Value,
|
|
xmlProfil.Attributes("crfolder_folder").Value,
|
|
xmlProfil.Attributes("crfolder_move").Value)
|
|
' Zähler für Profile erhöhen
|
|
i += 1
|
|
End If
|
|
|
|
Next
|
|
End If
|
|
End If
|
|
|
|
End If
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
' erstellt ein neues Profil
|
|
Public Shared Sub Add(ByVal profilname As String, ByVal dokumenttyp As String, ByVal windreamSuche As String,
|
|
ByVal NiArt As String, ByVal xmlEnd As String, ByVal dbArt As String, ByVal dataSource As String, ByVal userId As String,
|
|
ByVal password As String, ByVal initialCatalog As String, ByVal indexValidation As String, ByVal delete As String, ByVal intervall As Integer, ByVal GetFolderIdx As Boolean, ByVal Ordnertyp As String, Optional DESKIndex As String = "")
|
|
|
|
Try
|
|
If Not ClassNIProfile.Exists(profilname) Then
|
|
Dim xml As New Xml.XmlDocument
|
|
Dim xmlProfil As Xml.XmlElement
|
|
|
|
If ClassNIProfile.IsXmlAccessable() Then
|
|
|
|
' XML-Datei laden
|
|
xml.Load(xmlConfigFile)
|
|
|
|
Try
|
|
' versuchen die XML-Beschreibung zu schreiben
|
|
xml.InsertBefore(xml.CreateXmlDeclaration("1.0", "ISO-8859-1", "yes"), xml.ChildNodes(0))
|
|
Catch ex As Exception
|
|
' wenn dies nicht funktioniert, ist die Beschreibung schon vorhanden
|
|
End Try
|
|
|
|
' wenn die Hauptknoten noch nicht eingetragen wurden, sollen diese angelegt werden
|
|
If xml.DocumentElement Is Nothing Then xml.AppendChild(xml.CreateElement("Settings"))
|
|
If xml.SelectSingleNode("Settings/Profile") Is Nothing Then xml.SelectSingleNode("Settings").AppendChild(xml.CreateElement("Profile"))
|
|
|
|
|
|
' dann ein neues Profil anlegen
|
|
xmlProfil = xml.CreateElement("Profil")
|
|
|
|
' dem Profil die Attribute zuweisen
|
|
xmlProfil.SetAttribute("profilname", profilname)
|
|
xmlProfil.SetAttribute("dokumenttyp", dokumenttyp)
|
|
xmlProfil.SetAttribute("windreamsuche", windreamSuche)
|
|
xmlProfil.SetAttribute("dbArt", dbArt)
|
|
xmlProfil.SetAttribute("dataSource", dataSource)
|
|
'xmlProfil.SetAttribute("userID", userId)
|
|
'xmlProfil.SetAttribute("password", password)
|
|
'xmlProfil.SetAttribute("initialCatalog", initialCatalog)
|
|
|
|
|
|
|
|
If userId IsNot Nothing Then
|
|
xmlProfil.SetAttribute("userId", userId)
|
|
End If
|
|
|
|
If password IsNot Nothing Then
|
|
xmlProfil.SetAttribute("password", password)
|
|
End If
|
|
|
|
If initialCatalog IsNot Nothing Then
|
|
xmlProfil.SetAttribute("initialCatalog", initialCatalog)
|
|
End If
|
|
|
|
xmlProfil.SetAttribute("sqlanweisung", "")
|
|
xmlProfil.SetAttribute("windreamIndex", DESKIndex)
|
|
xmlProfil.SetAttribute("ni_art", NiArt)
|
|
xmlProfil.SetAttribute("xml_end", xmlEnd)
|
|
xmlProfil.SetAttribute("delete", delete)
|
|
xmlProfil.SetAttribute("folder", "")
|
|
xmlProfil.SetAttribute("checkIndexSQL", "")
|
|
xmlProfil.SetAttribute("indexValidation", indexValidation)
|
|
xmlProfil.SetAttribute("indexFehler", "")
|
|
'finaler Index
|
|
xmlProfil.SetAttribute("finalerIndex", "")
|
|
xmlProfil.SetAttribute("aktiv", True)
|
|
xmlProfil.SetAttribute("mr_DAIndex", "")
|
|
xmlProfil.SetAttribute("mr_KDIndex", "")
|
|
xmlProfil.SetAttribute("move2Folder", "")
|
|
xmlProfil.SetAttribute("intervall", intervall)
|
|
xmlProfil.SetAttribute("lastrun", "01.01.1900")
|
|
xmlProfil.SetAttribute("NB_AD", "False")
|
|
xmlProfil.SetAttribute("getordneridx", GetFolderIdx)
|
|
xmlProfil.SetAttribute("ordnerType", Ordnertyp)
|
|
xmlProfil.SetAttribute("ordnerType_eb", "Parent")
|
|
xmlProfil.SetAttribute("crfolderindex", "")
|
|
xmlProfil.SetAttribute("crfolder_folder", "")
|
|
xmlProfil.SetAttribute("crfolder_move", False)
|
|
|
|
|
|
' und in den Hauptknoten 'Profile' einhängen
|
|
xml.SelectSingleNode("Settings/Profile").AppendChild(xmlProfil)
|
|
|
|
' XML-Datei speichern
|
|
xml.Save(xmlConfigFile)
|
|
|
|
' die Liste der Profile im Objekt vergrößern
|
|
ReDim Preserve ClassNIProfile._profiles(ClassNIProfile.Count)
|
|
|
|
|
|
' das Profilobjekt erstellen
|
|
ClassNIProfile._profiles(ClassNIProfile.Count - 1) = New ClassNIProfil(
|
|
profilname,
|
|
dokumenttyp,
|
|
windreamSuche,
|
|
NiArt,
|
|
xmlEnd,
|
|
delete,
|
|
"",
|
|
dbArt,
|
|
dataSource,
|
|
userId,
|
|
password,
|
|
initialCatalog,
|
|
"", "", "", indexValidation, "", "", "True", "", "", "",
|
|
intervall,
|
|
"01.01.1900", False, GetFolderIdx, Ordnertyp, "Parent", "", "", False)
|
|
MsgBox("Das Profil '" & profilname & "' wurde erfolgreich angelegt!", MsgBoxStyle.Information, "Erfolgsmeldung:")
|
|
|
|
End If
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler beim Anlegen eines Profils")
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
|
|
Public Shared Function DeleteProfil(ByVal profilname As String) As Boolean
|
|
|
|
Try
|
|
If ClassNIProfile.Exists(profilname) Then
|
|
|
|
' XML-Objekt initialisieren
|
|
Dim xml As New Xml.XmlDocument
|
|
|
|
If ClassNIProfile.IsXmlAccessable() Then
|
|
|
|
' XML-Datei laden
|
|
xml.Load(xmlConfigFile)
|
|
|
|
|
|
' ***** Zuerst einmal das Profil heraus löschen ***** '
|
|
|
|
' XML-Element auswählen
|
|
Dim node As Xml.XmlElement = xml.SelectSingleNode("Settings/Profile/Profil[@profilname='" & profilname & "']")
|
|
|
|
If node IsNot Nothing Then
|
|
' Element löschen
|
|
node.ParentNode.RemoveChild(node)
|
|
|
|
' XML-Datei speichern
|
|
xml.Save(xmlConfigFile)
|
|
End If
|
|
|
|
|
|
If ClassNIProfile.Exists(profilname) Then
|
|
' temporäres Array erzeugen
|
|
Dim tempItems() As ClassNIProfil = ClassNIProfile._profiles
|
|
ClassNIProfile._profiles = Nothing
|
|
Dim i As Integer = 0
|
|
|
|
|
|
' alle Verknüpfungen durchlaufen
|
|
For Each item As ClassNIProfil In tempItems
|
|
|
|
' wenn es sich nicht um das gelöschte handelt
|
|
If Not item.OriginalProfilname = profilname Then
|
|
|
|
' Größe anpassen
|
|
ReDim Preserve ClassNIProfile._profiles(i)
|
|
|
|
' die Verknüpfung in das Items-Array übertragen
|
|
ClassNIProfile._profiles(i) = item
|
|
|
|
' Counter hochzählen
|
|
i += 1
|
|
End If
|
|
Next
|
|
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
Else
|
|
Return False
|
|
End If
|
|
Else
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler beim Löschen eines Profils")
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
|
|
Public Shared Function Exists(ByVal profilname As String)
|
|
|
|
If ClassNIProfile.Count > 0 Then
|
|
For Each profil As ClassNIProfil In ClassNIProfile._profiles
|
|
If profil.OriginalProfilname = profilname Then
|
|
Return True
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
Return False
|
|
|
|
End Function
|
|
|
|
' gibt ein einzelnes Profil-Objekt zurück
|
|
Public Shared Function getProfilByName(ByVal profilname As String) As ClassNIProfil
|
|
|
|
If _profiles Is Nothing Then
|
|
Return Nothing
|
|
End If
|
|
|
|
' alle Profile durchlaufen
|
|
For Each profil As ClassNIProfil In _profiles
|
|
|
|
' wenn der aktuelle Profilname mit dem gesuchten Profilnamen übereinstimmt
|
|
If profil.Profilname = profilname Then
|
|
|
|
' das Profil zurückgeben
|
|
Return profil
|
|
End If
|
|
Next
|
|
|
|
' sonst nichts zurückgeben
|
|
Return Nothing
|
|
|
|
End Function
|
|
Public Shared ReadOnly Property Profile() As ClassNIProfil()
|
|
Get
|
|
Return ClassNIProfile._profiles
|
|
End Get
|
|
End Property
|
|
Public Shared ReadOnly Property Count() As Integer
|
|
Get
|
|
' Anzahl der Profile zurückgeben
|
|
If ClassNIProfile._profiles IsNot Nothing Then
|
|
Return ClassNIProfile._profiles.Length
|
|
Else
|
|
Return 0
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
|
|
End Class
|