7 Commits

Author SHA1 Message Date
Jonathan Jenne
ffcfd017ce EDMI: JobTest 2020-05-14 13:17:52 +02:00
Jonathan Jenne
b8040cff2b Database: Clean up GetSQLConnection() 2020-05-14 13:17:40 +02:00
Jonathan Jenne
f3986bb8fa EDMI: WIP GraphQLJob 2020-05-14 13:17:11 +02:00
Jonathan Jenne
de2bb5e88d Config: Version 0.0.7.2 2020-05-14 13:16:43 +02:00
Jonathan Jenne
3d5315d032 Config: Fix creating ComputerConfig folder when no path is given 2020-05-14 13:16:22 +02:00
Jonathan Jenne
ab83044664 Logging: Version 2.0.2.0 2020-05-14 13:13:03 +02:00
Jonathan Jenne
267c90e287 Logging: Keep debug file open to prevent massive slowdown when writing many log messages 2020-05-14 13:12:46 +02:00
9 changed files with 83 additions and 28 deletions

View File

@@ -23,28 +23,41 @@ Partial Class Form1
<System.Diagnostics.DebuggerStepThrough()> _ <System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent() Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button() Me.Button1 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout() Me.SuspendLayout()
' '
'Button1 'Button1
' '
Me.Button1.Location = New System.Drawing.Point(253, 101) Me.Button1.Location = New System.Drawing.Point(12, 25)
Me.Button1.Name = "Button1" Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23) Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0 Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1" Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True Me.Button1.UseVisualStyleBackColor = True
' '
'TextBox1
'
Me.TextBox1.Font = New System.Drawing.Font("Consolas", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox1.Location = New System.Drawing.Point(93, 25)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(695, 413)
Me.TextBox1.TabIndex = 1
'
'Form1 'Form1
' '
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(800, 450) Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.Button1)
Me.Name = "Form1" Me.Name = "Form1"
Me.Text = "Form1" Me.Text = "Form1"
Me.ResumeLayout(False) Me.ResumeLayout(False)
Me.PerformLayout()
End Sub End Sub
Friend WithEvents Button1 As Button Friend WithEvents Button1 As Button
Friend WithEvents TextBox1 As TextBox
End Class End Class

View File

@@ -3,7 +3,8 @@ Imports DigitalData.Modules.Logging
Public Class Form1 Public Class Form1
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
Dim oLogConfig As New LogConfig(LogConfig.PathType.Temp) Dim oLogConfig As New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath, Nothing, "Digital Data", "JobTest")
oLogConfig.Debug = True
Dim oJob As New GraphQLJob(oLogConfig) Dim oJob As New GraphQLJob(oLogConfig)
Dim oArgs As New GraphQLArgs() With { Dim oArgs As New GraphQLArgs() With {
@@ -12,5 +13,7 @@ Public Class Form1
.QueryConfigPath = "E:\GraphQL" .QueryConfigPath = "E:\GraphQL"
} }
oJob.Start(oArgs) oJob.Start(oArgs)
MsgBox("Finished!", MsgBoxStyle.Critical)
End Sub End Sub
End Class End Class

View File

@@ -86,8 +86,10 @@ Public Class ConfigManager(Of T)
_UserDirectory = _File.CreateDirectory(UserConfigPath) _UserDirectory = _File.CreateDirectory(UserConfigPath)
_UserConfigPath = Path.Combine(_UserDirectory, USER_CONFIG_NAME) _UserConfigPath = Path.Combine(_UserDirectory, USER_CONFIG_NAME)
_ComputerDirectory = _File.CreateDirectory(ComputerConfigPath) If ComputerConfigPath <> String.Empty Then
_ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME) _ComputerDirectory = _File.CreateDirectory(ComputerConfigPath)
_ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME)
End If
If ApplicationStartupPath <> String.Empty Then If ApplicationStartupPath <> String.Empty Then
_AppConfigPath = Path.Combine(ApplicationStartupPath, APP_CONFIG_NAME) _AppConfigPath = Path.Combine(ApplicationStartupPath, APP_CONFIG_NAME)

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("0.0.7.1")> <Assembly: AssemblyVersion("0.0.7.2")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@@ -64,21 +64,16 @@ Public Class MSSQLServer
Private Function GetSQLConnection() As SqlConnection Private Function GetSQLConnection() As SqlConnection
Try Try
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = CurrentSQLConnectionString}
Dim oConnection As New SqlConnection(CurrentSQLConnectionString) Dim oConnection As New SqlConnection(CurrentSQLConnectionString)
oConnection.Open() oConnection.Open()
Dim OMyConnection As New SqlClient.SqlConnection(CurrentSQLConnectionString) 'csb.ConnectionString)
Dim csb As New SqlClient.SqlConnectionStringBuilder
csb.ConnectionString = CurrentSQLConnectionString
Dim constr = OMyConnection.ConnectionString
Try
constr = constr.Replace(csb.Password, "XXXXX")
Catch ex As Exception
Try
Dim oConnectionString = CurrentSQLConnectionString.Replace(oBuilder.Password, "XXXXX")
_Logger.Debug($"Following Connectionstring is open: {oConnectionString}")
Catch ex As Exception
End Try End Try
'If constr.Contains("Trusted_Connection=True") = False Then
' constr = constr.Replace(csb.Password, "XXXXX")
'End If
_Logger.Debug($"Following Connectionstring is open: {constr}")
Return oConnection Return oConnection
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)

View File

@@ -8,6 +8,7 @@ Public Class GraphQLConfig
Public Property Queries As New List(Of Query) Public Property Queries As New List(Of Query)
Public Class Query Public Class Query
Public Property Name As String
Public Property ConnectionString As String = "" Public Property ConnectionString As String = ""
Public Property ClearBeforeFill As Boolean = False Public Property ClearBeforeFill As Boolean = False
Public Property QueryString As String = "" Public Property QueryString As String = ""

View File

@@ -4,6 +4,9 @@ Imports DigitalData.Modules.Jobs
Imports DigitalData.Modules.Config Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports Newtonsoft.Json.Linq Imports Newtonsoft.Json.Linq
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text.RegularExpressions
Public Class GraphQLJob Public Class GraphQLJob
Inherits JobBase Inherits JobBase
@@ -25,16 +28,17 @@ Public Class GraphQLJob
End With End With
' Login to get cookie ' Login to get cookie
_Logger.Info("Logging in..") _Logger.Debug("Logging in")
Dim oLoginResponse = oInterface.Login() Dim oLoginResponse = oInterface.Login()
' save cookie for future requests ' save cookie for future requests
oInterface.SaveCookies(oLoginResponse.Cookies.Item(0)) oInterface.SaveCookies(oLoginResponse.Cookies.Item(0))
_Logger.Info("Getting the data..") _Logger.Debug("Getting the data")
For Each oQuery As GraphQLConfig.Query In oConfigManager.Config.Queries For Each oQuery As GraphQLConfig.Query In oConfigManager.Config.Queries
Dim oCurrentQuery = oQuery Dim oCurrentQuery = oQuery
Dim oDatabase As New Database.MSSQLServer(_LogConfig, oQuery.ConnectionString)
' get the data ' get the data
Dim oDataResponse = oInterface.GetData(oCurrentQuery.QueryString, oCurrentQuery.OperationName) Dim oDataResponse = oInterface.GetData(oCurrentQuery.QueryString, oCurrentQuery.OperationName)
@@ -47,11 +51,11 @@ Public Class GraphQLJob
End Using End Using
End Using End Using
oCurrentQuery = HandleResponse(oResult, oCurrentQuery) HandleResponse(oResult, oCurrentQuery, oDatabase)
Next Next
' logout ' logout
_Logger.Info("Logging out..") _Logger.Debug("Logging out")
Dim oLogoutResponse = oInterface.Logout() Dim oLogoutResponse = oInterface.Logout()
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
@@ -59,19 +63,47 @@ Public Class GraphQLJob
End Try End Try
End Sub End Sub
Private Function HandleResponse(JsonString As String, QueryData As GraphQLConfig.Query) As GraphQLConfig.Query Private Function HandleResponse(JsonString As String, QueryData As GraphQLConfig.Query, DB As Database.MSSQLServer)
Dim oObj As JObject = JObject.Parse(JsonString) Dim oObj As JObject = JObject.Parse(JsonString)
Dim oResultList = oObj.SelectToken(QueryData.MappingBasePath) Dim oResultList = oObj.SelectToken(QueryData.MappingBasePath)
Dim oMappings = QueryData.MappingFields Dim oMappings = QueryData.MappingFields
_Logger.Info("Processing Queue [{0}] with [{1}] Items", QueryData.Name, oResultList.Count)
If QueryData.ClearBeforeFill Then
_Logger.Info("Clearing Table {0} before insert", QueryData.DestinationTable)
Try
DB.ExecuteNonQuery($"DELETE FROM {QueryData.DestinationTable}")
Catch ex As Exception
_Logger.Error(ex)
End Try
End If
For Each oResultItem In oResultList For Each oResultItem In oResultList
For Each oMapping In oMappings Try
Dim oValue = oResultItem.SelectToken(oMapping.SourcePath).ToString() Dim oValues As New List(Of String)
Dim oKeys As New List(Of String)
' TODO: Build SQL For Each oMapping In oMappings
Next Dim oValue = oResultItem.SelectToken(oMapping.SourcePath).ToString()
'TODO: Insert into db oValues.Add(oValue)
oKeys.Add(oMapping.DestinationColumn)
Next
Dim oColumnValues = oValues.
Select(Function(Value) Regex.Replace(Value, "'", "''")).
Select(Function(Value) $"'{Value}'").
ToList()
Dim oValueString = String.Join(",", oColumnValues)
Dim oColumns = String.Join(",", oKeys.ToArray)
Dim oSQL As String = $"INSERT INTO {QueryData.DestinationTable} ({oColumns}) VALUES ({oValueString})"
DB.ExecuteNonQuery(oSQL)
Catch ex As Exception
_Logger.Error(ex)
End Try
Next Next
Return QueryData Return QueryData

View File

@@ -56,7 +56,13 @@ Imports NLog.Targets
''' </remarks> ''' </remarks>
Public Class LogConfig Public Class LogConfig
#Region "Private Properties" #Region "Private Properties"
Private Const OPEN_FILE_CACHE_TIMEOUT As Integer = 5
Private Const OPEN_FILE_FLUSH_TIMEOUT As Integer = 5
Private Const AUTO_FLUSH As Boolean = True
Private Const KEEP_FILES_OPEN As Boolean = False Private Const KEEP_FILES_OPEN As Boolean = False
Private Const KEEP_FILES_OPEN_DEBUG As Boolean = True
' MAX_ARCHIVES_FILES works like this (in version 4.5.8): ' MAX_ARCHIVES_FILES works like this (in version 4.5.8):
' 0 = keep ALL archives files ' 0 = keep ALL archives files
' 1 = only keep latest logfile and NO archive files ' 1 = only keep latest logfile and NO archive files
@@ -427,7 +433,10 @@ Public Class LogConfig
.Layout = LOG_FORMAT_DEBUG, .Layout = LOG_FORMAT_DEBUG,
.MaxArchiveFiles = MAX_ARCHIVE_FILES_DEBUG_DETAIL, .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEBUG_DETAIL,
.ArchiveEvery = ARCHIVE_EVERY, .ArchiveEvery = ARCHIVE_EVERY,
.KeepFileOpen = KEEP_FILES_OPEN .KeepFileOpen = KEEP_FILES_OPEN_DEBUG,
.OpenFileCacheTimeout = OPEN_FILE_CACHE_TIMEOUT,
.AutoFlush = AUTO_FLUSH,
.OpenFileFlushTimeout = OPEN_FILE_FLUSH_TIMEOUT
} }
Return debugLog Return debugLog

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.0.1.0")> <Assembly: AssemblyVersion("2.0.2.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>