GraphQLTest: Add Proxy config

This commit is contained in:
Jonathan Jenne
2020-05-05 13:21:35 +02:00
parent 729b4d8195
commit 6e577627d3
4 changed files with 154 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Config
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Net
Public Class frmMain
Private _LogConfig As LogConfig
@@ -58,6 +59,10 @@ Public Class frmMain
txtCertFile.Text = _Config.Config.CertificateFile
txtCertPass.Text = _Config.Config.CertificatePass
txtConnectionString.Text = _Config.Config.ConnectionString
txtProxyHost.Text = _Config.Config.ProxyHost
txtProxyPort.Text = _Config.Config.ProxyPort
txtProxyUser.Text = _Config.Config.ProxyUsername
txtProxyPass.Text = _Config.Config.ProxyPassword
ComboBox1.SelectedIndex = 0
@@ -70,6 +75,7 @@ Public Class frmMain
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Try
_Interface = New GraphQLInterface(_LogConfig,
txtBaseUrl.Text,
txtUsername.Text,
@@ -77,6 +83,22 @@ Public Class frmMain
txtCertFile.Text,
txtCertPass.Text)
If _Config.Config.HasProxySet() And _Config.Config.HasProxyCredentialsSet() Then
Dim oURI As New Uri($"http://{_Config.Config.ProxyHost}:{_Config.Config.ProxyPort}")
Dim oCredentials As New NetworkCredential(_Config.Config.ProxyUsername, _Config.Config.ProxyPassword)
Dim oProxy As New WebProxy() With {
.Address = oURI,
.UseDefaultCredentials = False,
.Credentials = oCredentials
}
_Interface.Proxy = oProxy
_Logger.Debug("Using Proxy: {0}", oURI.ToString)
_Logger.Debug("Proxy Credentials: [{0}] [{1}]", _Config.Config.ProxyUsername, _Config.Config.ProxyPassword)
Else
_Logger.Debug("Proxy not set.")
End If
Dim oResponse = _Interface.Login
_Interface.SaveCookies(oResponse.Cookies.Item(0))
@@ -137,14 +159,16 @@ Public Class frmMain
If oSuccess Then
_Logger.Debug("Record [{0}] inserted!", oItem.beschreibung)
End If
oCounter += 1
ProgressBar1.Value = oCounter
Next
txtResults.Text &= "--------------------------------------------" & vbNewLine
txtResults.Text &= $"--- Datapool: {oDatapool}" & vbNewLine
txtResults.Text &= JsonConvert.SerializeObject(oObj, Formatting.Indented) & vbNewLine
oCounter += 1
ProgressBar1.Value = oCounter
Application.DoEvents()
Next
Else
MsgBox("Unknown query!", MsgBoxStyle.Exclamation, Text)
@@ -158,19 +182,22 @@ Public Class frmMain
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.Config.ProxyHost = txtProxyHost.Text
_Config.Config.ProxyPassword = txtProxyPass.Text
_Config.Config.ProxyPort = txtProxyPort.Text
_Config.Config.ProxyUsername = txtProxyUser.Text
_Config.Save(ForceAll:=True)
_Config.Save()
Dim oLogoutResponse = _Interface.Logout()
If oLogoutResponse.StatusCode = Net.HttpStatusCode.OK Then
_Logger.Info("Logout successful.")
End If
Catch ex As Exception
_Logger.Error(ex)
End Try