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,4 +5,17 @@
Public Property Email As String = "foo.bar@wisag.de" Public Property Email As String = "foo.bar@wisag.de"
Public Property Password As String = "Password" Public Property Password As String = "Password"
Public Property BaseUrl As String = "https://data.api.wisag.de:8443" Public Property BaseUrl As String = "https://data.api.wisag.de:8443"
Public Property ProxyHost As String = ""
Public Property ProxyPort As Integer = 0
Public Property ProxyUsername As String = ""
Public Property ProxyPassword As String = ""
Public Function HasProxySet() As Boolean
Return ProxyHost <> "" And ProxyPort > 0
End Function
Public Function HasProxyCredentialsSet() As Boolean
Return ProxyUsername <> "" And ProxyPassword <> ""
End Function
End Class End Class

View File

@ -42,13 +42,21 @@ Partial Class frmMain
Me.TabPage1 = New System.Windows.Forms.TabPage() Me.TabPage1 = New System.Windows.Forms.TabPage()
Me.btnLogin = New System.Windows.Forms.Button() Me.btnLogin = New System.Windows.Forms.Button()
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar() Me.ProgressBar1 = New System.Windows.Forms.ProgressBar()
Me.txtProxyHost = New System.Windows.Forms.TextBox()
Me.txtProxyUser = New System.Windows.Forms.TextBox()
Me.txtProxyPass = New System.Windows.Forms.TextBox()
Me.Label8 = New System.Windows.Forms.Label()
Me.Label9 = New System.Windows.Forms.Label()
Me.Label10 = New System.Windows.Forms.Label()
Me.txtProxyPort = New System.Windows.Forms.TextBox()
Me.Label11 = New System.Windows.Forms.Label()
Me.TabControl1.SuspendLayout() Me.TabControl1.SuspendLayout()
Me.TabPage1.SuspendLayout() Me.TabPage1.SuspendLayout()
Me.SuspendLayout() Me.SuspendLayout()
' '
'Button1 'Button1
' '
Me.Button1.Location = New System.Drawing.Point(826, 300) 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)
Me.Button1.TabIndex = 0 Me.Button1.TabIndex = 0
@ -148,7 +156,7 @@ Partial Class frmMain
Me.txtResults.Multiline = True Me.txtResults.Multiline = True
Me.txtResults.Name = "txtResults" Me.txtResults.Name = "txtResults"
Me.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical Me.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtResults.Size = New System.Drawing.Size(458, 260) Me.txtResults.Size = New System.Drawing.Size(458, 342)
Me.txtResults.TabIndex = 3 Me.txtResults.TabIndex = 3
' '
'txtConnectionString 'txtConnectionString
@ -172,7 +180,7 @@ Partial Class frmMain
' '
Me.ComboBox1.FormattingEnabled = True Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Items.AddRange(New Object() {"SAPDaten"}) Me.ComboBox1.Items.AddRange(New Object() {"SAPDaten"})
Me.ComboBox1.Location = New System.Drawing.Point(106, 240) Me.ComboBox1.Location = New System.Drawing.Point(106, 352)
Me.ComboBox1.Name = "ComboBox1" Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(338, 21) Me.ComboBox1.Size = New System.Drawing.Size(338, 21)
Me.ComboBox1.TabIndex = 4 Me.ComboBox1.TabIndex = 4
@ -180,7 +188,7 @@ Partial Class frmMain
'Label7 'Label7
' '
Me.Label7.AutoSize = True Me.Label7.AutoSize = True
Me.Label7.Location = New System.Drawing.Point(12, 243) Me.Label7.Location = New System.Drawing.Point(12, 355)
Me.Label7.Name = "Label7" Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(35, 13) Me.Label7.Size = New System.Drawing.Size(35, 13)
Me.Label7.TabIndex = 2 Me.Label7.TabIndex = 2
@ -192,7 +200,7 @@ Partial Class frmMain
Me.TabControl1.Location = New System.Drawing.Point(450, 6) Me.TabControl1.Location = New System.Drawing.Point(450, 6)
Me.TabControl1.Name = "TabControl1" Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0 Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(472, 292) Me.TabControl1.Size = New System.Drawing.Size(472, 374)
Me.TabControl1.TabIndex = 5 Me.TabControl1.TabIndex = 5
' '
'TabPage1 'TabPage1
@ -201,14 +209,14 @@ Partial Class frmMain
Me.TabPage1.Location = New System.Drawing.Point(4, 22) Me.TabPage1.Location = New System.Drawing.Point(4, 22)
Me.TabPage1.Name = "TabPage1" Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Padding = New System.Windows.Forms.Padding(3) Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage1.Size = New System.Drawing.Size(464, 266) Me.TabPage1.Size = New System.Drawing.Size(464, 348)
Me.TabPage1.TabIndex = 0 Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "Raw GraphQL Result" Me.TabPage1.Text = "Raw GraphQL Result"
Me.TabPage1.UseVisualStyleBackColor = True Me.TabPage1.UseVisualStyleBackColor = True
' '
'btnLogin 'btnLogin
' '
Me.btnLogin.Location = New System.Drawing.Point(724, 300) 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)
Me.btnLogin.TabIndex = 0 Me.btnLogin.TabIndex = 0
@ -217,16 +225,80 @@ Partial Class frmMain
' '
'ProgressBar1 'ProgressBar1
' '
Me.ProgressBar1.Location = New System.Drawing.Point(12, 311) Me.ProgressBar1.Location = New System.Drawing.Point(12, 394)
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
' '
'txtProxyHost
'
Me.txtProxyHost.Location = New System.Drawing.Point(106, 240)
Me.txtProxyHost.Name = "txtProxyHost"
Me.txtProxyHost.Size = New System.Drawing.Size(338, 20)
Me.txtProxyHost.TabIndex = 1
'
'txtProxyUser
'
Me.txtProxyUser.Location = New System.Drawing.Point(106, 292)
Me.txtProxyUser.Name = "txtProxyUser"
Me.txtProxyUser.Size = New System.Drawing.Size(338, 20)
Me.txtProxyUser.TabIndex = 1
'
'txtProxyPass
'
Me.txtProxyPass.Location = New System.Drawing.Point(106, 318)
Me.txtProxyPass.Name = "txtProxyPass"
Me.txtProxyPass.Size = New System.Drawing.Size(338, 20)
Me.txtProxyPass.TabIndex = 1
'
'Label8
'
Me.Label8.AutoSize = True
Me.Label8.Location = New System.Drawing.Point(12, 243)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(58, 13)
Me.Label8.TabIndex = 2
Me.Label8.Text = "Proxy Host"
'
'Label9
'
Me.Label9.AutoSize = True
Me.Label9.Location = New System.Drawing.Point(12, 295)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(58, 13)
Me.Label9.TabIndex = 2
Me.Label9.Text = "Proxy User"
'
'Label10
'
Me.Label10.AutoSize = True
Me.Label10.Location = New System.Drawing.Point(12, 321)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(82, 13)
Me.Label10.TabIndex = 2
Me.Label10.Text = "Proxy Password"
'
'txtProxyPort
'
Me.txtProxyPort.Location = New System.Drawing.Point(106, 266)
Me.txtProxyPort.Name = "txtProxyPort"
Me.txtProxyPort.Size = New System.Drawing.Size(338, 20)
Me.txtProxyPort.TabIndex = 1
'
'Label11
'
Me.Label11.AutoSize = True
Me.Label11.Location = New System.Drawing.Point(12, 269)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(55, 13)
Me.Label11.TabIndex = 2
Me.Label11.Text = "Proxy Port"
'
'frmMain 'frmMain
' '
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(934, 346) Me.ClientSize = New System.Drawing.Size(934, 429)
Me.Controls.Add(Me.ProgressBar1) Me.Controls.Add(Me.ProgressBar1)
Me.Controls.Add(Me.TabControl1) Me.Controls.Add(Me.TabControl1)
Me.Controls.Add(Me.ComboBox1) Me.Controls.Add(Me.ComboBox1)
@ -234,14 +306,22 @@ Partial Class frmMain
Me.Controls.Add(Me.Label6) Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label10)
Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label11)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtConnectionString) Me.Controls.Add(Me.txtConnectionString)
Me.Controls.Add(Me.txtCertPass) Me.Controls.Add(Me.txtCertPass)
Me.Controls.Add(Me.txtCertFile) Me.Controls.Add(Me.txtCertFile)
Me.Controls.Add(Me.txtProxyPass)
Me.Controls.Add(Me.txtPassword) Me.Controls.Add(Me.txtPassword)
Me.Controls.Add(Me.txtProxyUser)
Me.Controls.Add(Me.txtUsername) Me.Controls.Add(Me.txtUsername)
Me.Controls.Add(Me.txtProxyPort)
Me.Controls.Add(Me.txtProxyHost)
Me.Controls.Add(Me.txtBaseUrl) Me.Controls.Add(Me.txtBaseUrl)
Me.Controls.Add(Me.btnLogin) Me.Controls.Add(Me.btnLogin)
Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.Button1)
@ -275,4 +355,12 @@ Partial Class frmMain
Friend WithEvents TabPage1 As TabPage Friend WithEvents TabPage1 As TabPage
Friend WithEvents btnLogin As Button Friend WithEvents btnLogin As Button
Friend WithEvents ProgressBar1 As ProgressBar Friend WithEvents ProgressBar1 As ProgressBar
Friend WithEvents txtProxyHost As TextBox
Friend WithEvents txtProxyUser As TextBox
Friend WithEvents txtProxyPass As TextBox
Friend WithEvents Label8 As Label
Friend WithEvents Label9 As Label
Friend WithEvents Label10 As Label
Friend WithEvents txtProxyPort As TextBox
Friend WithEvents Label11 As Label
End Class End Class

View File

@ -5,6 +5,7 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Config Imports DigitalData.Modules.Config
Imports Newtonsoft.Json Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq Imports Newtonsoft.Json.Linq
Imports System.Net
Public Class frmMain Public Class frmMain
Private _LogConfig As LogConfig Private _LogConfig As LogConfig
@ -58,6 +59,10 @@ Public Class frmMain
txtCertFile.Text = _Config.Config.CertificateFile txtCertFile.Text = _Config.Config.CertificateFile
txtCertPass.Text = _Config.Config.CertificatePass txtCertPass.Text = _Config.Config.CertificatePass
txtConnectionString.Text = _Config.Config.ConnectionString 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 ComboBox1.SelectedIndex = 0
@ -70,6 +75,7 @@ Public Class frmMain
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
_Interface = New GraphQLInterface(_LogConfig, _Interface = New GraphQLInterface(_LogConfig,
txtBaseUrl.Text, txtBaseUrl.Text,
txtUsername.Text, txtUsername.Text,
@ -77,6 +83,22 @@ Public Class frmMain
txtCertFile.Text, txtCertFile.Text,
txtCertPass.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 Dim oResponse = _Interface.Login
_Interface.SaveCookies(oResponse.Cookies.Item(0)) _Interface.SaveCookies(oResponse.Cookies.Item(0))
@ -137,14 +159,16 @@ Public Class frmMain
If oSuccess Then If oSuccess Then
_Logger.Debug("Record [{0}] inserted!", oItem.beschreibung) _Logger.Debug("Record [{0}] inserted!", oItem.beschreibung)
End If End If
oCounter += 1
ProgressBar1.Value = oCounter
Next Next
txtResults.Text &= "--------------------------------------------" & vbNewLine txtResults.Text &= "--------------------------------------------" & vbNewLine
txtResults.Text &= $"--- Datapool: {oDatapool}" & vbNewLine txtResults.Text &= $"--- Datapool: {oDatapool}" & vbNewLine
txtResults.Text &= JsonConvert.SerializeObject(oObj, Formatting.Indented) & vbNewLine txtResults.Text &= JsonConvert.SerializeObject(oObj, Formatting.Indented) & vbNewLine
oCounter += 1 Application.DoEvents()
ProgressBar1.Value = oCounter
Next Next
Else Else
MsgBox("Unknown query!", MsgBoxStyle.Exclamation, Text) 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 Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try 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.ConnectionString = txtConnectionString.Text
_Config.Config.BaseUrl = txtBaseUrl.Text _Config.Config.BaseUrl = txtBaseUrl.Text
_Config.Config.CertificateFile = txtCertFile.Text _Config.Config.CertificateFile = txtCertFile.Text
_Config.Config.CertificatePass = txtCertPass.Text _Config.Config.CertificatePass = txtCertPass.Text
_Config.Config.Email = txtUsername.Text _Config.Config.Email = txtUsername.Text
_Config.Config.Password = txtPassword.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 Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
End Try End Try

View File

@ -13,9 +13,10 @@ Public Class GraphQLInterface
Private _userPassword As String Private _userPassword As String
Private _certificate As X509Certificate Private _certificate As X509Certificate
Private _cookieJar As CookieContainer Private _cookieJar As CookieContainer
Private _Encoding As New UTF8Encoding Private _Encoding As New UTF8Encoding
Public Property Proxy As WebProxy
Public Sub New(LogConfig As LogConfig, BaseUrl As String, Email As String, Password As String, CertificateFile As String, CertificatePassword As String) Public Sub New(LogConfig As LogConfig, BaseUrl As String, Email As String, Password As String, CertificateFile As String, CertificatePassword As String)
Try Try
_logConfig = LogConfig _logConfig = LogConfig
@ -92,6 +93,9 @@ Public Class GraphQLInterface
Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest
Try Try
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}") Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}")
oRequest.Method = "POST" oRequest.Method = "POST"
oRequest.ContentType = "application/json" oRequest.ContentType = "application/json"
@ -99,6 +103,10 @@ Public Class GraphQLInterface
oRequest.ClientCertificates.Add(_certificate) oRequest.ClientCertificates.Add(_certificate)
oRequest.CookieContainer = GetCookies() oRequest.CookieContainer = GetCookies()
If Proxy IsNot Nothing Then
oRequest.Proxy = Proxy
End If
Return oRequest Return oRequest
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)