GUIs.Test: Rewrite graphql test tool, add BulkInsert form
This commit is contained in:
2
GUIs.Test.GraphQLTest/frmMain.Designer.vb
generated
2
GUIs.Test.GraphQLTest/frmMain.Designer.vb
generated
@@ -191,7 +191,7 @@ Partial Class frmMain
|
||||
'cmbQuery
|
||||
'
|
||||
Me.cmbQuery.FormattingEnabled = True
|
||||
Me.cmbQuery.Items.AddRange(New Object() {"SAPDaten", "Custom"})
|
||||
Me.cmbQuery.Items.AddRange(New Object() {"SAPDaten", "SAPAufträge", "Custom"})
|
||||
Me.cmbQuery.Location = New System.Drawing.Point(106, 352)
|
||||
Me.cmbQuery.Name = "cmbQuery"
|
||||
Me.cmbQuery.Size = New System.Drawing.Size(338, 21)
|
||||
|
||||
@@ -31,6 +31,18 @@ Public Class frmMain
|
||||
Public gueltig_bis As String
|
||||
End Class
|
||||
|
||||
Public Class AuftragData
|
||||
Public auftraege As List(Of AuftragDataItem)
|
||||
End Class
|
||||
|
||||
Public Class AuftragDataItem
|
||||
Public auftragsnr As String
|
||||
Public kdnr As String
|
||||
Public mdnr As String
|
||||
Public name As String
|
||||
Public objektnummer As String
|
||||
End Class
|
||||
|
||||
Const GRAPHQL_QUERY_SAP_DATA = "
|
||||
query SAPDaten {
|
||||
sapdaten(datenpool: __DATA_POOL__) {
|
||||
@@ -44,6 +56,21 @@ Public Class frmMain
|
||||
}
|
||||
"
|
||||
|
||||
Const GRAPHQL_QUERY_SAP_AUFTRAEGE = "
|
||||
query Auftraege{
|
||||
auftraege(offset: 0, limit: 0){
|
||||
auftraege {
|
||||
auftragsnr
|
||||
kdnr
|
||||
mdnr
|
||||
name
|
||||
kontaktName
|
||||
kontaktMail
|
||||
}
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Try
|
||||
Dim oStartupPath As String = AppDomain.CurrentDomain.BaseDirectory
|
||||
@@ -153,6 +180,62 @@ Public Class frmMain
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
If cmbQuery.Text = "SAPAufträge" Then
|
||||
_MSSQL.ExecuteNonQuery("DELETE FROM TBCUST_SYNC_API_AUFTRAEGE")
|
||||
|
||||
txtResult.Text = String.Empty
|
||||
|
||||
Dim oTotalTotal As Integer = 0
|
||||
|
||||
|
||||
Dim oQuery As String = GRAPHQL_QUERY_SAP_AUFTRAEGE.Trim
|
||||
Dim oDataResponse = _Interface.GetData(oQuery, "Auftraege")
|
||||
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 oObj As JObject = JObject.Parse(oResult)
|
||||
|
||||
Dim oData As AuftragData = ConvertAuftraegeResponse(oResult)
|
||||
|
||||
Dim oCounter As Integer = 0
|
||||
Dim oTotal As Integer = oData.auftraege.Count
|
||||
ProgressBar1.Maximum = oTotal
|
||||
ProgressBar1.Value = oCounter
|
||||
|
||||
'For Each oItem As AuftragDataItem In oData.auftraege
|
||||
' Dim oBeschreibung = Regex.Replace(oItem.name, "'", "''", RegexOptions.IgnoreCase)
|
||||
|
||||
' Dim oSQL = $"INSERT INTO TBCUST_SYNC_API_AUFTRAEGE (AUFTRAGSNR, KDNR, MDNR, NAME) VALUES ('{oItem.auftragsnr}', '{oItem.kdnr}', '{oItem.mdnr}', '{oItem.name}')"
|
||||
' Dim oSuccess = _MSSQL.ExecuteNonQuery(oSQL)
|
||||
|
||||
' If oSuccess Then
|
||||
' _Logger.Debug("Record [{0}] inserted!", oItem.name)
|
||||
' End If
|
||||
|
||||
' oCounter += 1
|
||||
' ProgressBar1.Value = oCounter
|
||||
'Next
|
||||
|
||||
Dim oQueryResult = JsonConvert.SerializeObject(oObj, Formatting.None)
|
||||
|
||||
txtResult.Text &= "--------------------------------------------" & vbNewLine
|
||||
txtResult.Text &= oQueryResult & vbNewLine
|
||||
|
||||
Application.DoEvents()
|
||||
File.WriteAllText("E:\graphql.txt", oQueryResult)
|
||||
|
||||
oTotalTotal += oTotal
|
||||
|
||||
|
||||
MsgBox($"Query finished! Lines inserted: [{oTotalTotal}]", MsgBoxStyle.Information, Text)
|
||||
End If
|
||||
|
||||
If cmbQuery.Text = "SAPDaten" Then
|
||||
_MSSQL.ExecuteNonQuery("DELETE FROM TBCUST_SYNC_API_SAPDATEN")
|
||||
|
||||
@@ -174,7 +257,7 @@ Public Class frmMain
|
||||
'Dim oObj As JObject = JsonConvert.DeserializeObject(oResult)
|
||||
Dim oObj As JObject = JObject.Parse(oResult)
|
||||
|
||||
Dim oData As SAPData = ConvertResponse(oResult)
|
||||
Dim oData As SAPData = ConvertSAPDatenResponse(oResult)
|
||||
|
||||
_Logger.Debug("Inserting [{0}] items for datapool [{1}]", oData.sapdaten.Count, oDatapool)
|
||||
|
||||
@@ -207,12 +290,15 @@ Public Class frmMain
|
||||
Next
|
||||
|
||||
MsgBox($"Query finished! Lines inserted: [{oTotalTotal}]", MsgBoxStyle.Information, Text)
|
||||
ElseIf cmbQuery.Text = "Custom" Then
|
||||
End If
|
||||
|
||||
If cmbQuery.Text = "Custom" Then
|
||||
If txtOperation.Text = String.Empty Then
|
||||
MsgBox("Please select an operation!", MsgBoxStyle.Exclamation, Text)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
|
||||
Dim oDataResponse = _Interface.GetData(txtQuery.Text, txtOperation.Text)
|
||||
|
||||
Dim oResult As String
|
||||
@@ -223,7 +309,7 @@ Public Class frmMain
|
||||
End Using
|
||||
End Using
|
||||
|
||||
Dim oPath = "data.auftraege.auftraege"
|
||||
Dim oPath = "data"
|
||||
Dim oObj As JObject = JObject.Parse(oResult)
|
||||
If _Interface.ReadJSONPathFragmented(oObj, oPath) = False Then
|
||||
MsgBox($"JSONPath [{oPath}] was not successfully read", MsgBoxStyle.Critical, Text)
|
||||
@@ -234,10 +320,8 @@ Public Class frmMain
|
||||
txtResult.Text = oIndentedJson
|
||||
|
||||
TabControl1.SelectedTab = pageRaw
|
||||
Else
|
||||
MsgBox("Unknown query!", MsgBoxStyle.Exclamation, Text)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical)
|
||||
@@ -273,7 +357,7 @@ Public Class frmMain
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Function ConvertResponse(JsonString As String) As SAPData
|
||||
Public Function ConvertSAPDatenResponse(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)
|
||||
@@ -281,6 +365,14 @@ Public Class frmMain
|
||||
Return oSAPData
|
||||
End Function
|
||||
|
||||
Public Function ConvertAuftraegeResponse(JsonString As String) As AuftragData
|
||||
Dim oObj As JObject = JObject.Parse(JsonString)("data")("auftraege")
|
||||
Dim oString As String = JsonConvert.SerializeObject(oObj, Formatting.None)
|
||||
Dim oAuftragData As AuftragData = JsonConvert.DeserializeObject(Of AuftragData)(oString)
|
||||
|
||||
Return oAuftragData
|
||||
End Function
|
||||
|
||||
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbQuery.SelectedIndexChanged
|
||||
_Config.Config.CurrentQuery = cmbQuery.Text
|
||||
_Config.Save()
|
||||
|
||||
Reference in New Issue
Block a user