GUIs.Test: Rewrite graphql test tool, add BulkInsert form

This commit is contained in:
Jonathan Jenne 2024-01-23 13:50:04 +01:00
parent e4ce86dd3c
commit 6573ab3e7c
8 changed files with 429 additions and 9 deletions

View File

@ -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)

View File

@ -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()

View File

@ -86,6 +86,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDModules\Interfaces\bin\Debug\DigitalData.Modules.Interfaces.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Jobs, Version=2.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDModules\Jobs\bin\Debug\DigitalData.Modules.Jobs.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Logging">
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
</Reference>
@ -163,6 +167,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationEvents.vb" />
<Compile Include="frmBulkInsert.Designer.vb">
<DependentUpon>frmBulkInsert.vb</DependentUpon>
</Compile>
<Compile Include="frmBulkInsert.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmChecksum.Designer.vb">
<DependentUpon>frmChecksum.vb</DependentUpon>
</Compile>
@ -266,6 +276,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="frmBulkInsert.resx">
<DependentUpon>frmBulkInsert.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmChecksum.resx">
<DependentUpon>frmChecksum.vb</DependentUpon>
</EmbeddedResource>

View File

@ -0,0 +1,97 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmBulkInsert
Inherits System.Windows.Forms.Form
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Wird vom Windows Form-Designer benötigt.
Private components As System.ComponentModel.IContainer
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.txtQueryId = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.txtQueryFile = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(22, 155)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'txtQueryId
'
Me.txtQueryId.Location = New System.Drawing.Point(22, 40)
Me.txtQueryId.Name = "txtQueryId"
Me.txtQueryId.Size = New System.Drawing.Size(276, 20)
Me.txtQueryId.TabIndex = 1
Me.txtQueryId.Text = "16"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(19, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(47, 13)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Query Id"
'
'txtQueryFile
'
Me.txtQueryFile.Location = New System.Drawing.Point(22, 96)
Me.txtQueryFile.Name = "txtQueryFile"
Me.txtQueryFile.Size = New System.Drawing.Size(276, 20)
Me.txtQueryFile.TabIndex = 3
Me.txtQueryFile.Text = "E:\graphql.txt"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(19, 73)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(54, 13)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Query File"
'
'frmBulkInsert
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.txtQueryFile)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtQueryId)
Me.Controls.Add(Me.Button1)
Me.Name = "frmBulkInsert"
Me.Text = "frmBulkInsert"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Button1 As Button
Friend WithEvents txtQueryId As TextBox
Friend WithEvents Label1 As Label
Friend WithEvents txtQueryFile As TextBox
Friend WithEvents Label2 As Label
End Class

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,81 @@
Imports System.Data.SqlClient
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules.Jobs
Imports DigitalData.Modules.Logging
Public Class frmBulkInsert
Private LogConfig As LogConfig
Private Logger As Logger
Private Database As MSSQLServer
Private Writer As GraphQLWriter
Private Model As GraphQLModel
Private Const TABLE_NAME = "TBTEST_BULKINSERT"
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
LogConfig = pLogConfig
Logger = LogConfig.GetLogger()
Database = pDatabase
Writer = New GraphQLWriter(LogConfig, Database)
Model = New GraphQLModel(LogConfig, Database)
End Sub
Private Sub frmBulkInsert_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oSW As New Stopwatch()
oSW.Start()
Dim oQueryId As Integer = Integer.Parse(txtQueryId.Text)
Dim oJsonString = IO.File.ReadAllText(txtQueryFile.Text)
Dim oQueries = Model.GetQueryList()
Dim oQuery = oQueries.Where(Function(q) q.Id = oQueryId).FirstOrDefault()
Writer.WriteNewQueryData(oJsonString, oQuery, "Test GraphQL")
oSW.Stop()
MsgBox("Time: " & oSW.ElapsedMilliseconds / 1000 & "s")
End Sub
Private Function BulkInsert()
Dim oSQL As String = "SELECT AUFTRAGSNR, name, MDNR, KDNR FROM TBCUST_SYNC_API_AUFTRAEGE"
Dim oTable = Database.GetDatatable(oSQL)
Dim oSw As New Stopwatch()
oSw.Start()
Using oConnection = Database.GetConnection()
Using oBulkCopy = New SqlBulkCopy(oConnection)
oBulkCopy.DestinationTableName = "TBCUST_SYNC_API_AUFTRAEGE_COPY"
oBulkCopy.ColumnMappings.Add(New SqlBulkCopyColumnMapping("AUFTRAGSNR", "AUFTRAGSNR"))
oBulkCopy.ColumnMappings.Add(New SqlBulkCopyColumnMapping("name", "name"))
oBulkCopy.ColumnMappings.Add(New SqlBulkCopyColumnMapping("MDNR", "MDNR"))
oBulkCopy.ColumnMappings.Add(New SqlBulkCopyColumnMapping("KDNR", "KDNR"))
Try
oBulkCopy.WriteToServer(oTable)
Catch ex As Exception
Logger.Error(ex)
End Try
End Using
End Using
End Function
End Class

View File

@ -33,6 +33,7 @@ Partial Class frmStart
Me.Button9 = New System.Windows.Forms.Button()
Me.Button10 = New System.Windows.Forms.Button()
Me.btnObjectProperties = New System.Windows.Forms.Button()
Me.Button11 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
@ -134,6 +135,15 @@ Partial Class frmStart
Me.btnObjectProperties.Text = "Object Properties"
Me.btnObjectProperties.UseVisualStyleBackColor = True
'
'Button11
'
Me.Button11.Location = New System.Drawing.Point(254, 326)
Me.Button11.Name = "Button11"
Me.Button11.Size = New System.Drawing.Size(236, 60)
Me.Button11.TabIndex = 2
Me.Button11.Text = "Bulk Insert"
Me.Button11.UseVisualStyleBackColor = True
'
'frmStart
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
@ -142,6 +152,7 @@ Partial Class frmStart
Me.Controls.Add(Me.Button10)
Me.Controls.Add(Me.Button9)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button11)
Me.Controls.Add(Me.btnObjectProperties)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
@ -167,4 +178,5 @@ Partial Class frmStart
Friend WithEvents Button9 As Button
Friend WithEvents Button10 As Button
Friend WithEvents btnObjectProperties As Button
Friend WithEvents Button11 As Button
End Class

View File

@ -12,7 +12,7 @@ Public Class frmStart
.ProductName = "TestGUI",
.CompanyName = "Digital Data"
})
Database = New MSSQLServer(LogConfig, "Data Source=SDD-VMP04-SQL17\DD_DEVELOP01;Initial Catalog=DD_ECM;Persist Security Info=True;User ID=sa;Password=dd")
Database = New MSSQLServer(LogConfig, "Data Source=SDD-VMP04-SQL17\WISAG;Initial Catalog=DD_ECM;Persist Security Info=True;User ID=sa;Password=dd")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
@ -65,4 +65,9 @@ Public Class frmStart
Dim oForm As New frmObjectProperties(LogConfig, Database)
oForm.ShowDialog()
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
Dim oForm As New frmBulkInsert(LogConfig, Database)
oForm.ShowDialog()
End Sub
End Class