GraphQLTest: Prepare for test
This commit is contained in:
186
GUIs.Test.GraphQLTest/frmMain.vb
Normal file
186
GUIs.Test.GraphQLTest/frmMain.vb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user