357 lines
14 KiB
VB.net
357 lines
14 KiB
VB.net
Public Class ClassMI_Profile
|
|
Private Shared _profiles() As ClassMI_Profil
|
|
Public Shared xmlConfigFile As String
|
|
Public Shared aktivesProfil As ClassMI_Profil
|
|
Public Shared aktivesProfilAusProfileigenschaften As Boolean = False
|
|
Public Shared _windream As New ClassWindream_allgemein(CURR_LogConfig)
|
|
'Public Shared xmlConfigFile As String = My.Settings.vConfigDatei
|
|
'Private Shared config As ClassMerkatorIntegrationKonfiguration = New ClassMerkatorIntegrationKonfiguration()
|
|
|
|
Public Shared Sub Init()
|
|
xmlConfigFile = My.Application.Info.DirectoryPath & "\" & My.Settings.vMIConfigDatei
|
|
ClassMI_Profile.LoadFromXmlFile()
|
|
' 3b. Windream initialisieren (Connection, Session, ... aufbauen)
|
|
_windream.Init()
|
|
'If ClassMI_Profile._parentClass.Config IsNot Nothing Then
|
|
' If ClassMI_Profile._parentClass.Config.isInitialized Then
|
|
' ClassMI_Profile.LoadFromXmlFile()
|
|
' Else
|
|
' ClassMI_Profile._parentClass.Config.Init()
|
|
' ClassMI_Profile.LoadFromXmlFile()
|
|
' End If
|
|
'End If
|
|
|
|
End Sub
|
|
Public Shared Function IsXmlAccessable()
|
|
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
|
|
If My.Settings.vLogErrorsonly = False Then MsgBox("System kann nicht auf Konfig-Datei " & vbNewLine & xmlConfigFile & vbNewLine & " zugreifen! (Nicht vorhanden bzw Syntaxfehler)" & vbNewLine & "Datei wird neu erstellt!", MsgBoxStyle.Exclamation, "Achtung:")
|
|
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()
|
|
|
|
|
|
Dim i As Integer = 0
|
|
Dim xml As Xml.XmlDocument
|
|
|
|
ClassMI_Profile._profiles = Nothing
|
|
|
|
If xmlConfigFile Is Nothing Then Exit Sub
|
|
|
|
If Not xmlConfigFile = "" Then
|
|
|
|
If ClassMI_Profile.IsXmlAccessable() Then
|
|
|
|
xml = New Xml.XmlDocument()
|
|
xml.Load(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 i As Integer = 0 To anzProfile - 1
|
|
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 Then
|
|
|
|
' ein Element an Items anhängen
|
|
ReDim Preserve ClassMI_Profile._profiles(i)
|
|
|
|
|
|
' das Profilobjekt erzeugen
|
|
ClassMI_Profile._profiles(i) = New ClassMI_Profil(
|
|
xmlProfil.Attributes("profilname").Value,
|
|
_windream.GetObjecttypeByName(xmlProfil.Attributes("dokumenttyp").Value, False),
|
|
xmlProfil.Attributes("servername").Value,
|
|
xmlProfil.Attributes("zeige_suchmaske").Value,
|
|
xmlProfil.Attributes("wdf_suche").Value,
|
|
xmlProfil.Attributes("dokumenttyp").Value
|
|
)
|
|
|
|
Dim profil As ClassMI_Profil = ClassMI_Profile._profiles(i)
|
|
|
|
Dim xmlProfilParam As Xml.XmlNode = xml.SelectSingleNode("//Settings/Profile/Profil[@profilname='" & profil.OriginalProfilname & "']")
|
|
|
|
' wenn der Knoten NICHT gefunden wurde -> Vorgang abbrechen
|
|
If xmlProfilParam IsNot Nothing Then
|
|
|
|
For Each param As Xml.XmlElement In xmlProfilParam.ChildNodes
|
|
profil.AddParameter(param.Attributes("index").Value)
|
|
Next
|
|
' die neuen Werte in die XML-Datei schreiben
|
|
|
|
End If
|
|
|
|
' wenn ein Dokumenttyp in der XML-Datei angegeben wurde, diesen dem Objekt zuweisen
|
|
'If xmlProfil.Attributes("dokumenttyp") IsNot Nothing Then Me.Items(i).DokumentTyp = ClassMerkatorIntegrationWindream.ErzeugeObjekttypNachName(xmlProfil.Attributes("dokumenttyp").Value)
|
|
' wenn eine windream-Suche (Speicherort) in der XML-Datei angegeben wurde, diesen dem Objekt zuweisen
|
|
'If xmlProfil.Attributes("windreamsuche") IsNot Nothing Then Me.Items(i).WindreamSuche = xmlProfil.Attributes("windreamsuche").Value
|
|
|
|
' Zähler für Profile erhöhen
|
|
i += 1
|
|
End If
|
|
|
|
Next
|
|
End If
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
|
|
' gibt ein einzelnes Profil-Objekt zurück
|
|
Public Shared Function getProfilByName(ByVal profilname As String) As ClassMI_Profil
|
|
|
|
' alle Profile durchlaufen
|
|
For Each profil As ClassMI_Profil 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 Function Exists(ByVal profilname As String)
|
|
|
|
If ClassMI_Profile.Count > 0 Then
|
|
For Each profil As ClassMI_Profil In ClassMI_Profile._profiles
|
|
If profil.OriginalProfilname = profilname Then
|
|
Return True
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
Return False
|
|
|
|
End Function
|
|
|
|
|
|
'Private Shared Function IsXmlIsAccessable()
|
|
' Dim xml As New Xml.XmlDocument
|
|
|
|
' Try
|
|
' ' XML-Datei laden und speichern um Zugriff zu testen
|
|
' xml.Load(ClassMI_Profile._parentClass.Config.XmlConfigFile)
|
|
' xml.Save(ClassMI_Profile._parentClass.Config.XmlConfigFile)
|
|
|
|
' Return True
|
|
|
|
' Catch ex As Exception
|
|
|
|
' Try
|
|
' Dim fw As System.IO.StreamWriter = New System.IO.StreamWriter(ClassMI_Profile._parentClass.Config.XmlConfigFile)
|
|
|
|
' fw.WriteLine("<?xml version=""1.0"" encoding=""ISO-8859-1"" standalone=""yes""?>")
|
|
' fw.WriteLine("<Settings>")
|
|
' fw.WriteLine(" <Profile />")
|
|
' fw.WriteLine("</Settings>")
|
|
|
|
' fw.Close()
|
|
|
|
' Return True
|
|
' Catch e2 As Exception
|
|
' Return False
|
|
' End Try
|
|
|
|
' End Try
|
|
'End Function
|
|
|
|
|
|
' erstellt ein neues Profil
|
|
'Public Sub Add(ByVal profilname As String, ByVal dokumenttyp As WINDREAMLib.WMObject, Optional ByVal windreamsuche As String = "")
|
|
Public Shared Function Add(ByVal profilname As String, ByVal dokumenttyp As String, ByVal servername As String, _
|
|
ByVal zeige_suchmaske As Boolean, ByVal wdf_suche As String)
|
|
|
|
Try
|
|
If Not ClassMI_Profile.Exists(profilname) Then
|
|
Dim xml As New Xml.XmlDocument
|
|
Dim xmlProfil As Xml.XmlElement
|
|
|
|
If ClassMI_Profile.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.SelectNodes("Settings/Profile") Is Nothing Then xml.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("servername", servername)
|
|
xmlProfil.SetAttribute("zeige_suchmaske", zeige_suchmaske)
|
|
xmlProfil.SetAttribute("wdf_suche", wdf_suche)
|
|
|
|
|
|
' 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 ClassMI_Profile._profiles(ClassMI_Profile.Count)
|
|
|
|
' und das neue Profil dem Profilarray anhängen und die Eigenschaften zuweisen
|
|
ClassMI_Profile._profiles(ClassMI_Profile.Count - 1) = New ClassMI_Profil(
|
|
profilname,
|
|
_windream.GetObjecttypeByName(dokumenttyp, False),
|
|
servername,
|
|
zeige_suchmaske,
|
|
wdf_suche,
|
|
dokumenttyp)
|
|
'Me.Items(Me.Count - 1).DokumentTyp = dokumenttyp
|
|
'Me.Items(Me.Count - 1).WindreamSuche = windreamsuche
|
|
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
Else
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler beim Anlegen eines Profils")
|
|
Return False
|
|
End Try
|
|
|
|
End Function
|
|
|
|
|
|
Public Shared Function Delete(ByVal profilname As String) As Boolean
|
|
|
|
Try
|
|
If ClassMI_Profile.Exists(profilname) Then
|
|
|
|
' XML-Objekt initialisieren
|
|
Dim xml As New Xml.XmlDocument
|
|
|
|
If ClassMI_Profile.IsXmlAccessable() Then
|
|
|
|
' XML-Datei laden
|
|
xml.Load(xmlConfigFile)
|
|
|
|
' 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
|
|
|
|
|
|
' *** Array umschreiben (Element aus Array entfernen) ***
|
|
|
|
If ClassMI_Profile.Exists(profilname) Then
|
|
' temporäres Array erzeugen
|
|
Dim tempItems() As ClassMI_Profil = ClassMI_Profile._profiles
|
|
ClassMI_Profile._profiles = Nothing
|
|
Dim i As Integer = 0
|
|
|
|
|
|
' alle Verknüpfungen durchlaufen
|
|
For Each item As ClassMI_Profil In tempItems
|
|
|
|
' wenn es sich nicht um das gelöschte handelt
|
|
If Not item.OriginalProfilname = profilname Then
|
|
|
|
' Größe anpassen
|
|
ReDim Preserve ClassMI_Profile._profiles(i)
|
|
|
|
' die Verknüpfung in das Items-Array übertragen
|
|
ClassMI_Profile._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 ReadOnly Property Profile() As ClassMI_Profil()
|
|
Get
|
|
Return ClassMI_Profile._profiles
|
|
End Get
|
|
End Property
|
|
|
|
|
|
|
|
Public Shared ReadOnly Property Count() As Integer
|
|
Get
|
|
' Anzahl der Profile zurückgeben
|
|
If ClassMI_Profile._profiles IsNot Nothing Then
|
|
Return ClassMI_Profile._profiles.Length
|
|
Else
|
|
Return 0
|
|
End If
|
|
End Get
|
|
End Property
|
|
End Class
|