Interfaces/GraphQL: Improve debugging

This commit is contained in:
Jonathan Jenne 2021-09-30 13:15:23 +02:00
parent 65447df0ca
commit d73e3e2f28
4 changed files with 57 additions and 21 deletions

View File

@ -251,6 +251,7 @@ Partial Class frmMain
Me.txtOperation.Name = "txtOperation" Me.txtOperation.Name = "txtOperation"
Me.txtOperation.Size = New System.Drawing.Size(458, 20) Me.txtOperation.Size = New System.Drawing.Size(458, 20)
Me.txtOperation.TabIndex = 1 Me.txtOperation.TabIndex = 1
Me.txtOperation.Text = "Auftraege"
' '
'btnLogin 'btnLogin
' '

View File

@ -153,7 +153,9 @@ Public Class frmMain
End Using End Using
End Using End Using
Dim oObj As JObject = JsonConvert.DeserializeObject(oResult) 'Dim oObj As JObject = JsonConvert.DeserializeObject(oResult)
Dim oObj As JObject = JObject.Parse(oResult)
Dim oData As SAPData = ConvertResponse(oResult) Dim oData As SAPData = ConvertResponse(oResult)
_Logger.Debug("Inserting [{0}] items for datapool [{1}]", oData.sapdaten.Count, oDatapool) _Logger.Debug("Inserting [{0}] items for datapool [{1}]", oData.sapdaten.Count, oDatapool)
@ -203,7 +205,13 @@ Public Class frmMain
End Using End Using
End Using End Using
Dim oObj As JObject = JsonConvert.DeserializeObject(oResult) Dim oPath = "data.auftraege.auftraege"
Dim oObj As JObject = JObject.Parse(oResult)
If _Interface.ReadJSONPathFragmented(oObj, oPath) = False Then
MsgBox($"JSONPath [{oPath}] was not successfully read", MsgBoxStyle.Critical, Text)
End If
'Dim oObj As JObject = JsonConvert.DeserializeObject(oResult)
Dim oIndentedJson As String = JsonConvert.SerializeObject(oObj, Formatting.Indented) Dim oIndentedJson As String = JsonConvert.SerializeObject(oObj, Formatting.Indented)
txtResult.Text = oIndentedJson txtResult.Text = oIndentedJson
@ -217,6 +225,7 @@ Public Class frmMain
MsgBox(ex.Message, MsgBoxStyle.Critical) MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try End Try
End Sub End Sub
Sub SaveConfig() Sub SaveConfig()
_Config.Config.ConnectionString = txtConnectionString.Text _Config.Config.ConnectionString = txtConnectionString.Text
_Config.Config.BaseUrl = txtBaseUrl.Text _Config.Config.BaseUrl = txtBaseUrl.Text

View File

@ -118,6 +118,30 @@ Public Class GraphQLInterface
End Try End Try
End Function End Function
Public Function ReadJSONPathFragmented(pObject As Linq.JObject, pJsonPath As String)
Dim oSplitPath As List(Of String) = pJsonPath.Split(".").ToList()
Dim oCurrentPath As String = String.Empty
For Each oPart In oSplitPath
If oCurrentPath = String.Empty Then
oCurrentPath = oPart
Else
oCurrentPath &= "." & oPart
End If
_logger.Debug("Selecting Path Fragment [{0}]", oCurrentPath)
Try
pObject.SelectToken(oCurrentPath, errorWhenNoMatch:=True)
Catch ex As Exception
_logger.Warn("Path Fragment [{0}] did not return a valid token", oCurrentPath)
Return False
End Try
Next
Return True
End Function
Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest
Try Try
Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}") Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}")

View File

@ -16,6 +16,8 @@ Public Class GraphQLJob
Inherits JobBase Inherits JobBase
Implements IJob(Of GraphQLArgs) Implements IJob(Of GraphQLArgs)
Private _GraphQL As GraphQLInterface = Nothing
Private Const PLACEHOLDER_STATIC = "STATIC:" Private Const PLACEHOLDER_STATIC = "STATIC:"
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer) Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer)
@ -27,18 +29,16 @@ Public Class GraphQLJob
Dim oConfigPath As String = Args.QueryConfigPath Dim oConfigPath As String = Args.QueryConfigPath
Dim oConfigManager As New ConfigManager(Of GraphQLConfig)(_LogConfig, oConfigPath) Dim oConfigManager As New ConfigManager(Of GraphQLConfig)(_LogConfig, oConfigPath)
Dim oInterface As GraphQLInterface
With oConfigManager.Config With oConfigManager.Config
oInterface = New GraphQLInterface(_LogConfig, .BaseUrl, .Email, .Password, .CertificateFingerprint) _GraphQL = New GraphQLInterface(_LogConfig, .BaseUrl, .Email, .Password, .CertificateFingerprint)
End With End With
' Login to get cookie ' Login to get cookie
_Logger.Debug("Logging in") _Logger.Debug("Logging in")
Dim oLoginResponse = oInterface.Login() Dim oLoginResponse = _GraphQL.Login()
' save cookie for future requests ' save cookie for future requests
oInterface.SaveCookies(oLoginResponse.Cookies.Item(0)) _GraphQL.SaveCookies(oLoginResponse.Cookies.Item(0))
_Logger.Debug("Loading Queries") _Logger.Debug("Loading Queries")
@ -85,7 +85,7 @@ Public Class GraphQLJob
_Logger.Info("Getting data..", oQuery.Name) _Logger.Info("Getting data..", oQuery.Name)
' get the data from GraphQL ' get the data from GraphQL
Dim oDataResponse = oInterface.GetData(oQuery.QueryString, oQuery.OperationName) Dim oDataResponse = _GraphQL.GetData(oQuery.QueryString, oQuery.OperationName)
Dim oResult As String Dim oResult As String
' write data to string ' write data to string
@ -144,7 +144,7 @@ Public Class GraphQLJob
' logout ' logout
_Logger.Debug("Logging out") _Logger.Debug("Logging out")
Dim oLogoutResponse = oInterface.Logout() Dim oLogoutResponse = _GraphQL.Logout()
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
Throw ex Throw ex
@ -153,24 +153,26 @@ Public Class GraphQLJob
Private Function HandleResponse(JsonString As String, QueryData As GraphQL.Query, DB As Database.MSSQLServer) As GraphQL.Query Private Function HandleResponse(JsonString As String, QueryData As GraphQL.Query, DB As Database.MSSQLServer) As GraphQL.Query
Dim oObj As JObject = JObject.Parse(JsonString) Dim oObj As JObject = JObject.Parse(JsonString)
Dim oResultList As JToken = oObj.SelectToken(QueryData.MappingBasePath) Dim oResultList As JToken
If _GraphQL.ReadJSONPathFragmented(oObj, QueryData.MappingBasePath) = False Then
_Logger.Warn("There is an error in the MappingBasePath [{1}] configuration of query [{0}]", QueryData.Name, QueryData.MappingBasePath)
End If
Try
oResultList = oObj.SelectToken(QueryData.MappingBasePath, errorWhenNoMatch:=True)
Catch ex As Exception
_Logger.Warn("HandleResponse: Could not find BasePath: [{0}] for query [{1}]", QueryData.MappingBasePath, QueryData.Name)
_Logger.Error(ex)
Return Nothing
End Try
If oResultList Is Nothing Then If oResultList Is Nothing Then
_Logger.Warn("HandleResponse: Could not find BasePath: [{0}] for query [{1}]", QueryData.MappingBasePath, QueryData.Name) _Logger.Warn("HandleResponse: Could not find BasePath: [{0}] for query [{1}]", QueryData.MappingBasePath, QueryData.Name)
Return Nothing Return Nothing
End If End If
_Logger.Info("Processing Queue [{0}] with [{1}] Items", QueryData.Name, oResultList.Count) _Logger.Info("HandleResponse: Processing Queue [{0}] with [{1}] Items", QueryData.Name, oResultList.Count)
'If QueryData.ClearBeforeFill Then
' _Logger.Info("Clearing Table {0} before insert", QueryData.DestinationTable)
' _Logger.Info("Clear Command: [{0}]", QueryData.ClearCommand)
' Try
' DB.ExecuteNonQuery(QueryData.ClearCommand)
' Catch ex As Exception
' _Logger.Error(ex)
' End Try
'End If
For Each oResultItem As JToken In oResultList For Each oResultItem As JToken In oResultList
Try Try