Imports System.IO Imports System.Xml Imports System.Xml.Schema Imports System.Data Imports System.Data.SqlTypes Imports System.Data.SqlClient Public Class Action #Region "Members" Private Shared _actionSingleton As Action Private _actionType As ActionType Private _creatorTgNr As String Private _sourceApplication As String Private _parameters As Parameter() Private _validationSuccess As Boolean #End Region #Region "Public methods" '''Lädt externes Xml file für automatisierte Aktionen '''Das Xml File mit den entsprechenden Parametern Public Sub Load(ByVal xmlImportFile As FileInfo) Try 'Validate source 'If Not IsValid(xmlImportFile) Then ' 'xml file is invalid ' Throw New ActionException(1, "Specified file " & xmlImportFile.FullName & " hasn't got a valid strucure which is specified by his schema") 'End If Dim doc As New XmlDocument() Try doc.Load(xmlImportFile.FullName) Catch ex As Exception 'MsgBox(ex.Message) End Try 'read header elements _actionType = CType(doc.SelectSingleNode("action/actionId").InnerText, ActionType) _creatorTgNr = doc.SelectSingleNode("action/creatorTg").InnerText _sourceApplication = doc.SelectSingleNode("action/sourceApplication").InnerText Dim RootNode As XmlElement = doc.DocumentElement Dim nodeList As XmlNodeList = RootNode.ChildNodes If nodeList.Count > 0 Then 'set correct array size ReDim _parameters(nodeList.Count - 1) Dim value As String Dim name As String Dim parameterCounter As Integer = 0 Dim i As Integer For i = 0 To nodeList.Count - 1 value = nodeList.Item(i).InnerText name = nodeList.Item(i).LocalName 'append new parameter _parameters(parameterCounter) = New Parameter(name, value) parameterCounter = parameterCounter + 1 Next End If 'Rel 4.02 Catch ex As Exception Throw ex TKBLib.Errorhandling.TraceHelper.Msg("EdokaLib.Common.Action.Load", ex.Message & ex.StackTrace, TraceLevel.Error) End Try End Sub '''Returns a parameter identified by his name ''' ''' Public Function GetParameterByName(ByVal paramName As String) As Parameter Try Dim param As Parameter For Each param In _parameters If param.Name = paramName Then Return param End If Next Catch ex As Exception TKBLib.Errorhandling.TraceHelper.Msg("EdokaLib.Common.Action.GetParameterByName", ex.Message & ex.StackTrace, TraceLevel.Error) Throw ex End Try End Function '''Zerstört die statische Instanz Public Sub Destroy() Try _actionSingleton = Nothing Catch ex As Exception TKBLib.Errorhandling.TraceHelper.Msg("EdokaLib.Common.Action.Destroy", ex.Message & ex.StackTrace, TraceLevel.Error) Throw ex End Try End Sub #End Region #Region "Private methods/subs" '''Überprüft ob das Xml file dem angegebenen Schema entspricht ''' ''' Private Function IsValid(ByVal xmlImportFile As FileInfo) As Boolean Dim reader As New XmlTextReader(xmlImportFile.FullName) 'We pass the xmltextreader into the xmlvalidatingreader 'This will validate the xml doc with the schema file 'NOTE the xml file it self points to the schema file Dim validator As New XmlValidatingReader(reader) Try 'First we create the xmltextreader ' Set the validation event handler 'AddHandler validator.ValidationEventHandler, _ 'AddressOf ValidationCallback _validationSuccess = True 'make sure to reset the success var ' Read XML data While (validator.Read) End While 'Close the reader. validator.Close() reader.Close() 'The validationeventhandler is the only thing that would 'set m_Success to false Return _validationSuccess Catch ex As Exception validator.Close() reader.Close() _validationSuccess = False TKBLib.Errorhandling.TraceHelper.Msg("EdokaLib.Common.Action.IsValid", ex.Message & ex.StackTrace, TraceLevel.Warning) _validationSuccess = False Return _validationSuccess Throw ex End Try End Function Private Sub ValidationCallback(ByVal sender As Object, ByVal args As ValidationEventArgs) Try 'Display the validation error. This is only called on error _validationSuccess = False 'Validation failed Debug.Write("Validation error: " + args.Message + Environment.NewLine) Throw New ActionException(1, "Fehler bei der Validierung") Catch ex As Exception Throw ex End Try End Sub #End Region #Region "Properties" Public Shared ReadOnly Property Action() As Action Get If IsNothing(_actionSingleton) Then _actionSingleton = New Action() End If Return _actionSingleton End Get End Property Public ReadOnly Property valtionOK() As Boolean Get Return _validationSuccess End Get End Property Public ReadOnly Property ActionType() As ActionType Get Return _actionType End Get End Property Public ReadOnly Property CreatorTgNr() As String Get Return _creatorTgNr End Get End Property Public ReadOnly Property SourceApplication() As String Get Return _sourceApplication End Get End Property Public ReadOnly Property Parameters() As Parameter() Get Return _parameters End Get End Property #End Region End Class #Region "ActionException" Public Class ActionException Inherits Exception Private _number As Integer Private _description As String Public Sub New(ByVal number As Integer, ByVal description As String) _number = number _description = description End Sub Public Overrides ReadOnly Property Message() As String Get Return _description End Get End Property Public ReadOnly Property Number() As Integer Get Return _number End Get End Property End Class #End Region '''Struct für einzelne Parameter Public Structure Parameter Private _value As String Private _name As String Public Sub New(ByVal name As String, ByVal value As String) Try _value = value _name = name Catch ex As Exception TKBLib.Errorhandling.TraceHelper.Msg("EdokaLib.Common.Parameter.New", ex.Message & ex.StackTrace, TraceLevel.Error) Throw ex End Try End Sub Public ReadOnly Property Value() As String Get Return _value End Get End Property Public ReadOnly Property Name() As String Get Return _name End Get End Property End Structure Public Enum ActionType AnzeigePartnerdossier = 1 DokumentAnzeige = 2 DokumentErstellung = 3 DokumentBearbeitung = 4 Statusmutation = 5 HostDokumentAnzeige = 6 UVMDokumentanzeige = 7 ZVDokumentanzeige = 8 DokLoeschung = 9 AusHyperlink = 10 End Enum