GraphQLTest: improve logging

This commit is contained in:
Jonathan Jenne 2024-01-22 10:28:43 +01:00
parent 3e49d66e92
commit 35f675e21a
5 changed files with 105 additions and 25 deletions

View File

@ -1,40 +1,44 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<configSections> <configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="GUIs.Test.GraphQLTest.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/> <section name="GUIs.Test.GraphQLTest.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup> </sectionGroup>
</configSections> </configSections>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup> </startup>
<userSettings> <userSettings>
<GUIs.Test.GraphQLTest.My.MySettings> <GUIs.Test.GraphQLTest.My.MySettings>
<setting name="ConnectionString" serializeAs="String"> <setting name="ConnectionString" serializeAs="String">
<value/> <value />
</setting> </setting>
<setting name="CertificateFile" serializeAs="String"> <setting name="CertificateFile" serializeAs="String">
<value/> <value />
</setting> </setting>
<setting name="CertificatePass" serializeAs="String"> <setting name="CertificatePass" serializeAs="String">
<value/> <value />
</setting> </setting>
<setting name="Email" serializeAs="String"> <setting name="Email" serializeAs="String">
<value/> <value />
</setting> </setting>
<setting name="Password" serializeAs="String"> <setting name="Password" serializeAs="String">
<value/> <value />
</setting> </setting>
<setting name="BaseUrl" serializeAs="String"> <setting name="BaseUrl" serializeAs="String">
<value/> <value />
</setting> </setting>
</GUIs.Test.GraphQLTest.My.MySettings> </GUIs.Test.GraphQLTest.My.MySettings>
</userSettings> </userSettings>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral"/> <assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="7.5.0.0"/> <bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="7.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>

View File

@ -48,6 +48,12 @@
<OptionInfer>On</OptionInfer> <OptionInfer>On</OptionInfer>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="DevExpress.Data.Desktop.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.Printing.v21.2.Core, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.Sparkline.v21.2.Core, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.Utils.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.XtraEditors.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DigitalData.Modules.Config, Version=1.1.4.1, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="DigitalData.Modules.Config, Version=1.1.4.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDModules\Config\bin\Debug\DigitalData.Modules.Config.dll</HintPath> <HintPath>..\..\DDModules\Config\bin\Debug\DigitalData.Modules.Config.dll</HintPath>
@ -68,15 +74,17 @@
<HintPath>..\..\DDModules\Patterns\bin\Debug\DigitalData.Modules.Patterns.dll</HintPath> <HintPath>..\..\DDModules\Patterns\bin\Debug\DigitalData.Modules.Patterns.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.0\lib\net45\NLog.dll</HintPath> <HintPath>..\packages\NLog.5.0.5\lib\net46\NLog.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Deployment" /> <Reference Include="System.Deployment" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" /> <Reference Include="System.IO.Compression" />

View File

@ -40,6 +40,8 @@ Partial Class frmMain
Me.cmbQuery = New System.Windows.Forms.ComboBox() Me.cmbQuery = New System.Windows.Forms.ComboBox()
Me.Label7 = New System.Windows.Forms.Label() Me.Label7 = New System.Windows.Forms.Label()
Me.TabControl1 = New System.Windows.Forms.TabControl() Me.TabControl1 = New System.Windows.Forms.TabControl()
Me.pageLog = New System.Windows.Forms.TabPage()
Me.lbLog = New DevExpress.XtraEditors.ListBoxControl()
Me.pageRaw = New System.Windows.Forms.TabPage() Me.pageRaw = New System.Windows.Forms.TabPage()
Me.pageQuery = New System.Windows.Forms.TabPage() Me.pageQuery = New System.Windows.Forms.TabPage()
Me.txtQuery = New System.Windows.Forms.TextBox() Me.txtQuery = New System.Windows.Forms.TextBox()
@ -57,12 +59,15 @@ Partial Class frmMain
Me.txtCertFingerprint = New System.Windows.Forms.TextBox() Me.txtCertFingerprint = New System.Windows.Forms.TextBox()
Me.Label12 = New System.Windows.Forms.Label() Me.Label12 = New System.Windows.Forms.Label()
Me.TabControl1.SuspendLayout() Me.TabControl1.SuspendLayout()
Me.pageLog.SuspendLayout()
CType(Me.lbLog, System.ComponentModel.ISupportInitialize).BeginInit()
Me.pageRaw.SuspendLayout() Me.pageRaw.SuspendLayout()
Me.pageQuery.SuspendLayout() Me.pageQuery.SuspendLayout()
Me.SuspendLayout() Me.SuspendLayout()
' '
'Button1 'Button1
' '
Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Button1.Location = New System.Drawing.Point(826, 386) Me.Button1.Location = New System.Drawing.Point(826, 386)
Me.Button1.Name = "Button1" Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 31) Me.Button1.Size = New System.Drawing.Size(96, 31)
@ -203,6 +208,10 @@ Partial Class frmMain
' '
'TabControl1 'TabControl1
' '
Me.TabControl1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TabControl1.Controls.Add(Me.pageLog)
Me.TabControl1.Controls.Add(Me.pageRaw) Me.TabControl1.Controls.Add(Me.pageRaw)
Me.TabControl1.Controls.Add(Me.pageQuery) Me.TabControl1.Controls.Add(Me.pageQuery)
Me.TabControl1.Location = New System.Drawing.Point(450, 6) Me.TabControl1.Location = New System.Drawing.Point(450, 6)
@ -211,6 +220,25 @@ Partial Class frmMain
Me.TabControl1.Size = New System.Drawing.Size(472, 374) Me.TabControl1.Size = New System.Drawing.Size(472, 374)
Me.TabControl1.TabIndex = 5 Me.TabControl1.TabIndex = 5
' '
'pageLog
'
Me.pageLog.Controls.Add(Me.lbLog)
Me.pageLog.Location = New System.Drawing.Point(4, 22)
Me.pageLog.Name = "pageLog"
Me.pageLog.Padding = New System.Windows.Forms.Padding(3)
Me.pageLog.Size = New System.Drawing.Size(464, 348)
Me.pageLog.TabIndex = 2
Me.pageLog.Text = "Log"
Me.pageLog.UseVisualStyleBackColor = True
'
'lbLog
'
Me.lbLog.Dock = System.Windows.Forms.DockStyle.Fill
Me.lbLog.Location = New System.Drawing.Point(3, 3)
Me.lbLog.Name = "lbLog"
Me.lbLog.Size = New System.Drawing.Size(458, 342)
Me.lbLog.TabIndex = 0
'
'pageRaw 'pageRaw
' '
Me.pageRaw.Controls.Add(Me.txtResult) Me.pageRaw.Controls.Add(Me.txtResult)
@ -255,6 +283,7 @@ Partial Class frmMain
' '
'btnLogin 'btnLogin
' '
Me.btnLogin.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.btnLogin.Location = New System.Drawing.Point(724, 386) Me.btnLogin.Location = New System.Drawing.Point(724, 386)
Me.btnLogin.Name = "btnLogin" Me.btnLogin.Name = "btnLogin"
Me.btnLogin.Size = New System.Drawing.Size(96, 31) Me.btnLogin.Size = New System.Drawing.Size(96, 31)
@ -264,7 +293,9 @@ Partial Class frmMain
' '
'ProgressBar1 'ProgressBar1
' '
Me.ProgressBar1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.ProgressBar1.Location = New System.Drawing.Point(12, 394) Me.ProgressBar1.Location = New System.Drawing.Point(12, 394)
Me.ProgressBar1.MinimumSize = New System.Drawing.Size(432, 23)
Me.ProgressBar1.Name = "ProgressBar1" Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.Size = New System.Drawing.Size(432, 23) Me.ProgressBar1.Size = New System.Drawing.Size(432, 23)
Me.ProgressBar1.TabIndex = 6 Me.ProgressBar1.TabIndex = 6
@ -386,6 +417,8 @@ Partial Class frmMain
Me.Name = "frmMain" Me.Name = "frmMain"
Me.Text = "GraphQL Interface" Me.Text = "GraphQL Interface"
Me.TabControl1.ResumeLayout(False) Me.TabControl1.ResumeLayout(False)
Me.pageLog.ResumeLayout(False)
CType(Me.lbLog, System.ComponentModel.ISupportInitialize).EndInit()
Me.pageRaw.ResumeLayout(False) Me.pageRaw.ResumeLayout(False)
Me.pageRaw.PerformLayout() Me.pageRaw.PerformLayout()
Me.pageQuery.ResumeLayout(False) Me.pageQuery.ResumeLayout(False)
@ -428,4 +461,6 @@ Partial Class frmMain
Friend WithEvents txtOperation As TextBox Friend WithEvents txtOperation As TextBox
Friend WithEvents txtCertFingerprint As TextBox Friend WithEvents txtCertFingerprint As TextBox
Friend WithEvents Label12 As Label Friend WithEvents Label12 As Label
Friend WithEvents pageLog As TabPage
Friend WithEvents lbLog As DevExpress.XtraEditors.ListBoxControl
End Class End Class

View File

@ -9,9 +9,9 @@ Imports System.Net
Imports System.Text.RegularExpressions Imports System.Text.RegularExpressions
Public Class frmMain Public Class frmMain
Private WithEvents _Interface As GraphQLInterface
Private _LogConfig As LogConfig Private _LogConfig As LogConfig
Private _Logger As Logger Private _Logger As Logger
Private _Interface As GraphQLInterface
Private _MSSQL As MSSQLServer Private _MSSQL As MSSQLServer
Private _Config As ConfigManager(Of Config) Private _Config As ConfigManager(Of Config)
Private _Datapools As New List(Of String) From { Private _Datapools As New List(Of String) From {
@ -73,21 +73,36 @@ Public Class frmMain
cmbQuery.SelectedIndex = oIndex cmbQuery.SelectedIndex = oIndex
_MSSQL = New MSSQLServer(_LogConfig, _Config.Config.ConnectionString) _MSSQL = New MSSQLServer(_LogConfig, _Config.Config.ConnectionString)
LogInfo("Initialization finished")
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) LogError(ex)
MsgBox(ex.Message, MsgBoxStyle.Critical, Text) MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
End Try End Try
End Sub End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Try Try
SaveConfig() SaveConfig()
lbLog.Items.Clear()
LogInfo("START OF REQUEST")
LogInfo("Looking up certificate by fingerprint..")
_Interface = New GraphQLInterface(_LogConfig, _Interface = New GraphQLInterface(_LogConfig,
txtBaseUrl.Text, txtBaseUrl.Text,
txtUsername.Text, txtUsername.Text,
txtPassword.Text, txtPassword.Text,
txtCertFingerprint.Text) txtCertFingerprint.Text)
LogInfo("Certificate Subject: [{0}]", _Interface.Certificate.Subject)
LogInfo("Certificate Issuer: [{0}]", _Interface.Certificate.Issuer)
LogInfo("Certificate Fingerprint: [{0}]", _Interface.Certificate.Thumbprint)
If _Config.Config.HasProxySet() And _Config.Config.HasProxyCredentialsSet() Then If _Config.Config.HasProxySet() And _Config.Config.HasProxyCredentialsSet() Then
Dim oURI As New Uri($"http://{_Config.Config.ProxyHost}:{_Config.Config.ProxyPort}") Dim oURI As New Uri($"http://{_Config.Config.ProxyHost}:{_Config.Config.ProxyPort}")
Dim oCredentials As New NetworkCredential(_Config.Config.ProxyUsername, _Config.Config.ProxyPassword) Dim oCredentials As New NetworkCredential(_Config.Config.ProxyUsername, _Config.Config.ProxyPassword)
@ -108,18 +123,21 @@ Public Class frmMain
_Logger.Debug("Proxy not set.") _Logger.Debug("Proxy not set.")
End If End If
LogInfo("Starting login..")
Dim oResponse = _Interface.Login Dim oResponse = _Interface.Login
_Interface.SaveCookies(oResponse.Cookies.Item(0)) _Interface.SaveCookies(oResponse.Cookies.Item(0))
If oResponse.StatusCode = Net.HttpStatusCode.OK Then If oResponse.StatusCode = Net.HttpStatusCode.OK Then
MsgBox("Login Successful!", MsgBoxStyle.Information, Text) LogInfo("Login Successful!")
Else Else
MsgBox("Login failed! Check Certificate and User Credentials!", MsgBoxStyle.Critical, Text) LogInfo("Login failed! Check Certificate and User Credentials!")
End If End If
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) LogError(ex)
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
End Try End Try
LogInfo("END OF REQUEST")
End Sub End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
@ -246,8 +264,8 @@ Public Class frmMain
Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try Try
SaveConfig() SaveConfig()
Dim oLogoutResponse = _Interface.Logout() Dim oLogoutResponse = _Interface?.Logout()
If oLogoutResponse.StatusCode = Net.HttpStatusCode.OK Then If oLogoutResponse?.StatusCode = Net.HttpStatusCode.OK Then
_Logger.Info("Logout successful.") _Logger.Info("Logout successful.")
End If End If
Catch ex As Exception Catch ex As Exception
@ -267,4 +285,19 @@ Public Class frmMain
_Config.Config.CurrentQuery = cmbQuery.Text _Config.Config.CurrentQuery = cmbQuery.Text
_Config.Save() _Config.Save()
End Sub End Sub
Private Sub LogInfo(pMessage As String, ParamArray pParams As String())
Dim oMessage = String.Format(pMessage, pParams)
lbLog.Items.Add(oMessage)
_Logger.Info(oMessage)
End Sub
Private Sub LogError(pException As Exception)
lbLog.Items.Add(pException.Message)
_Logger.Error(pException)
End Sub
Private Sub _Interface_LogRequested(sender As Object, e As String) Handles _Interface.LogRequested
LogInfo(e)
End Sub
End Class End Class

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" /> <package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="NLog" version="4.7.0" targetFramework="net461" /> <package id="NLog" version="5.0.5" targetFramework="net48" />
</packages> </packages>