From 4cde71195550416c842b10ac004d98524e72852d Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 27 Apr 2020 14:16:42 +0200 Subject: [PATCH 01/12] EDMI --- GUIs.Test.EDMIBenchmark/Form1.vb | 2 +- Modules.EDMIAPI/Client.vb | 12 ++ Service.EDMIService/Database/IDatabase.vb | 3 - Service.EDMIService/Database/MSSQL.vb | 20 -- Service.EDMIService/EDMIService.vb | 191 +----------------- Service.EDMIService/EDMIService.vbproj | 6 - Service.EDMIService/Exceptions.vb | 10 +- Service.EDMIService/IEDMIService.vb | 29 ++- .../Results/ContainerResult.vb | 18 -- Service.EDMIService/Results/DocumentResult.vb | 31 --- .../Results/DocumentResultOld.vb | 26 --- Service.EDMIService/Results/IndexResult.vb | 15 -- 12 files changed, 38 insertions(+), 325 deletions(-) delete mode 100644 Service.EDMIService/Database/IDatabase.vb delete mode 100644 Service.EDMIService/Database/MSSQL.vb delete mode 100644 Service.EDMIService/Results/ContainerResult.vb delete mode 100644 Service.EDMIService/Results/DocumentResult.vb delete mode 100644 Service.EDMIService/Results/DocumentResultOld.vb delete mode 100644 Service.EDMIService/Results/IndexResult.vb diff --git a/GUIs.Test.EDMIBenchmark/Form1.vb b/GUIs.Test.EDMIBenchmark/Form1.vb index aac64917..fd3aa573 100644 --- a/GUIs.Test.EDMIBenchmark/Form1.vb +++ b/GUIs.Test.EDMIBenchmark/Form1.vb @@ -15,7 +15,7 @@ Public Class Form1 Try _LogConfig = New LogConfig(LogConfig.PathType.Temp, Nothing, "EDMIBenschmark") _Logger = _LogConfig.GetLogger() - _Client = New Client(_LogConfig, "net.tcp://172.24.12.39:9000/DigitalData/Services/Main") + _Client = New Client(_LogConfig, "172.24.12.39", 9000) _Client.Connect() DocumentViewer1.Init(_LogConfig, "21182889975216572111813147150675976632") diff --git a/Modules.EDMIAPI/Client.vb b/Modules.EDMIAPI/Client.vb index 2ca1d33e..b0ff42e8 100644 --- a/Modules.EDMIAPI/Client.vb +++ b/Modules.EDMIAPI/Client.vb @@ -36,6 +36,18 @@ Public Class Client End Try End Sub + Public Sub New(LogConfig As LogConfig, IPAddress As String, PortNumber As Integer) + _logger = LogConfig.GetLogger() + + Try + Dim oBinding = Channel.GetBinding() + Dim oAddress = New EndpointAddress($"net.tcp://{IPAddress}:{PortNumber}/DigitalData/Services/Main") + Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress) + Catch ex As Exception + + End Try + End Sub + ''' ''' Connect to the service ''' diff --git a/Service.EDMIService/Database/IDatabase.vb b/Service.EDMIService/Database/IDatabase.vb deleted file mode 100644 index 0b370d22..00000000 --- a/Service.EDMIService/Database/IDatabase.vb +++ /dev/null @@ -1,3 +0,0 @@ -Public Interface IDatabase - Function NewDocument(RelativePath As String, AddedWho As String, ObjectStoreId As Int64, ReferenceId As Int64) As Int64 -End Interface diff --git a/Service.EDMIService/Database/MSSQL.vb b/Service.EDMIService/Database/MSSQL.vb deleted file mode 100644 index 3d4153b1..00000000 --- a/Service.EDMIService/Database/MSSQL.vb +++ /dev/null @@ -1,20 +0,0 @@ -Imports DigitalData.Modules.Database -Imports DigitalData.Modules.Logging - -Public Class MSSQL - Implements IDatabase - - Private ReadOnly LogConfig As LogConfig - Private ReadOnly Database As MSSQLServer - Private ReadOnly Logger As Logger - - Public Sub New(LogConfig As LogConfig, Database As MSSQLServer) - Me.LogConfig = LogConfig - Me.Database = Database - Me.Logger = LogConfig.GetLogger() - End Sub - - Public Function NewDocument(RelativePath As String, AddedWho As String, ObjectStoreId As Long, ReferenceId As Long) As Long Implements IDatabase.NewDocument - - End Function -End Class diff --git a/Service.EDMIService/EDMIService.vb b/Service.EDMIService/EDMIService.vb index 5c5ea456..01e344a8 100644 --- a/Service.EDMIService/EDMIService.vb +++ b/Service.EDMIService/EDMIService.vb @@ -47,7 +47,7 @@ Public Class EDMIService End If End Function -#Region "Auth" +#Region "=== Authorization ===" Private Function TestUserAuth() As Boolean Try 'Dim oSQL As String = $"SELECT FNIDB_AUTH_USER('{_username}') FROM RDB$DATABASE;" @@ -60,12 +60,12 @@ Public Class EDMIService End Try End Function #End Region -#Region "Heartbeat" +#Region "=== Heartbeat ===" Public Function Heartbeat() As Boolean Implements IEDMIService.Heartbeat Return True End Function #End Region -#Region "Request" +#Region "=== Database Request ===" Public Sub CreateRequest(Name As String, Optional Debug As Boolean = False) _request = New Request(Name, _username, Firebird, Debug) _debug = Debug @@ -90,7 +90,7 @@ Public Class EDMIService End Sub #End Region -#Region "Database" +#Region "=== Database (Firebird) ===" Private Sub TestRequestCreated() If IsNothing(_request) Then Throw New Exceptions.NoRequestException() @@ -144,174 +144,8 @@ Public Class EDMIService Return New NonQueryResult(ex.Message) End Try End Function - - #End Region -#Region "Document (with FileContainer)" - Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResultOld Implements IEDMIService.NewFile - Try - Dim oContainer As FileContainer - Dim oContainerId As String - - If Not TestUserAuth() Then - Throw New Exception($"User {_username} not authorized.") - End If - - oContainer = FileContainer.Create(LogConfig, AppConfig.ContainerPassword) - oContainerId = oContainer.ContainerId - _logger.Debug("Container created with id {0}", oContainerId) - - Dim oExtension As String = Path.GetExtension(FileName).Substring(1) - _logger.Debug("File extension of file {0} is {1}", FileName, oExtension) - - Dim oSQL = $"SELECT FNICM_NEW_DOC('010', '{oContainerId}', '{GetContainerName(oContainerId)}', '{FileName}', '{oExtension}', '{_username}') FROM RDB$DATABASE;" - Dim oDocId As Int64 = Firebird.GetScalarValue(oSQL) - - If oDocId = -1 Then - _logger.Warn("Database returned -1 while creating Document Entry. File was not saved!") - Return Nothing - End If - - _logger.Debug("Database Entry created with DocId {0}", oDocId) - - oContainer.SetFile(Contents, FileName) - oContainer.SaveAs(GetContainerPath(oContainerId)) - - _logger.Debug("File saved in Container!", FileName) - - Dim oDocument = New DocumentObject(oContainerId, oDocId, FileName) - Return New DocumentResultOld(oDocument) - Catch ex As Exception - _logger.Error(ex) - Return New DocumentResultOld(ex.Message) - End Try - End Function - - Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResultOld Implements IEDMIService.UpdateFile - Try - TestFileExists(DocObject.ContainerId) - - ' TODO: update db - - Dim oFilePath = GetContainerPath(DocObject.ContainerId) - Dim oFileContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oFilePath) - - oFileContainer.SetFile(Contents, oFileContainer.GetFile.FileName) - oFileContainer.Save() - - - Return New DocumentResultOld(DocObject) - Catch ex As Exception - _logger.Error(ex) - Return Nothing - End Try - End Function - - Public Function GetFile(DocObject As DocumentObject) As DocumentResultOld Implements IEDMIService.GetFile - Try - TestFileExists(DocObject.ContainerId) - - Dim oContainerPath = GetContainerPath(DocObject.ContainerId) - Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) - Dim oContents As Byte() = oContainer.GetFile().Contents - - Return New DocumentResultOld(DocObject, oContents) - Catch ex As Exception - _logger.Error(ex) - Return New DocumentResultOld(ex.Message) - End Try - End Function - - Public Function DeleteFile(DocObject As DocumentObject) As Boolean Implements IEDMIService.DeleteFile - Try - TestFileExists(DocObject.ContainerId) - - Dim oFilePath = GetContainerPath(DocObject.ContainerId) - IO.File.Delete(oFilePath) - - 'TODO: Delete doc from db - - Return True - Catch ex As Exception - _logger.Error(ex) - Return False - End Try - End Function - - Private Function GetContainerPath(ContainerId As String) As String - Return Path.Combine(AppConfig.ContainerPath, GetContainerName(ContainerId)) - End Function - - Private Function GetContainerName(ContainerId As String) As String - Return ContainerId & ".enc" - End Function - - Private Sub TestFileExists(ContainerId) - Dim oContainerPath = GetContainerPath(ContainerId) - - If Not IO.File.Exists(oContainerPath) Then - Throw New FileNotFoundException("Container existiert nicht", oContainerPath) - End If - End Sub - - Public Function GetDocumentByDocumentId(DocumentId As Long) As DocumentResultOld Implements IEDMIService.GetDocumentByDocumentId - Try - Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE GUID = {DocumentId}" - Dim oTable = Firebird.GetDatatable(oSQL) - - If oTable.Rows.Count = 0 Then - Return New DocumentResultOld("Document not found") - End If - - Dim oRow As DataRow = oTable.Rows.Item(0) - Dim oDocument As New DocumentObject( - oRow.Item("CONTAINER_ID"), - oRow.Item("GUID"), - oRow.Item("ORIGINAL_FILENAME") - ) - - TestFileExists(oDocument.ContainerId) - - Dim oContainerPath = GetContainerPath(oDocument.ContainerId) - Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) - Dim oContents As Byte() = oContainer.GetFile().Contents - - Return New DocumentResultOld(oDocument, oContents) - Catch ex As Exception - Return New DocumentResultOld(ex.Message) - End Try - End Function - - Public Function GetDocumentByContainerId(ContainerId As String) As DocumentResultOld Implements IEDMIService.GetDocumentByContainerId - Try - Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE CONTAINER_ID = '{ContainerId}'" - Dim oTable = Firebird.GetDatatable(oSQL) - - If oTable.Rows.Count = 0 Then - Return New DocumentResultOld("Document not found") - End If - - Dim oRow As DataRow = oTable.Rows.Item(0) - Dim oDocument As New DocumentObject( - oRow.Item("CONTAINER_ID"), - oRow.Item("GUID"), - oRow.Item("ORIGINAL_FILENAME") - ) - - TestFileExists(oDocument.ContainerId) - - Dim oContainerPath = GetContainerPath(oDocument.ContainerId) - Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) - Dim oContents As Byte() = oContainer.GetFile().Contents - - Return New DocumentResultOld(oDocument, oContents) - Catch ex As Exception - Return New DocumentResultOld(ex.Message) - End Try - End Function -#End Region - -#Region "Document" +#Region "=== Document ===" ''' ''' Imports a file according to ObjectStoreId ''' @@ -436,20 +270,5 @@ Public Class EDMIService Throw New FaultException(ex.Message) End Try End Function - -#End Region - -#Region "Index" - Public Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult Implements IEDMIService.NewFileIndex - Try - Dim oSQL = $"SELECT FNIDB_NEW_DOC_VALUE({DocObject.DocumentId},'{Syskey}','{LanguageCode}','{Value}','{_username}') FROM RDB$DATABASE;" - Dim oIndexId As Int64 = Firebird.GetScalarValue(oSQL) - - Return New IndexResult(oIndexId) - Catch ex As Exception - _logger.Error(ex) - Return New IndexResult(ex.Message) - End Try - End Function #End Region End Class \ No newline at end of file diff --git a/Service.EDMIService/EDMIService.vbproj b/Service.EDMIService/EDMIService.vbproj index 3cdbcc3a..444b5c26 100644 --- a/Service.EDMIService/EDMIService.vbproj +++ b/Service.EDMIService/EDMIService.vbproj @@ -102,18 +102,12 @@ - - - - - - Component diff --git a/Service.EDMIService/Exceptions.vb b/Service.EDMIService/Exceptions.vb index e1effc7e..750f7df2 100644 --- a/Service.EDMIService/Exceptions.vb +++ b/Service.EDMIService/Exceptions.vb @@ -1,7 +1,13 @@ -Public Class Exceptions +Imports System.ServiceModel + +Public Class Exceptions + + Public Class BaseException + Inherits FaultException + End Class Public Class NoRequestException - Inherits ApplicationException + Inherits BaseException End Class End Class diff --git a/Service.EDMIService/IEDMIService.vb b/Service.EDMIService/IEDMIService.vb index f862a87e..cef612e8 100644 --- a/Service.EDMIService/IEDMIService.vb +++ b/Service.EDMIService/IEDMIService.vb @@ -28,23 +28,23 @@ Interface IEDMIService #End Region #Region "Document (with FileContainer)" - - Function NewFile(FileName As String, Contents As Byte()) As DocumentResultOld + ' + 'Function NewFile(FileName As String, Contents As Byte()) As DocumentResultOld - - Function UpdateFile(DocObject As DocumentObject, Contents As Byte()) As DocumentResultOld + ' + 'Function UpdateFile(DocObject As DocumentObject, Contents As Byte()) As DocumentResultOld - - Function GetFile(DocObject As DocumentObject) As DocumentResultOld + ' + 'Function GetFile(DocObject As DocumentObject) As DocumentResultOld - - Function DeleteFile(DocObject As DocumentObject) As Boolean + ' + 'Function DeleteFile(DocObject As DocumentObject) As Boolean - - Function GetDocumentByDocumentId(DocumentId As Int64) As DocumentResultOld + ' + 'Function GetDocumentByDocumentId(DocumentId As Int64) As DocumentResultOld - - Function GetDocumentByContainerId(ContainerId As String) As DocumentResultOld + ' + 'Function GetDocumentByContainerId(ContainerId As String) As DocumentResultOld #End Region #Region "Document (New)" @@ -59,9 +59,4 @@ Interface IEDMIService Function ListFilesForUser() As Messages.DocumentListResponse #End Region -#Region "Index" - - Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult -#End Region - End Interface \ No newline at end of file diff --git a/Service.EDMIService/Results/ContainerResult.vb b/Service.EDMIService/Results/ContainerResult.vb deleted file mode 100644 index 5b5b17fa..00000000 --- a/Service.EDMIService/Results/ContainerResult.vb +++ /dev/null @@ -1,18 +0,0 @@ -Imports DigitalData.Modules.Filesystem - - -Public Class ContainerResult - Public ReadOnly OK As Boolean - Public ReadOnly ErrorMessage As String - Public Container As FileContainerInner - - Public Sub New() - OK = True - ErrorMessage = Nothing - End Sub - - Public Sub New(ErrorMessage As String) - OK = False - Me.ErrorMessage = ErrorMessage - End Sub -End Class diff --git a/Service.EDMIService/Results/DocumentResult.vb b/Service.EDMIService/Results/DocumentResult.vb deleted file mode 100644 index 11332187..00000000 --- a/Service.EDMIService/Results/DocumentResult.vb +++ /dev/null @@ -1,31 +0,0 @@ -Imports System.Xml.Serialization - - -Public Class DocumentResult - Inherits BaseResult - - Public Document As DocumentObject - Public HasContents As Boolean = False - Public Contents As Byte() - - Public Sub New(Document As DocumentObject) - MyBase.New() - Me.Document = Document - End Sub - - Public Sub New(Document As DocumentObject, Contents As Byte()) - MyBase.New() - Me.Document = Document - Me.Contents = Contents - Me.HasContents = True - End Sub - - Public Sub New(ErrorMessage As String) - MyBase.New(ErrorMessage) - End Sub - - Public Class DocumentObject - Public FileName As String - Public FileId As String - End Class -End Class diff --git a/Service.EDMIService/Results/DocumentResultOld.vb b/Service.EDMIService/Results/DocumentResultOld.vb deleted file mode 100644 index 02202516..00000000 --- a/Service.EDMIService/Results/DocumentResultOld.vb +++ /dev/null @@ -1,26 +0,0 @@ -Imports DigitalData.Modules.Filesystem - - -Public Class DocumentResultOld - Inherits BaseResult - - Public Document As DocumentObject - Public HasContents As Boolean = False - Public Contents As Byte() - - Public Sub New(Document As DocumentObject) - MyBase.New() - Me.Document = Document - End Sub - - Public Sub New(Document As DocumentObject, Contents As Byte()) - MyBase.New() - Me.Document = Document - Me.Contents = Contents - Me.HasContents = True - End Sub - - Public Sub New(ErrorMessage As String) - MyBase.New(ErrorMessage) - End Sub -End Class diff --git a/Service.EDMIService/Results/IndexResult.vb b/Service.EDMIService/Results/IndexResult.vb deleted file mode 100644 index ac31956b..00000000 --- a/Service.EDMIService/Results/IndexResult.vb +++ /dev/null @@ -1,15 +0,0 @@ - -Public Class IndexResult - Inherits BaseResult - - Public ReadOnly IndexId As Int64 - - Public Sub New(IndexId As Int64) - MyBase.New() - Me.IndexId = IndexId - End Sub - - Public Sub New(ErrorMessage As String) - MyBase.New(ErrorMessage) - End Sub -End Class From ebc482b7b214175bf6024e287f798dcb4358addc Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 27 Apr 2020 16:22:34 +0200 Subject: [PATCH 02/12] Windream: Log if object does not exist --- Modules.Windream/Windream.vb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Modules.Windream/Windream.vb b/Modules.Windream/Windream.vb index 50866a63..7699754f 100644 --- a/Modules.Windream/Windream.vb +++ b/Modules.Windream/Windream.vb @@ -766,15 +766,15 @@ Public Class Windream 'If UsesDriveLetter Then ' Remove Driveletter eg. W:\ If oNormalizedPath.StartsWith($"{ClientDriveLetter}:\") Then - _logger.Debug($"Replacing ClientDriveLetter: [{ClientDriveLetter}]") - oNormalizedPath = oNormalizedPath.Substring(ClientDriveLetter.Length + 2) - End If + _logger.Debug($"Replacing ClientDriveLetter: [{ClientDriveLetter}]") + oNormalizedPath = oNormalizedPath.Substring(ClientDriveLetter.Length + 2) + End If 'Else If oNormalizedPath.ToLower.StartsWith(ClientBasePath.ToLower) Then - _logger.Debug($"Replacing ClientBasePath: [{ClientBasePath}]") - ' Remove Windream Base Path eg. \\windream\objects\ - oNormalizedPath = oNormalizedPath.Substring(ClientBasePath.Length - 1) - End If + _logger.Debug($"Replacing ClientBasePath: [{ClientBasePath}]") + ' Remove Windream Base Path eg. \\windream\objects\ + oNormalizedPath = oNormalizedPath.Substring(ClientBasePath.Length - 1) + End If 'End If oNormalizedPath = oNormalizedPath.Replace("\\", "\") @@ -1463,6 +1463,7 @@ Public Class Windream End If If TestObjectExists(ObjectName, ObjectType) = False Then + _logger.Warn("GetObjectByName: Object {0} does not exist!", ObjectName) Return Nothing End If @@ -1481,6 +1482,7 @@ Public Class Windream End If If TestObjectExists(ObjectName, ObjectType) = False Then + _logger.Warn("GetObjectByPath: Object {0} does not exist!", ObjectName) Return Nothing End If From 7bf03b303b798ce613cd1be01d9a81b2c2d84740 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 28 Apr 2020 11:11:54 +0200 Subject: [PATCH 03/12] EDMI: clean up service --- Service.EDMIService/EDMIService.vb | 2 +- Service.EDMIService/IEDMIService.vb | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/Service.EDMIService/EDMIService.vb b/Service.EDMIService/EDMIService.vb index 01e344a8..ed4ce628 100644 --- a/Service.EDMIService/EDMIService.vb +++ b/Service.EDMIService/EDMIService.vb @@ -239,8 +239,8 @@ Public Class EDMIService Using oSource As FileStream = IO.File.OpenRead(oFullPath) oSource.CopyTo(oDestination) End Using - oDestination.Seek(0, SeekOrigin.Begin) + Dim oMessage As New Messages.DocumentStreamResponse() With { .FileName = oFileInfo.Name, .FileContents = oDestination diff --git a/Service.EDMIService/IEDMIService.vb b/Service.EDMIService/IEDMIService.vb index cef612e8..ee963c52 100644 --- a/Service.EDMIService/IEDMIService.vb +++ b/Service.EDMIService/IEDMIService.vb @@ -27,26 +27,6 @@ Interface IEDMIService Function ExecuteNonQuery(SQL As String) As NonQueryResult #End Region -#Region "Document (with FileContainer)" - ' - 'Function NewFile(FileName As String, Contents As Byte()) As DocumentResultOld - - ' - 'Function UpdateFile(DocObject As DocumentObject, Contents As Byte()) As DocumentResultOld - - ' - 'Function GetFile(DocObject As DocumentObject) As DocumentResultOld - - ' - 'Function DeleteFile(DocObject As DocumentObject) As Boolean - - ' - 'Function GetDocumentByDocumentId(DocumentId As Int64) As DocumentResultOld - - ' - 'Function GetDocumentByContainerId(ContainerId As String) As DocumentResultOld -#End Region - #Region "Document (New)" Function ImportFile(Data As Messages.DocumentImportRequest) As Messages.DocumentImportResponse From 874e8c893cf4480d8522cb9210b84c9dc77b1868 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 28 Apr 2020 14:50:41 +0200 Subject: [PATCH 04/12] Logging: Show Method/Line Numbers for Debug Messages --- Modules.Logging/LogConfig.vb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/Modules.Logging/LogConfig.vb b/Modules.Logging/LogConfig.vb index 5b4e7e5c..66e92604 100644 --- a/Modules.Logging/LogConfig.vb +++ b/Modules.Logging/LogConfig.vb @@ -66,14 +66,12 @@ Public Class LogConfig Private Const ARCHIVE_EVERY As FileArchivePeriod = FileArchivePeriod.Day Private Const FILE_NAME_FORMAT_DEFAULT As String = "${shortdate}-${var:product}${var:suffix}.log" - Private Const FILE_NAME_FORMAT_DETAIL As String = "${shortdate}-${var:product}${var:suffix}-Detail.log" Private Const FILE_NAME_FORMAT_DEBUG As String = "${shortdate}-${var:product}${var:suffix}-Debug.log" Private Const FILE_NAME_FORMAT_ERROR As String = "${shortdate}-${var:product}${var:suffix}-Error.log" Private Const TARGET_DEFAULT As String = "defaultTarget" Private Const TARGET_ERROR_EX As String = "errorExceptionTarget" Private Const TARGET_ERROR As String = "errorTarget" - Private Const TARGET_DETAIL As String = "detailTarget" Private Const TARGET_DEBUG As String = "debugTarget" Private Const TARGET_MEMORY As String = "memoryTarget" @@ -82,10 +80,11 @@ Public Class LogConfig Private Const LOG_FORMAT_BASE As String = DATE_FORMAT_DEFAULT & "|${logger:shortName=True}|${level:uppercase=true}" Private Const LOG_FORMAT_BASE_LONG_DATE As String = DATE_FORMAT_LONG & "|${logger:shortName=True}|${level:uppercase=true}" + Private Const LOG_FORMAT_CALLSITE As String = "${callsite:className=false:fileName=true:includeSourcePath=false:methodName=true}" Private Const LOG_FORMAT_DEFAULT As String = LOG_FORMAT_BASE & " >> ${message}" Private Const LOG_FORMAT_EXCEPTION As String = LOG_FORMAT_BASE & " >> ${exception:format=Message}${newline}${exception:format=StackTrace}" - Private Const LOG_FORMAT_DEBUG As String = LOG_FORMAT_BASE_LONG_DATE & " >> ${message}" + Private Const LOG_FORMAT_DEBUG As String = LOG_FORMAT_BASE_LONG_DATE & " >> " & LOG_FORMAT_CALLSITE & " -> ${message}" Private Const LOG_FORMAT_MEMORY As String = LOG_FORMAT_BASE_LONG_DATE & " >> ${message}${newline}${exception:format=Message}${newline}${exception:format=StackTrace}" Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt" @@ -421,23 +420,11 @@ Public Class LogConfig Return errorLog End Function - Private Function GetDetailLogTarget(basePath As String) As FileTarget - Dim detailLog As New FileTarget() With { - .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DETAIL), - .Name = TARGET_DETAIL, - .Layout = LOG_FORMAT_DEFAULT, - .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEBUG_DETAIL, - .ArchiveEvery = ARCHIVE_EVERY, - .KeepFileOpen = KEEP_FILES_OPEN - } - - Return detailLog - End Function Private Function GetDebugLogTarget(basePath As String) As FileTarget Dim debugLog As New FileTarget() With { .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DEBUG), .Name = TARGET_DEBUG, - .Layout = LOG_FORMAT_DEFAULT, + .Layout = LOG_FORMAT_DEBUG, .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEBUG_DETAIL, .ArchiveEvery = ARCHIVE_EVERY, .KeepFileOpen = KEEP_FILES_OPEN From 7f59e1d1ca657e325c8f3c1b2ac0181f5643af32 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 28 Apr 2020 14:50:55 +0200 Subject: [PATCH 05/12] Version 2.0.1.0 --- Modules.Logging/My Project/AssemblyInfo.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules.Logging/My Project/AssemblyInfo.vb b/Modules.Logging/My Project/AssemblyInfo.vb index df9a9ffa..297eacca 100644 --- a/Modules.Logging/My Project/AssemblyInfo.vb +++ b/Modules.Logging/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + From 31ae07b3ebc767e8f2c8a4ed2cd37a95cce69015 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 28 Apr 2020 14:51:24 +0200 Subject: [PATCH 06/12] EDMI: fix API.Client constructor --- Modules.EDMIAPI/Client.vb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules.EDMIAPI/Client.vb b/Modules.EDMIAPI/Client.vb index b0ff42e8..8bceaa00 100644 --- a/Modules.EDMIAPI/Client.vb +++ b/Modules.EDMIAPI/Client.vb @@ -43,8 +43,10 @@ Public Class Client Dim oBinding = Channel.GetBinding() Dim oAddress = New EndpointAddress($"net.tcp://{IPAddress}:{PortNumber}/DigitalData/Services/Main") Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress) - Catch ex As Exception + _channelFactory = oFactory + Catch ex As Exception + _logger.Error(ex) End Try End Sub From 150a95643cf55a9ce66e154b1f21595dfb0e38e6 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 29 Apr 2020 15:01:41 +0200 Subject: [PATCH 07/12] ZUGFeRD: Improve logging for ZUGFeRD Service --- Modules.Interfaces/My Project/AssemblyInfo.vb | 2 +- Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb | 2 +- Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb | 8 +++++--- Modules.Jobs/My Project/AssemblyInfo.vb | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Modules.Interfaces/My Project/AssemblyInfo.vb b/Modules.Interfaces/My Project/AssemblyInfo.vb index 213861ec..73e75b1d 100644 --- a/Modules.Interfaces/My Project/AssemblyInfo.vb +++ b/Modules.Interfaces/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb b/Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb index d2382f37..17d7c5a5 100644 --- a/Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb +++ b/Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb @@ -117,7 +117,7 @@ Public Class PDFAttachments Continue For End If Else - Logger.Warn("File [{0}] was skipped because its extension [{1}] is not allowed.", oFileName, oExtension) + Logger.Debug("File [{0}] was skipped because its extension [{1}] is not allowed.", oFileName, oExtension) Continue For End If Else diff --git a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb index 2bfb4757..edbef779 100644 --- a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -27,6 +27,7 @@ Public Class ImportZUGFeRDFiles Public HISTORY_ID As Integer ' List of allowed extensions for PDF/A Attachments + ' This list should not contain xml so the zugferd xml file will be filtered out Private ReadOnly AllowedExtensions As List(Of String) = New List(Of String) From {"docx", "doc", "pdf", "xls", "xlsx", "ppt", "pptx", "txt"} Private ReadOnly _logger As Logger @@ -185,22 +186,23 @@ Public Class ImportZUGFeRDFiles Catch ex As ZUGFeRDExecption Select Case ex.ErrorType Case ZUGFeRDInterface.ErrorType.NoZugferd - _logger.Warn("File is not a valid ZUGFeRD document! Skipping.") + _logger.Warn("File [{0}] is not a valid ZUGFeRD document! Skipping.", oFile.Name) oEmailAttachmentFiles.Add(oFile) Continue For Case ZUGFeRDInterface.ErrorType.NoValidZugferd - _logger.Warn("File is an Incorrectly formatted ZUGFeRD document!") + _logger.Warn("File [{0}] is an Incorrectly formatted ZUGFeRD document!", oFile.Name) Throw New InvalidFerdException() Case Else - _logger.Warn("Unexpected Error occurred while extracting ZUGFeRD Information from file {0}", oFile.FullName) + _logger.Warn("Unexpected Error occurred while extracting ZUGFeRD Information from file {0}", oFile.Name) Throw ex End Select End Try ' Extract all attachments with the extensions specified in `AllowedExtensions`. ' If you need to extract and use embedded xml files, you need to filter out the zugferd-invoice.xml yourself. + ' Right now the zugferd-invoice.xml is filtered out because `AllowedExtensions` does not contain `xml`. Dim oAttachments = oAttachmentExtractor.Extract(oFile.FullName, AllowedExtensions) If oAttachments Is Nothing Then _logger.Warn("Attachments for file [{0}] could not be extracted", oFile.FullName) diff --git a/Modules.Jobs/My Project/AssemblyInfo.vb b/Modules.Jobs/My Project/AssemblyInfo.vb index 0fe78cac..8e2ba0be 100644 --- a/Modules.Jobs/My Project/AssemblyInfo.vb +++ b/Modules.Jobs/My Project/AssemblyInfo.vb @@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices ' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern ' übernehmen, indem Sie "*" eingeben: - + From 3ad3519201529d97151b48f26b626f73127f16a8 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 30 Apr 2020 11:40:18 +0200 Subject: [PATCH 08/12] Filesystem: Add GetCleanFilename and GetCleanPath --- Modules.Filesystem/File.vb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Modules.Filesystem/File.vb b/Modules.Filesystem/File.vb index 941e91ea..12888f33 100644 --- a/Modules.Filesystem/File.vb +++ b/Modules.Filesystem/File.vb @@ -1,4 +1,5 @@ Imports System.IO +Imports System.Text.RegularExpressions Imports DigitalData.Modules.Logging ''' File @@ -24,13 +25,46 @@ Public Class File Private ReadOnly _logger As Logger Private ReadOnly _logConfig As LogConfig + Private ReadOnly _invalidFilenameChars As String + Private ReadOnly _invalidPathChars As String + + Private Const REGEX_CLEAN_FILENAME As String = "[\\/:""<>|\b\0\r\n\t]" + Private Const REGEX_CLEAN_PATH As String = "[:""<>|\b\0\r\n\t]" + Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt" Public Sub New(LogConfig As LogConfig) _logConfig = LogConfig _logger = LogConfig.GetLogger() + + _invalidFilenameChars = String.Join("", Path.GetInvalidFileNameChars()) + _invalidPathChars = String.Join("", Path.GetInvalidPathChars()) End Sub + Public Function GetCleanFilename(FileName As String) As String + _logger.Debug("Filename before cleaning: [{0}]", FileName) + + Dim oCleanName As String = FileName + oCleanName = Regex.Replace(oCleanName, _invalidFilenameChars, String.Empty) + oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_FILENAME, String.Empty, RegexOptions.Singleline) + + _logger.Debug("Filename after cleaning: [{0}]", oCleanName) + + Return oCleanName + End Function + + Public Function GetCleanPath(FilePath As String) As String + _logger.Debug("Path before cleaning: [{0}]", FilePath) + + Dim oCleanName As String = FilePath + oCleanName = Regex.Replace(oCleanName, _invalidPathChars, String.Empty) + oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_FILENAME, String.Empty, RegexOptions.Singleline) + + _logger.Debug("Path after cleaning: [{0}]", oCleanName) + + Return oCleanName + End Function + ''' ''' Adds fileversions to given filename `Destination` if that file already exists. ''' From dfb53d60e6247e9e3c166ac315a54b6eff0b5a02 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 30 Apr 2020 11:40:54 +0200 Subject: [PATCH 09/12] Filesystem: Version 1.0.1.0 --- Modules.Filesystem/My Project/AssemblyInfo.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules.Filesystem/My Project/AssemblyInfo.vb b/Modules.Filesystem/My Project/AssemblyInfo.vb index d3b46582..33b96164 100644 --- a/Modules.Filesystem/My Project/AssemblyInfo.vb +++ b/Modules.Filesystem/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + From 857f1b1f9f6d57bf5469dd6355751401beaf4490 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 30 Apr 2020 11:45:04 +0200 Subject: [PATCH 10/12] Filesystem: Version 1.0.1.1 --- Modules.Filesystem/File.vb | 2 +- Modules.Filesystem/My Project/AssemblyInfo.vb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules.Filesystem/File.vb b/Modules.Filesystem/File.vb index 12888f33..af4dae4d 100644 --- a/Modules.Filesystem/File.vb +++ b/Modules.Filesystem/File.vb @@ -58,7 +58,7 @@ Public Class File Dim oCleanName As String = FilePath oCleanName = Regex.Replace(oCleanName, _invalidPathChars, String.Empty) - oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_FILENAME, String.Empty, RegexOptions.Singleline) + oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_PATH, String.Empty, RegexOptions.Singleline) _logger.Debug("Path after cleaning: [{0}]", oCleanName) diff --git a/Modules.Filesystem/My Project/AssemblyInfo.vb b/Modules.Filesystem/My Project/AssemblyInfo.vb index 33b96164..832d1440 100644 --- a/Modules.Filesystem/My Project/AssemblyInfo.vb +++ b/Modules.Filesystem/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + From 729b4d819589e42ec53436760c37ea58aadc3cad Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 4 May 2020 14:48:01 +0200 Subject: [PATCH 11/12] GraphQLTest: Prepare for test --- GUIs.Test.GraphQLTest/App.config | 27 +++ GUIs.Test.GraphQLTest/Config.vb | 8 + GUIs.Test.GraphQLTest/Form1.vb | 46 ----- .../GUIs.Test.GraphQLTest.vbproj | 22 ++- .../My Project/Application.Designer.vb | 2 +- .../My Project/Settings.Designer.vb | 144 ++++++++++---- .../My Project/Settings.settings | 29 ++- ...{Form1.Designer.vb => frmMain.Designer.vb} | 151 ++++++++++---- .../{Form1.resx => frmMain.resx} | 18 -- GUIs.Test.GraphQLTest/frmMain.vb | 186 ++++++++++++++++++ .../GrapQLInterface/QueryData.vb | 6 +- Modules.Interfaces/GraphQLInterface.vb | 13 +- 12 files changed, 498 insertions(+), 154 deletions(-) create mode 100644 GUIs.Test.GraphQLTest/Config.vb delete mode 100644 GUIs.Test.GraphQLTest/Form1.vb rename GUIs.Test.GraphQLTest/{Form1.Designer.vb => frmMain.Designer.vb} (52%) rename GUIs.Test.GraphQLTest/{Form1.resx => frmMain.resx} (94%) create mode 100644 GUIs.Test.GraphQLTest/frmMain.vb diff --git a/GUIs.Test.GraphQLTest/App.config b/GUIs.Test.GraphQLTest/App.config index 5534e287..5b172ccb 100644 --- a/GUIs.Test.GraphQLTest/App.config +++ b/GUIs.Test.GraphQLTest/App.config @@ -1,6 +1,33 @@  + + +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GUIs.Test.GraphQLTest/Config.vb b/GUIs.Test.GraphQLTest/Config.vb new file mode 100644 index 00000000..1ab7de40 --- /dev/null +++ b/GUIs.Test.GraphQLTest/Config.vb @@ -0,0 +1,8 @@ +Public Class Config + Public Property ConnectionString As String = "Server=SERVER;Database=DATABASE;User Id=sa;Password=dd" + Public Property CertificateFile As String = "C:\Path\To\Cert.pfx" + Public Property CertificatePass As String = "CertificatePassword" + Public Property Email As String = "foo.bar@wisag.de" + Public Property Password As String = "Password" + Public Property BaseUrl As String = "https://data.api.wisag.de:8443" +End Class diff --git a/GUIs.Test.GraphQLTest/Form1.vb b/GUIs.Test.GraphQLTest/Form1.vb deleted file mode 100644 index 4c2a939b..00000000 --- a/GUIs.Test.GraphQLTest/Form1.vb +++ /dev/null @@ -1,46 +0,0 @@ -Imports System.IO -Imports DigitalData.Modules.Interfaces -Imports DigitalData.Modules.Logging - -Public Class Form1 - Private _LogConfig As LogConfig - Private _Interface As GraphQLInterface - - Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load - _LogConfig = New LogConfig(LogConfig.PathType.CurrentDirectory) - End Sub - - Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click - Try - _Interface = New GraphQLInterface(_LogConfig, - txtBaseUrl.Text, - txtUsername.Text, - txtPassword.Text, - txtCertFile.Text, - txtCertPass.Text) - - Dim oLoginResponse = _Interface.Login() - _Interface.SaveCookies(oLoginResponse.Cookies.Item(0)) - - Dim oDataResponse = _Interface.GetData(txtQuery.Text, "Nls") - Dim oResult As String - - Using oStream = oDataResponse.GetResponseStream() - Using oReader As New StreamReader(oStream) - oResult = oReader.ReadToEnd() - End Using - End Using - - File.WriteAllText("E:\JenneJ\WISAG\results.json", oResult) - - Dim oObj = Newtonsoft.Json.JsonConvert.DeserializeObject(oResult) - Dim oJson = Newtonsoft.Json.JsonConvert.SerializeObject(oObj, Newtonsoft.Json.Formatting.Indented) - - txtResults.Text = oJson - - Dim oLogoutResponse = _Interface.Logout() - Catch ex As Exception - MsgBox(ex.Message, MsgBoxStyle.Critical) - End Try - End Sub -End Class diff --git a/GUIs.Test.GraphQLTest/GUIs.Test.GraphQLTest.vbproj b/GUIs.Test.GraphQLTest/GUIs.Test.GraphQLTest.vbproj index eefb6998..08f44e28 100644 --- a/GUIs.Test.GraphQLTest/GUIs.Test.GraphQLTest.vbproj +++ b/GUIs.Test.GraphQLTest/GUIs.Test.GraphQLTest.vbproj @@ -84,11 +84,12 @@ - + + Form - - Form1.vb + + frmMain.vb Form @@ -108,8 +109,8 @@ - - Form1.vb + + frmMain.vb VbMyResourcesResXFileCodeGenerator @@ -132,6 +133,14 @@ + + {44982f9b-6116-44e2-85d0-f39650b1ef99} + Config + + + {EAF0EA75-5FA7-485D-89C7-B2D843B03A96} + Database + {AB6F09BF-E794-4F6A-94BB-C97C0BA84D64} Interfaces @@ -141,5 +150,8 @@ Logging + + + \ No newline at end of file diff --git a/GUIs.Test.GraphQLTest/My Project/Application.Designer.vb b/GUIs.Test.GraphQLTest/My Project/Application.Designer.vb index bfc32831..3a0a94ec 100644 --- a/GUIs.Test.GraphQLTest/My Project/Application.Designer.vb +++ b/GUIs.Test.GraphQLTest/My Project/Application.Designer.vb @@ -32,7 +32,7 @@ Namespace My _ Protected Overrides Sub OnCreateMainForm() - Me.MainForm = Global.GUIs.Test.GraphQLTest.Form1 + Me.MainForm = Global.GUIs.Test.GraphQLTest.frmMain End Sub End Class End Namespace diff --git a/GUIs.Test.GraphQLTest/My Project/Settings.Designer.vb b/GUIs.Test.GraphQLTest/My Project/Settings.Designer.vb index d6fe46e5..fb6cb655 100644 --- a/GUIs.Test.GraphQLTest/My Project/Settings.Designer.vb +++ b/GUIs.Test.GraphQLTest/My Project/Settings.Designer.vb @@ -1,10 +1,10 @@ '------------------------------------------------------------------------------ ' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 +' Dieser Code wurde von einem Tool generiert. +' Laufzeitversion:4.0.30319.42000 ' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. +' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +' der Code erneut generiert wird. ' '------------------------------------------------------------------------------ @@ -13,57 +13,129 @@ Option Explicit On Namespace My - - _ + + _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) - -#Region "My.Settings Auto-Save Functionality" + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + +#Region "Automatische My.Settings-Speicherfunktion" #If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean + Private Shared addedHandler As Boolean - Private Shared addedHandlerLockObject As New Object + Private Shared addedHandlerLockObject As New Object - _ - Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub + _ + Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub #End If #End Region - + Public Shared ReadOnly Property [Default]() As MySettings Get - + #If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If #End If Return defaultInstance End Get End Property + + _ + Public Property ConnectionString() As String + Get + Return CType(Me("ConnectionString"),String) + End Get + Set + Me("ConnectionString") = value + End Set + End Property + + _ + Public Property CertificateFile() As String + Get + Return CType(Me("CertificateFile"),String) + End Get + Set + Me("CertificateFile") = value + End Set + End Property + + _ + Public Property CertificatePass() As String + Get + Return CType(Me("CertificatePass"),String) + End Get + Set + Me("CertificatePass") = value + End Set + End Property + + _ + Public Property Email() As String + Get + Return CType(Me("Email"),String) + End Get + Set + Me("Email") = value + End Set + End Property + + _ + Public Property Password() As String + Get + Return CType(Me("Password"),String) + End Get + Set + Me("Password") = value + End Set + End Property + + _ + Public Property BaseUrl() As String + Get + Return CType(Me("BaseUrl"),String) + End Get + Set + Me("BaseUrl") = value + End Set + End Property End Class End Namespace Namespace My - - _ + + _ Friend Module MySettingsProperty - - _ + + _ Friend ReadOnly Property Settings() As Global.GUIs.Test.GraphQLTest.My.MySettings Get Return Global.GUIs.Test.GraphQLTest.My.MySettings.Default diff --git a/GUIs.Test.GraphQLTest/My Project/Settings.settings b/GUIs.Test.GraphQLTest/My Project/Settings.settings index 85b890b3..122a7383 100644 --- a/GUIs.Test.GraphQLTest/My Project/Settings.settings +++ b/GUIs.Test.GraphQLTest/My Project/Settings.settings @@ -1,7 +1,24 @@  - - - - - - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GUIs.Test.GraphQLTest/Form1.Designer.vb b/GUIs.Test.GraphQLTest/frmMain.Designer.vb similarity index 52% rename from GUIs.Test.GraphQLTest/Form1.Designer.vb rename to GUIs.Test.GraphQLTest/frmMain.Designer.vb index c3c65c59..c9b8db46 100644 --- a/GUIs.Test.GraphQLTest/Form1.Designer.vb +++ b/GUIs.Test.GraphQLTest/frmMain.Designer.vb @@ -1,5 +1,5 @@  _ -Partial Class Form1 +Partial Class frmMain Inherits System.Windows.Forms.Form 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. @@ -22,7 +22,6 @@ Partial Class Form1 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. _ Private Sub InitializeComponent() - Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1)) Me.Button1 = New System.Windows.Forms.Button() Me.txtBaseUrl = New System.Windows.Forms.TextBox() Me.txtUsername = New System.Windows.Forms.TextBox() @@ -35,55 +34,64 @@ Partial Class Form1 Me.Label4 = New System.Windows.Forms.Label() Me.Label5 = New System.Windows.Forms.Label() Me.txtResults = New System.Windows.Forms.TextBox() - Me.txtQuery = New System.Windows.Forms.TextBox() + Me.txtConnectionString = New System.Windows.Forms.TextBox() + Me.Label6 = New System.Windows.Forms.Label() + Me.ComboBox1 = New System.Windows.Forms.ComboBox() + Me.Label7 = New System.Windows.Forms.Label() + Me.TabControl1 = New System.Windows.Forms.TabControl() + Me.TabPage1 = New System.Windows.Forms.TabPage() + Me.btnLogin = New System.Windows.Forms.Button() + Me.ProgressBar1 = New System.Windows.Forms.ProgressBar() + Me.TabControl1.SuspendLayout() + Me.TabPage1.SuspendLayout() Me.SuspendLayout() ' 'Button1 ' - Me.Button1.Location = New System.Drawing.Point(15, 407) + Me.Button1.Location = New System.Drawing.Point(826, 300) Me.Button1.Name = "Button1" - Me.Button1.Size = New System.Drawing.Size(318, 31) + Me.Button1.Size = New System.Drawing.Size(96, 31) Me.Button1.TabIndex = 0 Me.Button1.Text = "Run!" Me.Button1.UseVisualStyleBackColor = True ' 'txtBaseUrl ' - Me.txtBaseUrl.Location = New System.Drawing.Point(86, 6) + Me.txtBaseUrl.Location = New System.Drawing.Point(106, 6) Me.txtBaseUrl.Name = "txtBaseUrl" - Me.txtBaseUrl.Size = New System.Drawing.Size(247, 20) + Me.txtBaseUrl.Size = New System.Drawing.Size(338, 20) Me.txtBaseUrl.TabIndex = 1 - Me.txtBaseUrl.Text = "https://data.api.wisag.de:8090" + Me.txtBaseUrl.Text = "https://data.api.wisag.de:8443" ' 'txtUsername ' - Me.txtUsername.Location = New System.Drawing.Point(86, 32) + Me.txtUsername.Location = New System.Drawing.Point(106, 32) Me.txtUsername.Name = "txtUsername" - Me.txtUsername.Size = New System.Drawing.Size(247, 20) + Me.txtUsername.Size = New System.Drawing.Size(338, 20) Me.txtUsername.TabIndex = 1 Me.txtUsername.Text = "j.jenne@digitaldata.works" ' 'txtPassword ' - Me.txtPassword.Location = New System.Drawing.Point(86, 58) + Me.txtPassword.Location = New System.Drawing.Point(106, 58) Me.txtPassword.Name = "txtPassword" - Me.txtPassword.Size = New System.Drawing.Size(247, 20) + Me.txtPassword.Size = New System.Drawing.Size(338, 20) Me.txtPassword.TabIndex = 1 Me.txtPassword.Text = "DigitalData01!" ' 'txtCertFile ' - Me.txtCertFile.Location = New System.Drawing.Point(86, 84) + Me.txtCertFile.Location = New System.Drawing.Point(106, 84) Me.txtCertFile.Name = "txtCertFile" - Me.txtCertFile.Size = New System.Drawing.Size(247, 20) + Me.txtCertFile.Size = New System.Drawing.Size(338, 20) Me.txtCertFile.TabIndex = 1 Me.txtCertFile.Text = "E:\JenneJ\WISAG\jonathanjenne.pfx" ' 'txtCertPass ' - Me.txtCertPass.Location = New System.Drawing.Point(86, 110) + Me.txtCertPass.Location = New System.Drawing.Point(106, 110) Me.txtCertPass.Name = "txtCertPass" - Me.txtCertPass.Size = New System.Drawing.Size(247, 20) + Me.txtCertPass.Size = New System.Drawing.Size(338, 20) Me.txtCertPass.TabIndex = 1 Me.txtCertPass.Text = "jonathanjenne" ' @@ -134,44 +142,114 @@ Partial Class Form1 ' 'txtResults ' + Me.txtResults.Dock = System.Windows.Forms.DockStyle.Fill Me.txtResults.Font = New System.Drawing.Font("Consolas", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.txtResults.Location = New System.Drawing.Point(339, 6) + Me.txtResults.Location = New System.Drawing.Point(3, 3) Me.txtResults.Multiline = True Me.txtResults.Name = "txtResults" Me.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical - Me.txtResults.Size = New System.Drawing.Size(881, 432) + Me.txtResults.Size = New System.Drawing.Size(458, 260) Me.txtResults.TabIndex = 3 ' - 'txtQuery + 'txtConnectionString ' - Me.txtQuery.Font = New System.Drawing.Font("Consolas", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.txtQuery.Location = New System.Drawing.Point(15, 136) - Me.txtQuery.Multiline = True - Me.txtQuery.Name = "txtQuery" - Me.txtQuery.Size = New System.Drawing.Size(318, 265) - Me.txtQuery.TabIndex = 4 - Me.txtQuery.Text = resources.GetString("txtQuery.Text") + Me.txtConnectionString.Location = New System.Drawing.Point(106, 136) + Me.txtConnectionString.Multiline = True + Me.txtConnectionString.Name = "txtConnectionString" + Me.txtConnectionString.Size = New System.Drawing.Size(338, 98) + Me.txtConnectionString.TabIndex = 1 ' - 'Form1 + 'Label6 + ' + Me.Label6.AutoSize = True + Me.Label6.Location = New System.Drawing.Point(12, 139) + Me.Label6.Name = "Label6" + Me.Label6.Size = New System.Drawing.Size(88, 13) + Me.Label6.TabIndex = 2 + Me.Label6.Text = "ConnectionString" + ' + 'ComboBox1 + ' + Me.ComboBox1.FormattingEnabled = True + Me.ComboBox1.Items.AddRange(New Object() {"SAPDaten"}) + Me.ComboBox1.Location = New System.Drawing.Point(106, 240) + Me.ComboBox1.Name = "ComboBox1" + Me.ComboBox1.Size = New System.Drawing.Size(338, 21) + Me.ComboBox1.TabIndex = 4 + ' + 'Label7 + ' + Me.Label7.AutoSize = True + Me.Label7.Location = New System.Drawing.Point(12, 243) + Me.Label7.Name = "Label7" + Me.Label7.Size = New System.Drawing.Size(35, 13) + Me.Label7.TabIndex = 2 + Me.Label7.Text = "Query" + ' + 'TabControl1 + ' + Me.TabControl1.Controls.Add(Me.TabPage1) + Me.TabControl1.Location = New System.Drawing.Point(450, 6) + Me.TabControl1.Name = "TabControl1" + Me.TabControl1.SelectedIndex = 0 + Me.TabControl1.Size = New System.Drawing.Size(472, 292) + Me.TabControl1.TabIndex = 5 + ' + 'TabPage1 + ' + Me.TabPage1.Controls.Add(Me.txtResults) + Me.TabPage1.Location = New System.Drawing.Point(4, 22) + Me.TabPage1.Name = "TabPage1" + Me.TabPage1.Padding = New System.Windows.Forms.Padding(3) + Me.TabPage1.Size = New System.Drawing.Size(464, 266) + Me.TabPage1.TabIndex = 0 + Me.TabPage1.Text = "Raw GraphQL Result" + Me.TabPage1.UseVisualStyleBackColor = True + ' + 'btnLogin + ' + Me.btnLogin.Location = New System.Drawing.Point(724, 300) + Me.btnLogin.Name = "btnLogin" + Me.btnLogin.Size = New System.Drawing.Size(96, 31) + Me.btnLogin.TabIndex = 0 + Me.btnLogin.Text = "Login" + Me.btnLogin.UseVisualStyleBackColor = True + ' + 'ProgressBar1 + ' + Me.ProgressBar1.Location = New System.Drawing.Point(12, 311) + Me.ProgressBar1.Name = "ProgressBar1" + Me.ProgressBar1.Size = New System.Drawing.Size(432, 23) + Me.ProgressBar1.TabIndex = 6 + ' + 'frmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(1232, 450) - Me.Controls.Add(Me.txtQuery) - Me.Controls.Add(Me.txtResults) + Me.ClientSize = New System.Drawing.Size(934, 346) + Me.Controls.Add(Me.ProgressBar1) + Me.Controls.Add(Me.TabControl1) + Me.Controls.Add(Me.ComboBox1) + Me.Controls.Add(Me.Label7) + Me.Controls.Add(Me.Label6) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) + Me.Controls.Add(Me.txtConnectionString) Me.Controls.Add(Me.txtCertPass) Me.Controls.Add(Me.txtCertFile) Me.Controls.Add(Me.txtPassword) Me.Controls.Add(Me.txtUsername) Me.Controls.Add(Me.txtBaseUrl) + Me.Controls.Add(Me.btnLogin) Me.Controls.Add(Me.Button1) - Me.Name = "Form1" - Me.Text = "GraphQL Interface Test" + Me.Name = "frmMain" + Me.Text = "GraphQL Interface" + Me.TabControl1.ResumeLayout(False) + Me.TabPage1.ResumeLayout(False) + Me.TabPage1.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() @@ -189,5 +267,12 @@ Partial Class Form1 Friend WithEvents Label4 As Label Friend WithEvents Label5 As Label Friend WithEvents txtResults As TextBox - Friend WithEvents txtQuery As TextBox + Friend WithEvents txtConnectionString As TextBox + Friend WithEvents Label6 As Label + Friend WithEvents ComboBox1 As ComboBox + Friend WithEvents Label7 As Label + Friend WithEvents TabControl1 As TabControl + Friend WithEvents TabPage1 As TabPage + Friend WithEvents btnLogin As Button + Friend WithEvents ProgressBar1 As ProgressBar End Class diff --git a/GUIs.Test.GraphQLTest/Form1.resx b/GUIs.Test.GraphQLTest/frmMain.resx similarity index 94% rename from GUIs.Test.GraphQLTest/Form1.resx rename to GUIs.Test.GraphQLTest/frmMain.resx index de5f15ff..1af7de15 100644 --- a/GUIs.Test.GraphQLTest/Form1.resx +++ b/GUIs.Test.GraphQLTest/frmMain.resx @@ -117,22 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - query Nls{ - niederlassungen { - niederlassungen { - mdnr - mdkurzbezeichnung - bezeichnung - sparte { - id - name - __typename - } - __typename - } - __typename - } -} - \ No newline at end of file diff --git a/GUIs.Test.GraphQLTest/frmMain.vb b/GUIs.Test.GraphQLTest/frmMain.vb new file mode 100644 index 00000000..ea842647 --- /dev/null +++ b/GUIs.Test.GraphQLTest/frmMain.vb @@ -0,0 +1,186 @@ +Imports System.IO +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Interfaces +Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Config +Imports Newtonsoft.Json +Imports Newtonsoft.Json.Linq + +Public Class frmMain + Private _LogConfig As LogConfig + Private _Logger As Logger + Private _Interface As GraphQLInterface + Private _MSSQL As MSSQLServer + Private _Config As ConfigManager(Of Config) + Private _Datapools As New List(Of String) From { + "sap_aviation", + "sap_facility", + "sap_holding" + } + + Public Class SAPData + Public sapdaten As List(Of SAPDataItem) + End Class + + Public Class SAPDataItem + Public buchungskreis As String + Public kostenstelle As String + Public beschreibung As String + Public gueltig_bis As String + End Class + + Const GRAPHQL_QUERY_SAP_DATA = " + query SAPDaten { + sapdaten(datenpool: __DATA_POOL__) { + sapdaten { + buchungskreis + kostenstelle + beschreibung + gueltig_bis + } + } + } + " + + Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load + Try + Dim oStartupPath As String = AppDomain.CurrentDomain.BaseDirectory + + _LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oStartupPath) With { + .Debug = True + } + _Logger = _LogConfig.GetLogger() + _Config = New ConfigManager(Of Config)(_LogConfig, oStartupPath) + + txtBaseUrl.Text = _Config.Config.BaseUrl + txtUsername.Text = _Config.Config.Email + txtPassword.Text = _Config.Config.Password + txtCertFile.Text = _Config.Config.CertificateFile + txtCertPass.Text = _Config.Config.CertificatePass + txtConnectionString.Text = _Config.Config.ConnectionString + + ComboBox1.SelectedIndex = 0 + + _MSSQL = New MSSQLServer(_LogConfig, _Config.Config.ConnectionString) + Catch ex As Exception + _Logger.Error(ex) + MsgBox(ex.Message, MsgBoxStyle.Critical, Text) + End Try + End Sub + + Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click + Try + _Interface = New GraphQLInterface(_LogConfig, + txtBaseUrl.Text, + txtUsername.Text, + txtPassword.Text, + txtCertFile.Text, + txtCertPass.Text) + + Dim oResponse = _Interface.Login + _Interface.SaveCookies(oResponse.Cookies.Item(0)) + + If oResponse.StatusCode = Net.HttpStatusCode.OK Then + MsgBox("Login Successful!", MsgBoxStyle.Information, Text) + Else + MsgBox("Login failed! Check Certificate and User Credentials!", MsgBoxStyle.Critical, Text) + End If + Catch ex As Exception + _Logger.Error(ex) + MsgBox(ex.Message, MsgBoxStyle.Critical, Text) + End Try + End Sub + + Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click + Try + + If _Interface Is Nothing Then + MsgBox("Please login first!", MsgBoxStyle.Exclamation, Text) + Exit Sub + End If + + If ComboBox1.SelectedIndex = -1 Then + MsgBox("Please select a query!", MsgBoxStyle.Exclamation, Text) + Exit Sub + End If + + If ComboBox1.Text = "SAPDaten" Then + _MSSQL.ExecuteNonQuery("DELETE FROM TBCUST_SYNC_API_SAPDATEN") + + txtResults.Text = String.Empty + + For Each oDatapool In _Datapools + Dim oQuery As String = GRAPHQL_QUERY_SAP_DATA.Trim.Replace("__DATA_POOL__", oDatapool) + Dim oDataResponse = _Interface.GetData(oQuery, "SAPDaten") + Dim oResult As String + + Using oStream = oDataResponse.GetResponseStream() + Using oReader As New StreamReader(oStream) + oResult = oReader.ReadToEnd() + End Using + End Using + + Dim oObj As JObject = JsonConvert.DeserializeObject(oResult) + Dim oData As SAPData = ConvertResponse(oResult) + + _Logger.Debug("Inserting [{0}] items for datapool [{1}]", oData.sapdaten.Count, oDatapool) + + Dim oCounter As Integer = 0 + Dim oTotal As Integer = oData.sapdaten.Count + ProgressBar1.Maximum = oTotal + ProgressBar1.Value = oCounter + + For Each oItem As SAPDataItem In oData.sapdaten + Dim oSQL = $"INSERT INTO TBCUST_SYNC_API_SAPDATEN (BESCHREIBUNG, BUCHUNGSKREIS, KOSTENSTELLE, GUELTIG_BIS) VALUES ('{oItem.beschreibung}', '{oItem.buchungskreis}', '{oItem.kostenstelle}', '{oItem.gueltig_bis}')" + Dim oSuccess = _MSSQL.ExecuteNonQuery(oSQL) + + If oSuccess Then + _Logger.Debug("Record [{0}] inserted!", oItem.beschreibung) + End If + Next + + txtResults.Text &= "--------------------------------------------" & vbNewLine + txtResults.Text &= $"--- Datapool: {oDatapool}" & vbNewLine + txtResults.Text &= JsonConvert.SerializeObject(oObj, Formatting.Indented) & vbNewLine + + oCounter += 1 + ProgressBar1.Value = oCounter + Next + Else + MsgBox("Unknown query!", MsgBoxStyle.Exclamation, Text) + Exit Sub + End If + Catch ex As Exception + _Logger.Error(ex) + MsgBox(ex.Message, MsgBoxStyle.Critical) + End Try + End Sub + + Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing + Try + Dim oLogoutResponse = _Interface.Logout() + If oLogoutResponse.StatusCode = Net.HttpStatusCode.OK Then + _Logger.Info("Logout successful.") + End If + + _Config.Config.ConnectionString = txtConnectionString.Text + _Config.Config.BaseUrl = txtBaseUrl.Text + _Config.Config.CertificateFile = txtCertFile.Text + _Config.Config.CertificatePass = txtCertPass.Text + _Config.Config.Email = txtUsername.Text + _Config.Config.Password = txtPassword.Text + + _Config.Save() + Catch ex As Exception + _Logger.Error(ex) + End Try + End Sub + + Public Function ConvertResponse(JsonString As String) As SAPData + Dim oObj As JObject = JObject.Parse(JsonString)("data")("sapdaten") + Dim oString As String = JsonConvert.SerializeObject(oObj, Formatting.None) + Dim oSAPData As SAPData = JsonConvert.DeserializeObject(Of SAPData)(oString) + + Return oSAPData + End Function +End Class diff --git a/Modules.Interfaces/GrapQLInterface/QueryData.vb b/Modules.Interfaces/GrapQLInterface/QueryData.vb index 6081f1c6..4bdc356a 100644 --- a/Modules.Interfaces/GrapQLInterface/QueryData.vb +++ b/Modules.Interfaces/GrapQLInterface/QueryData.vb @@ -1,5 +1,5 @@ Public Class QueryData - Public Query As String - Public OperationName As String - Public Variables As New Object + Public query As String + Public operationName As String + Public variables As New Object End Class diff --git a/Modules.Interfaces/GraphQLInterface.vb b/Modules.Interfaces/GraphQLInterface.vb index 8cb39dd9..3b1b7d6d 100644 --- a/Modules.Interfaces/GraphQLInterface.vb +++ b/Modules.Interfaces/GraphQLInterface.vb @@ -71,11 +71,12 @@ Public Class GraphQLInterface Public Function GetData(Query As String, OperationName As String) As HttpWebResponse Try Dim oQueryData As New QueryData() With { - .OperationName = OperationName, - .Query = Query, - .Variables = New Object - } - Dim oBytes = ToBytes(JsonConvert.SerializeObject(oQueryData)) + .operationName = OperationName, + .query = Query, + .variables = New Object + } + Dim oJson = JsonConvert.SerializeObject(oQueryData) + Dim oBytes = ToBytes(oJson) Dim oRequest = GetRequest("/graphql", oBytes) Using stream = oRequest.GetRequestStream() @@ -107,7 +108,7 @@ Public Class GraphQLInterface Private Function GetCookies() As CookieContainer If _cookieJar Is Nothing Then - _cookieJar = New CookieContainer() + _cookieJar = New CookieContainer(300, 20, 8192) End If Return _cookieJar From 6e577627d3eb3ff36600f29a4a277d9c290f67e2 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 5 May 2020 13:21:35 +0200 Subject: [PATCH 12/12] GraphQLTest: Add Proxy config --- GUIs.Test.GraphQLTest/Config.vb | 13 +++ GUIs.Test.GraphQLTest/frmMain.Designer.vb | 106 ++++++++++++++++++++-- GUIs.Test.GraphQLTest/frmMain.vb | 43 +++++++-- Modules.Interfaces/GraphQLInterface.vb | 10 +- 4 files changed, 154 insertions(+), 18 deletions(-) diff --git a/GUIs.Test.GraphQLTest/Config.vb b/GUIs.Test.GraphQLTest/Config.vb index 1ab7de40..790b811a 100644 --- a/GUIs.Test.GraphQLTest/Config.vb +++ b/GUIs.Test.GraphQLTest/Config.vb @@ -5,4 +5,17 @@ Public Property Email As String = "foo.bar@wisag.de" Public Property Password As String = "Password" Public Property BaseUrl As String = "https://data.api.wisag.de:8443" + + Public Property ProxyHost As String = "" + Public Property ProxyPort As Integer = 0 + Public Property ProxyUsername As String = "" + Public Property ProxyPassword As String = "" + + Public Function HasProxySet() As Boolean + Return ProxyHost <> "" And ProxyPort > 0 + End Function + + Public Function HasProxyCredentialsSet() As Boolean + Return ProxyUsername <> "" And ProxyPassword <> "" + End Function End Class diff --git a/GUIs.Test.GraphQLTest/frmMain.Designer.vb b/GUIs.Test.GraphQLTest/frmMain.Designer.vb index c9b8db46..a226e067 100644 --- a/GUIs.Test.GraphQLTest/frmMain.Designer.vb +++ b/GUIs.Test.GraphQLTest/frmMain.Designer.vb @@ -42,13 +42,21 @@ Partial Class frmMain Me.TabPage1 = New System.Windows.Forms.TabPage() Me.btnLogin = New System.Windows.Forms.Button() Me.ProgressBar1 = New System.Windows.Forms.ProgressBar() + Me.txtProxyHost = New System.Windows.Forms.TextBox() + Me.txtProxyUser = New System.Windows.Forms.TextBox() + Me.txtProxyPass = New System.Windows.Forms.TextBox() + Me.Label8 = New System.Windows.Forms.Label() + Me.Label9 = New System.Windows.Forms.Label() + Me.Label10 = New System.Windows.Forms.Label() + Me.txtProxyPort = New System.Windows.Forms.TextBox() + Me.Label11 = New System.Windows.Forms.Label() Me.TabControl1.SuspendLayout() Me.TabPage1.SuspendLayout() Me.SuspendLayout() ' 'Button1 ' - Me.Button1.Location = New System.Drawing.Point(826, 300) + Me.Button1.Location = New System.Drawing.Point(826, 386) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(96, 31) Me.Button1.TabIndex = 0 @@ -148,7 +156,7 @@ Partial Class frmMain Me.txtResults.Multiline = True Me.txtResults.Name = "txtResults" Me.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical - Me.txtResults.Size = New System.Drawing.Size(458, 260) + Me.txtResults.Size = New System.Drawing.Size(458, 342) Me.txtResults.TabIndex = 3 ' 'txtConnectionString @@ -172,7 +180,7 @@ Partial Class frmMain ' Me.ComboBox1.FormattingEnabled = True Me.ComboBox1.Items.AddRange(New Object() {"SAPDaten"}) - Me.ComboBox1.Location = New System.Drawing.Point(106, 240) + Me.ComboBox1.Location = New System.Drawing.Point(106, 352) Me.ComboBox1.Name = "ComboBox1" Me.ComboBox1.Size = New System.Drawing.Size(338, 21) Me.ComboBox1.TabIndex = 4 @@ -180,7 +188,7 @@ Partial Class frmMain 'Label7 ' Me.Label7.AutoSize = True - Me.Label7.Location = New System.Drawing.Point(12, 243) + Me.Label7.Location = New System.Drawing.Point(12, 355) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(35, 13) Me.Label7.TabIndex = 2 @@ -192,7 +200,7 @@ Partial Class frmMain Me.TabControl1.Location = New System.Drawing.Point(450, 6) Me.TabControl1.Name = "TabControl1" Me.TabControl1.SelectedIndex = 0 - Me.TabControl1.Size = New System.Drawing.Size(472, 292) + Me.TabControl1.Size = New System.Drawing.Size(472, 374) Me.TabControl1.TabIndex = 5 ' 'TabPage1 @@ -201,14 +209,14 @@ Partial Class frmMain Me.TabPage1.Location = New System.Drawing.Point(4, 22) Me.TabPage1.Name = "TabPage1" Me.TabPage1.Padding = New System.Windows.Forms.Padding(3) - Me.TabPage1.Size = New System.Drawing.Size(464, 266) + Me.TabPage1.Size = New System.Drawing.Size(464, 348) Me.TabPage1.TabIndex = 0 Me.TabPage1.Text = "Raw GraphQL Result" Me.TabPage1.UseVisualStyleBackColor = True ' 'btnLogin ' - Me.btnLogin.Location = New System.Drawing.Point(724, 300) + Me.btnLogin.Location = New System.Drawing.Point(724, 386) Me.btnLogin.Name = "btnLogin" Me.btnLogin.Size = New System.Drawing.Size(96, 31) Me.btnLogin.TabIndex = 0 @@ -217,16 +225,80 @@ Partial Class frmMain ' 'ProgressBar1 ' - Me.ProgressBar1.Location = New System.Drawing.Point(12, 311) + Me.ProgressBar1.Location = New System.Drawing.Point(12, 394) Me.ProgressBar1.Name = "ProgressBar1" Me.ProgressBar1.Size = New System.Drawing.Size(432, 23) Me.ProgressBar1.TabIndex = 6 ' + 'txtProxyHost + ' + Me.txtProxyHost.Location = New System.Drawing.Point(106, 240) + Me.txtProxyHost.Name = "txtProxyHost" + Me.txtProxyHost.Size = New System.Drawing.Size(338, 20) + Me.txtProxyHost.TabIndex = 1 + ' + 'txtProxyUser + ' + Me.txtProxyUser.Location = New System.Drawing.Point(106, 292) + Me.txtProxyUser.Name = "txtProxyUser" + Me.txtProxyUser.Size = New System.Drawing.Size(338, 20) + Me.txtProxyUser.TabIndex = 1 + ' + 'txtProxyPass + ' + Me.txtProxyPass.Location = New System.Drawing.Point(106, 318) + Me.txtProxyPass.Name = "txtProxyPass" + Me.txtProxyPass.Size = New System.Drawing.Size(338, 20) + Me.txtProxyPass.TabIndex = 1 + ' + 'Label8 + ' + Me.Label8.AutoSize = True + Me.Label8.Location = New System.Drawing.Point(12, 243) + Me.Label8.Name = "Label8" + Me.Label8.Size = New System.Drawing.Size(58, 13) + Me.Label8.TabIndex = 2 + Me.Label8.Text = "Proxy Host" + ' + 'Label9 + ' + Me.Label9.AutoSize = True + Me.Label9.Location = New System.Drawing.Point(12, 295) + Me.Label9.Name = "Label9" + Me.Label9.Size = New System.Drawing.Size(58, 13) + Me.Label9.TabIndex = 2 + Me.Label9.Text = "Proxy User" + ' + 'Label10 + ' + Me.Label10.AutoSize = True + Me.Label10.Location = New System.Drawing.Point(12, 321) + Me.Label10.Name = "Label10" + Me.Label10.Size = New System.Drawing.Size(82, 13) + Me.Label10.TabIndex = 2 + Me.Label10.Text = "Proxy Password" + ' + 'txtProxyPort + ' + Me.txtProxyPort.Location = New System.Drawing.Point(106, 266) + Me.txtProxyPort.Name = "txtProxyPort" + Me.txtProxyPort.Size = New System.Drawing.Size(338, 20) + Me.txtProxyPort.TabIndex = 1 + ' + 'Label11 + ' + Me.Label11.AutoSize = True + Me.Label11.Location = New System.Drawing.Point(12, 269) + Me.Label11.Name = "Label11" + Me.Label11.Size = New System.Drawing.Size(55, 13) + Me.Label11.TabIndex = 2 + Me.Label11.Text = "Proxy Port" + ' 'frmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(934, 346) + Me.ClientSize = New System.Drawing.Size(934, 429) Me.Controls.Add(Me.ProgressBar1) Me.Controls.Add(Me.TabControl1) Me.Controls.Add(Me.ComboBox1) @@ -234,14 +306,22 @@ Partial Class frmMain Me.Controls.Add(Me.Label6) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.Label4) + Me.Controls.Add(Me.Label10) Me.Controls.Add(Me.Label3) + Me.Controls.Add(Me.Label9) Me.Controls.Add(Me.Label2) + Me.Controls.Add(Me.Label11) + Me.Controls.Add(Me.Label8) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.txtConnectionString) Me.Controls.Add(Me.txtCertPass) Me.Controls.Add(Me.txtCertFile) + Me.Controls.Add(Me.txtProxyPass) Me.Controls.Add(Me.txtPassword) + Me.Controls.Add(Me.txtProxyUser) Me.Controls.Add(Me.txtUsername) + Me.Controls.Add(Me.txtProxyPort) + Me.Controls.Add(Me.txtProxyHost) Me.Controls.Add(Me.txtBaseUrl) Me.Controls.Add(Me.btnLogin) Me.Controls.Add(Me.Button1) @@ -275,4 +355,12 @@ Partial Class frmMain Friend WithEvents TabPage1 As TabPage Friend WithEvents btnLogin As Button Friend WithEvents ProgressBar1 As ProgressBar + Friend WithEvents txtProxyHost As TextBox + Friend WithEvents txtProxyUser As TextBox + Friend WithEvents txtProxyPass As TextBox + Friend WithEvents Label8 As Label + Friend WithEvents Label9 As Label + Friend WithEvents Label10 As Label + Friend WithEvents txtProxyPort As TextBox + Friend WithEvents Label11 As Label End Class diff --git a/GUIs.Test.GraphQLTest/frmMain.vb b/GUIs.Test.GraphQLTest/frmMain.vb index ea842647..717aebda 100644 --- a/GUIs.Test.GraphQLTest/frmMain.vb +++ b/GUIs.Test.GraphQLTest/frmMain.vb @@ -5,6 +5,7 @@ Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Config Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq +Imports System.Net Public Class frmMain Private _LogConfig As LogConfig @@ -58,6 +59,10 @@ Public Class frmMain txtCertFile.Text = _Config.Config.CertificateFile txtCertPass.Text = _Config.Config.CertificatePass txtConnectionString.Text = _Config.Config.ConnectionString + txtProxyHost.Text = _Config.Config.ProxyHost + txtProxyPort.Text = _Config.Config.ProxyPort + txtProxyUser.Text = _Config.Config.ProxyUsername + txtProxyPass.Text = _Config.Config.ProxyPassword ComboBox1.SelectedIndex = 0 @@ -70,6 +75,7 @@ Public Class frmMain Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click Try + _Interface = New GraphQLInterface(_LogConfig, txtBaseUrl.Text, txtUsername.Text, @@ -77,6 +83,22 @@ Public Class frmMain txtCertFile.Text, txtCertPass.Text) + If _Config.Config.HasProxySet() And _Config.Config.HasProxyCredentialsSet() Then + Dim oURI As New Uri($"http://{_Config.Config.ProxyHost}:{_Config.Config.ProxyPort}") + Dim oCredentials As New NetworkCredential(_Config.Config.ProxyUsername, _Config.Config.ProxyPassword) + Dim oProxy As New WebProxy() With { + .Address = oURI, + .UseDefaultCredentials = False, + .Credentials = oCredentials + } + _Interface.Proxy = oProxy + + _Logger.Debug("Using Proxy: {0}", oURI.ToString) + _Logger.Debug("Proxy Credentials: [{0}] [{1}]", _Config.Config.ProxyUsername, _Config.Config.ProxyPassword) + Else + _Logger.Debug("Proxy not set.") + End If + Dim oResponse = _Interface.Login _Interface.SaveCookies(oResponse.Cookies.Item(0)) @@ -137,14 +159,16 @@ Public Class frmMain If oSuccess Then _Logger.Debug("Record [{0}] inserted!", oItem.beschreibung) End If + + oCounter += 1 + ProgressBar1.Value = oCounter Next txtResults.Text &= "--------------------------------------------" & vbNewLine txtResults.Text &= $"--- Datapool: {oDatapool}" & vbNewLine txtResults.Text &= JsonConvert.SerializeObject(oObj, Formatting.Indented) & vbNewLine - oCounter += 1 - ProgressBar1.Value = oCounter + Application.DoEvents() Next Else MsgBox("Unknown query!", MsgBoxStyle.Exclamation, Text) @@ -158,19 +182,22 @@ Public Class frmMain Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Try - Dim oLogoutResponse = _Interface.Logout() - If oLogoutResponse.StatusCode = Net.HttpStatusCode.OK Then - _Logger.Info("Logout successful.") - End If - _Config.Config.ConnectionString = txtConnectionString.Text _Config.Config.BaseUrl = txtBaseUrl.Text _Config.Config.CertificateFile = txtCertFile.Text _Config.Config.CertificatePass = txtCertPass.Text _Config.Config.Email = txtUsername.Text _Config.Config.Password = txtPassword.Text + _Config.Config.ProxyHost = txtProxyHost.Text + _Config.Config.ProxyPassword = txtProxyPass.Text + _Config.Config.ProxyPort = txtProxyPort.Text + _Config.Config.ProxyUsername = txtProxyUser.Text + _Config.Save(ForceAll:=True) - _Config.Save() + Dim oLogoutResponse = _Interface.Logout() + If oLogoutResponse.StatusCode = Net.HttpStatusCode.OK Then + _Logger.Info("Logout successful.") + End If Catch ex As Exception _Logger.Error(ex) End Try diff --git a/Modules.Interfaces/GraphQLInterface.vb b/Modules.Interfaces/GraphQLInterface.vb index 3b1b7d6d..aab25113 100644 --- a/Modules.Interfaces/GraphQLInterface.vb +++ b/Modules.Interfaces/GraphQLInterface.vb @@ -13,9 +13,10 @@ Public Class GraphQLInterface Private _userPassword As String Private _certificate As X509Certificate Private _cookieJar As CookieContainer - Private _Encoding As New UTF8Encoding + Public Property Proxy As WebProxy + Public Sub New(LogConfig As LogConfig, BaseUrl As String, Email As String, Password As String, CertificateFile As String, CertificatePassword As String) Try _logConfig = LogConfig @@ -92,6 +93,9 @@ Public Class GraphQLInterface Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest Try + ServicePointManager.Expect100Continue = True + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12 + Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}") oRequest.Method = "POST" oRequest.ContentType = "application/json" @@ -99,6 +103,10 @@ Public Class GraphQLInterface oRequest.ClientCertificates.Add(_certificate) oRequest.CookieContainer = GetCookies() + If Proxy IsNot Nothing Then + oRequest.Proxy = Proxy + End If + Return oRequest Catch ex As Exception _logger.Error(ex)