diff --git a/GUIs.Test.EDMIBenchmark/Form1.vb b/GUIs.Test.EDMIBenchmark/Form1.vb index fd3aa573..318553d3 100644 --- a/GUIs.Test.EDMIBenchmark/Form1.vb +++ b/GUIs.Test.EDMIBenchmark/Form1.vb @@ -58,7 +58,7 @@ Public Class Form1 AddLogMessage($"Importing {oFileInfo.Name}... ({FormatBytes(oFileInfo.Length)})") - Dim oObjectId As Long = Await _Client.ImportFileAsync(oFileInfo.Name, "WichtigesDokument", 1, 0) + Dim oObjectId As Long = Await _Client.ImportFileAsync(oFileInfo.FullName, "WichtigesDokument", 1, 0) AddLogMessage($"File with Id [{oObjectId}] imported!") oSW.Stop() AddLogMessage($"Import Time: {FormatTime(oSW.ElapsedMilliseconds)}") diff --git a/GUIs.Test.GraphQLTest/frmMain.vb b/GUIs.Test.GraphQLTest/frmMain.vb index e06ba351..dfb0d3f7 100644 --- a/GUIs.Test.GraphQLTest/frmMain.vb +++ b/GUIs.Test.GraphQLTest/frmMain.vb @@ -6,6 +6,7 @@ Imports DigitalData.Modules.Config Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports System.Net +Imports System.Text.RegularExpressions Public Class frmMain Private _LogConfig As LogConfig @@ -139,6 +140,8 @@ Public Class frmMain txtResult.Text = String.Empty + Dim oTotalTotal As Integer = 0 + For Each oDatapool In _Datapools Dim oQuery As String = GRAPHQL_QUERY_SAP_DATA.Trim.Replace("__DATA_POOL__", oDatapool) Dim oDataResponse = _Interface.GetData(oQuery, "SAPDaten") @@ -161,7 +164,9 @@ Public Class frmMain 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 oBeschreibung = Regex.Replace(oItem.beschreibung, "'", "''", RegexOptions.IgnoreCase) + + Dim oSQL = $"INSERT INTO TBCUST_SYNC_API_SAPDATEN (BESCHREIBUNG, BUCHUNGSKREIS, KOSTENSTELLE, GUELTIG_BIS) VALUES ('{oBeschreibung}', '{oItem.buchungskreis}', '{oItem.kostenstelle}', '{oItem.gueltig_bis}')" Dim oSuccess = _MSSQL.ExecuteNonQuery(oSQL) If oSuccess Then @@ -177,7 +182,11 @@ Public Class frmMain txtResult.Text &= JsonConvert.SerializeObject(oObj, Formatting.Indented) & vbNewLine Application.DoEvents() + + oTotalTotal += oTotal Next + + MsgBox($"Query finished! Lines inserted: [{oTotalTotal}]", MsgBoxStyle.Information, Text) ElseIf cmbQuery.Text = "Custom" Then If txtOperation.Text = String.Empty Then MsgBox("Please select an operation!", MsgBoxStyle.Exclamation, Text) diff --git a/GUIs.Test.JobTest/App.config b/GUIs.Test.JobTest/App.config new file mode 100644 index 00000000..ffaf5407 --- /dev/null +++ b/GUIs.Test.JobTest/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/GUIs.Test.JobTest/Form1.Designer.vb b/GUIs.Test.JobTest/Form1.Designer.vb new file mode 100644 index 00000000..ebc083b1 --- /dev/null +++ b/GUIs.Test.JobTest/Form1.Designer.vb @@ -0,0 +1,63 @@ + _ +Partial Class Form1 + Inherits System.Windows.Forms.Form + + 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Wird vom Windows Form-Designer benötigt. + Private components As System.ComponentModel.IContainer + + 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich. + 'Das Bearbeiten ist mit dem Windows Form-Designer möglich. + 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. + _ + Private Sub InitializeComponent() + Me.Button1 = New System.Windows.Forms.Button() + Me.TextBox1 = New System.Windows.Forms.TextBox() + Me.SuspendLayout() + ' + 'Button1 + ' + Me.Button1.Location = New System.Drawing.Point(12, 25) + Me.Button1.Name = "Button1" + Me.Button1.Size = New System.Drawing.Size(75, 23) + Me.Button1.TabIndex = 0 + Me.Button1.Text = "Button1" + 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 + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(800, 450) + Me.Controls.Add(Me.TextBox1) + Me.Controls.Add(Me.Button1) + Me.Name = "Form1" + Me.Text = "Form1" + Me.ResumeLayout(False) + Me.PerformLayout() + + End Sub + + Friend WithEvents Button1 As Button + Friend WithEvents TextBox1 As TextBox +End Class diff --git a/GUIs.Test.JobTest/Form1.resx b/GUIs.Test.JobTest/Form1.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/GUIs.Test.JobTest/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GUIs.Test.JobTest/Form1.vb b/GUIs.Test.JobTest/Form1.vb new file mode 100644 index 00000000..1a155ed1 --- /dev/null +++ b/GUIs.Test.JobTest/Form1.vb @@ -0,0 +1,19 @@ +Imports DigitalData.Modules.Jobs +Imports DigitalData.Modules.Logging + +Public Class Form1 + Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click + Dim oLogConfig As New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath, Nothing, "Digital Data", "JobTest") + oLogConfig.Debug = True + Dim oJob As New GraphQLJob(oLogConfig) + + Dim oArgs As New GraphQLArgs() With { + .Enabled = True, + .Interval = 999, + .QueryConfigPath = "E:\GraphQL" + } + oJob.Start(oArgs) + + MsgBox("Finished!", MsgBoxStyle.Critical) + End Sub +End Class diff --git a/GUIs.Test.JobTest/GUIs.Test.JobTest.vbproj b/GUIs.Test.JobTest/GUIs.Test.JobTest.vbproj new file mode 100644 index 00000000..ac5a1c67 --- /dev/null +++ b/GUIs.Test.JobTest/GUIs.Test.JobTest.vbproj @@ -0,0 +1,133 @@ + + + + + Debug + AnyCPU + {CEC6B41B-764B-4304-B4F8-BFEBA37A03FB} + WinExe + GUIs.Test.JobTest.My.MyApplication + GUIs.Test.JobTest + GUIs.Test.JobTest + 512 + WindowsForms + v4.7.2 + true + true + + + AnyCPU + true + full + true + true + bin\Debug\ + GUIs.Test.JobTest.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + AnyCPU + pdbonly + false + true + true + bin\Release\ + GUIs.Test.JobTest.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Form + + + Form1.vb + Form + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + Form1.vb + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + + {39ec839a-3c30-4922-a41e-6b09d1dde5c3} + Jobs + + + {903b2d7d-3b80-4be9-8713-7447b704e1b0} + Logging + + + + \ No newline at end of file diff --git a/GUIs.Test.JobTest/My Project/Application.Designer.vb b/GUIs.Test.JobTest/My Project/Application.Designer.vb new file mode 100644 index 00000000..3dcba675 --- /dev/null +++ b/GUIs.Test.JobTest/My Project/Application.Designer.vb @@ -0,0 +1,38 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + 'NOTE: This file is auto-generated; do not modify it directly. To make changes, + ' or if you encounter build errors in this file, go to the Project Designer + ' (go to Project Properties or double-click the My Project node in + ' Solution Explorer), and make changes on the Application tab. + ' + Partial Friend Class MyApplication + + _ + Public Sub New() + MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) + Me.IsSingleInstance = false + Me.EnableVisualStyles = true + Me.SaveMySettingsOnExit = true + Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses + End Sub + + _ + Protected Overrides Sub OnCreateMainForm() + Me.MainForm = Global.GUIs.Test.JobTest.Form1 + End Sub + End Class +End Namespace diff --git a/GUIs.Test.JobTest/My Project/Application.myapp b/GUIs.Test.JobTest/My Project/Application.myapp new file mode 100644 index 00000000..1243847f --- /dev/null +++ b/GUIs.Test.JobTest/My Project/Application.myapp @@ -0,0 +1,11 @@ + + + true + Form1 + false + 0 + true + 0 + 0 + true + diff --git a/GUIs.Test.JobTest/My Project/AssemblyInfo.vb b/GUIs.Test.JobTest/My Project/AssemblyInfo.vb new file mode 100644 index 00000000..896cf092 --- /dev/null +++ b/GUIs.Test.JobTest/My Project/AssemblyInfo.vb @@ -0,0 +1,35 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + +' Allgemeine Informationen über eine Assembly werden über die folgenden +' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +' die einer Assembly zugeordnet sind. + +' Werte der Assemblyattribute überprüfen + + + + + + + + + + +'Die folgende GUID wird für die typelib-ID verwendet, wenn dieses Projekt für COM verfügbar gemacht wird. + + +' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +' +' Hauptversion +' Nebenversion +' Buildnummer +' Revision +' +' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +' indem Sie "*" wie unten gezeigt eingeben: +' + + + diff --git a/GUIs.Test.JobTest/My Project/Resources.Designer.vb b/GUIs.Test.JobTest/My Project/Resources.Designer.vb new file mode 100644 index 00000000..69aacc95 --- /dev/null +++ b/GUIs.Test.JobTest/My Project/Resources.Designer.vb @@ -0,0 +1,62 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("GUIs.Test.JobTest.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set(ByVal value As Global.System.Globalization.CultureInfo) + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/GUIs.Test.JobTest/My Project/Resources.resx b/GUIs.Test.JobTest/My Project/Resources.resx new file mode 100644 index 00000000..af7dbebb --- /dev/null +++ b/GUIs.Test.JobTest/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GUIs.Test.JobTest/My Project/Settings.Designer.vb b/GUIs.Test.JobTest/My Project/Settings.Designer.vb new file mode 100644 index 00000000..7d88e474 --- /dev/null +++ b/GUIs.Test.JobTest/My Project/Settings.Designer.vb @@ -0,0 +1,73 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.GUIs.Test.JobTest.My.MySettings + Get + Return Global.GUIs.Test.JobTest.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/GUIs.Test.JobTest/My Project/Settings.settings b/GUIs.Test.JobTest/My Project/Settings.settings new file mode 100644 index 00000000..85b890b3 --- /dev/null +++ b/GUIs.Test.JobTest/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Modules.Config/ConfigManager.vb b/Modules.Config/ConfigManager.vb index e357490e..d8120d0b 100644 --- a/Modules.Config/ConfigManager.vb +++ b/Modules.Config/ConfigManager.vb @@ -86,8 +86,10 @@ Public Class ConfigManager(Of T) _UserDirectory = _File.CreateDirectory(UserConfigPath) _UserConfigPath = Path.Combine(_UserDirectory, USER_CONFIG_NAME) - _ComputerDirectory = _File.CreateDirectory(ComputerConfigPath) - _ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME) + If ComputerConfigPath <> String.Empty Then + _ComputerDirectory = _File.CreateDirectory(ComputerConfigPath) + _ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME) + End If If ApplicationStartupPath <> String.Empty Then _AppConfigPath = Path.Combine(ApplicationStartupPath, APP_CONFIG_NAME) diff --git a/Modules.Config/My Project/AssemblyInfo.vb b/Modules.Config/My Project/AssemblyInfo.vb index 6c7fc2f2..5cf7a2d6 100644 --- a/Modules.Config/My Project/AssemblyInfo.vb +++ b/Modules.Config/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/Modules.Database/MSSQLServer.vb b/Modules.Database/MSSQLServer.vb index a27a4358..381de4ba 100644 --- a/Modules.Database/MSSQLServer.vb +++ b/Modules.Database/MSSQLServer.vb @@ -64,21 +64,16 @@ Public Class MSSQLServer Private Function GetSQLConnection() As SqlConnection Try + Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = CurrentSQLConnectionString} Dim oConnection As New SqlConnection(CurrentSQLConnectionString) 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 - '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 Catch ex As Exception _Logger.Error(ex) diff --git a/Modules.EDMIAPI/Client.vb b/Modules.EDMIAPI/Client.vb index 8bceaa00..9cdd7a7d 100644 --- a/Modules.EDMIAPI/Client.vb +++ b/Modules.EDMIAPI/Client.vb @@ -81,7 +81,7 @@ Public Class Client End If Using oStream As New FileStream(FilePath, FileMode.Open) - Dim oContents As Byte() = {} + Dim oContents(oStream.Length) As Byte Dim oBytesRead = Await oStream.ReadAsync(oContents, 0, oStream.Length) Dim oData As New DocumentImportRequest() With { .FileName = oFileInfo.Name, diff --git a/Modules.Filesystem/Filesystem.vbproj b/Modules.Filesystem/Filesystem.vbproj index 28c0351c..8f1e83fc 100644 --- a/Modules.Filesystem/Filesystem.vbproj +++ b/Modules.Filesystem/Filesystem.vbproj @@ -80,9 +80,7 @@ - - PreserveNewest - + diff --git a/Modules.Interfaces/GraphQLInterface.vb b/Modules.Interfaces/GraphQLInterface.vb index 9956288d..043e08ea 100644 --- a/Modules.Interfaces/GraphQLInterface.vb +++ b/Modules.Interfaces/GraphQLInterface.vb @@ -44,7 +44,7 @@ Public Class GraphQLInterface Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, CertificateFingerprint, False) If oFoundCerts.Count = 0 Then - MsgBox($"Das Zertifikat mit dem Fingerprint [{CertificateFingerprint}] konnte nicht im Store [{oStore.Name}] gefunden werden!") + _logger.Warn("Certificate could not be found! Exiting.") Exit Sub End If @@ -122,6 +122,7 @@ Public Class GraphQLInterface oRequest.ContentLength = PostData.Length oRequest.ClientCertificates.Add(_certificate) oRequest.CookieContainer = GetCookies() + oRequest.Proxy = Nothing If Proxy Is Nothing Then diff --git a/Modules.Jobs/EDMI/GraphQL/GraphQLArgs.vb b/Modules.Jobs/EDMI/GraphQL/GraphQLArgs.vb index 36ed04f1..392d86cc 100644 --- a/Modules.Jobs/EDMI/GraphQL/GraphQLArgs.vb +++ b/Modules.Jobs/EDMI/GraphQL/GraphQLArgs.vb @@ -1,9 +1,5 @@ Public Class GraphQLArgs Inherits JobArgs - Public CertificateFile As String - Public CertificatePassword As String - Public Email As String - Public Password As String - Public BaseUrl As String + Public QueryConfigPath As String End Class diff --git a/Modules.Jobs/EDMI/GraphQL/GraphQLConfig.vb b/Modules.Jobs/EDMI/GraphQL/GraphQLConfig.vb new file mode 100644 index 00000000..383e58ff --- /dev/null +++ b/Modules.Jobs/EDMI/GraphQL/GraphQLConfig.vb @@ -0,0 +1,27 @@ +Imports System.Collections.Generic + +Public Class GraphQLConfig + Public Property BaseUrl As String = "" + Public Property Email As String = "" + Public Property Password As String = "" + Public Property CertificateFingerprint As String = "" + Public Property Queries As New List(Of Query) + + Public Class Query + Public Property Name As String + Public Property ConnectionString As String = "" + Public Property ClearBeforeFill As Boolean = False + Public Property QueryString As String = "" + Public Property OperationName As String = "" + Public Property DestinationTable As String = "" + + Public Property MappingBasePath As String = "" + Public Property MappingFields As New List(Of FieldMapping) + End Class + + Public Class FieldMapping + Public SourcePath As String = "" + Public DestinationColumn As String = "" + Public Value As String = "" + End Class +End Class diff --git a/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb b/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb index 1c79ba30..f32b9b8b 100644 --- a/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb +++ b/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb @@ -1,7 +1,12 @@ Imports System.IO Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Jobs +Imports DigitalData.Modules.Config Imports DigitalData.Modules.Logging +Imports Newtonsoft.Json.Linq +Imports System.Collections.Generic +Imports System.Linq +Imports System.Text.RegularExpressions Public Class GraphQLJob Inherits JobBase @@ -12,56 +17,98 @@ Public Class GraphQLJob End Sub Public Sub Start(Args As GraphQLArgs) Implements IJob(Of GraphQLArgs).Start - Dim oInterface As New GraphQLInterface( - _LogConfig, Args.BaseUrl, Args.Email, Args.Password, Args.CertificateFile, Args.CertificatePassword) + Try + Dim oConfigPath As String = Args.QueryConfigPath + Dim oConfigManager As New ConfigManager(Of GraphQLConfig)(_LogConfig, oConfigPath) - Dim oQuery = "query Nls{ - niederlassungen(offset: 0, limit: 5) { - niederlassungen { - mdnr - bezeichnung - sparte { - id - name - __typename - } - __typename - } - __typename - } - }" + Dim oInterface As GraphQLInterface - _Logger.Info("Logging in..") + With oConfigManager.Config + oInterface = New GraphQLInterface(_LogConfig, .BaseUrl, .Email, .Password, .CertificateFingerprint) + End With - ' Login to get cookie - Dim oLoginResponse = oInterface.Login() + ' Login to get cookie + _Logger.Debug("Logging in") + Dim oLoginResponse = oInterface.Login() - ' save cookie for future requests - oInterface.SaveCookies(oLoginResponse.Cookies.Item(0)) + ' save cookie for future requests + oInterface.SaveCookies(oLoginResponse.Cookies.Item(0)) - _Logger.Info("Getting the data..") + _Logger.Debug("Getting the data") - ' get the data - Dim oDataResponse = oInterface.GetData(oQuery, "Nls") - Dim oResult As String + For Each oQuery As GraphQLConfig.Query In oConfigManager.Config.Queries + Dim oCurrentQuery = oQuery + Dim oDatabase As New Database.MSSQLServer(_LogConfig, oQuery.ConnectionString) - ' write data to string - Using oStream = oDataResponse.GetResponseStream() - Using oReader As New StreamReader(oStream) - oResult = oReader.ReadToEnd() - End Using - End Using + ' get the data + Dim oDataResponse = oInterface.GetData(oCurrentQuery.QueryString, oCurrentQuery.OperationName) + Dim oResult As String - ' TODO: save data to file - _Logger.Info("Response is:") - _Logger.Info(oResult) + ' write data to string + Using oStream = oDataResponse.GetResponseStream() + Using oReader As New StreamReader(oStream) + oResult = oReader.ReadToEnd() + End Using + End Using - _Logger.Info("Logging out..") + HandleResponse(oResult, oCurrentQuery, oDatabase) + Next - ' logout - Dim oLogoutResponse = oInterface.Logout() + ' logout + _Logger.Debug("Logging out") + Dim oLogoutResponse = oInterface.Logout() + Catch ex As Exception + _Logger.Error(ex) + Throw ex + End Try End Sub + Private Function HandleResponse(JsonString As String, QueryData As GraphQLConfig.Query, DB As Database.MSSQLServer) + Dim oObj As JObject = JObject.Parse(JsonString) + Dim oResultList = oObj.SelectToken(QueryData.MappingBasePath) + 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 + Try + Dim oValues As New List(Of String) + Dim oKeys As New List(Of String) + + For Each oMapping In oMappings + Dim oValue = oResultItem.SelectToken(oMapping.SourcePath).ToString() + + 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 + + Return QueryData + End Function + Public Function ShouldStart(Arguments As GraphQLArgs) As Boolean Implements IJob(Of GraphQLArgs).ShouldStart Return Arguments.Enabled End Function diff --git a/Modules.Jobs/JobConfig.vb b/Modules.Jobs/JobConfig.vb index 9b086bd2..4c09a2cd 100644 --- a/Modules.Jobs/JobConfig.vb +++ b/Modules.Jobs/JobConfig.vb @@ -2,6 +2,7 @@ Public Class JobConfig Public Enabled As Boolean + Public StartImmediately As Boolean Public CronExpression As String Public Arguments As Dictionary(Of String, String) End Class \ No newline at end of file diff --git a/Modules.Jobs/JobConfigParser.vb b/Modules.Jobs/JobConfigParser.vb index 74a7cfd5..fff93541 100644 --- a/Modules.Jobs/JobConfigParser.vb +++ b/Modules.Jobs/JobConfigParser.vb @@ -2,7 +2,7 @@ Imports System.Text.RegularExpressions Public Class JobConfigParser - Private Shared JobOptionsRegex As New Regex("(?True|False)\|(?[\w\d\s,\?*-/]*)(?:\|(?(?:\w*::[^,\n]+,?)*))?") + Private Shared JobOptionsRegex As New Regex("(?True|False|Debug)\|(?[\w\d\s,\?*-/]*)(?:\|(?(?:\w*::[^,\n]+,?)*))?") Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::[^,\n]+,?)?)+") Private Const ARGS_ITEM_DELIMITER As String = "," Private Const ARGS_KEYVALUE_DELIMITER As String = "::" @@ -21,11 +21,11 @@ Public Class JobConfigParser Dim oSplitOptions As String() = ConfigString.Split(ARGS_LIST_DELIMITER) If oSplitOptions.Length = 3 Then - oOptions.Enabled = CBool(oSplitOptions(0)) + oOptions = ParseEnabled(oSplitOptions(0), oOptions) oOptions.CronExpression = oSplitOptions(1) oOptions.Arguments = ParseOptionalArguments(oSplitOptions(2)) ElseIf oSplitOptions.Length = 2 Then - oOptions.Enabled = CBool(oSplitOptions(0)) + oOptions = ParseEnabled(oSplitOptions(0), oOptions) oOptions.CronExpression = oSplitOptions(1) oOptions.Arguments = New Dictionary(Of String, String) Else @@ -38,6 +38,22 @@ Public Class JobConfigParser End If End Function + Public Shared Function ParseEnabled(EnabledValue As String, Options As JobConfig) As JobConfig + Select Case EnabledValue + Case "True" + Options.Enabled = True + Options.StartImmediately = False + Case "Debug" + Options.Enabled = True + Options.StartImmediately = True + Case Else + Options.Enabled = False + Options.StartImmediately = False + End Select + + Return Options + End Function + Private Shared Function ParseOptionalArguments(ArgsString As String) As Dictionary(Of String, String) Dim oArgsDictionary As New Dictionary(Of String, String) diff --git a/Modules.Jobs/Jobs.vbproj b/Modules.Jobs/Jobs.vbproj index 734d342a..8b7daa08 100644 --- a/Modules.Jobs/Jobs.vbproj +++ b/Modules.Jobs/Jobs.vbproj @@ -64,6 +64,10 @@ + + {44982f9b-6116-44e2-85d0-f39650b1ef99} + Config + {991d0231-4623-496d-8bd0-9ca906029cbc} Filesystem @@ -85,6 +89,7 @@ + @@ -109,6 +114,9 @@ ..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + ..\packages\NLog.4.7.0\lib\net45\NLog.dll diff --git a/Modules.Jobs/My Project/AssemblyInfo.vb b/Modules.Jobs/My Project/AssemblyInfo.vb index 8e2ba0be..c555899d 100644 --- a/Modules.Jobs/My Project/AssemblyInfo.vb +++ b/Modules.Jobs/My Project/AssemblyInfo.vb @@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices ' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern ' übernehmen, indem Sie "*" eingeben: - + diff --git a/Modules.Jobs/packages.config b/Modules.Jobs/packages.config index 9df4a30e..c6e89356 100644 --- a/Modules.Jobs/packages.config +++ b/Modules.Jobs/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file diff --git a/Modules.Logging/LogConfig.vb b/Modules.Logging/LogConfig.vb index 66e92604..11831477 100644 --- a/Modules.Logging/LogConfig.vb +++ b/Modules.Logging/LogConfig.vb @@ -56,7 +56,13 @@ Imports NLog.Targets ''' Public Class LogConfig #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_DEBUG As Boolean = True + ' MAX_ARCHIVES_FILES works like this (in version 4.5.8): ' 0 = keep ALL archives files ' 1 = only keep latest logfile and NO archive files @@ -427,7 +433,10 @@ Public Class LogConfig .Layout = LOG_FORMAT_DEBUG, .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEBUG_DETAIL, .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 diff --git a/Modules.Logging/My Project/AssemblyInfo.vb b/Modules.Logging/My Project/AssemblyInfo.vb index 297eacca..182fe287 100644 --- a/Modules.Logging/My Project/AssemblyInfo.vb +++ b/Modules.Logging/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/Service.JobRunner/App.config b/Service.JobRunner/App.config index e9041aa4..36cc84f4 100644 --- a/Service.JobRunner/App.config +++ b/Service.JobRunner/App.config @@ -35,7 +35,7 @@ True|10/0 * * * * ?|Foo::Bar - False|0 0 0/1 * * ?|CertPath::E:\jonathanjenne.pfx,CertPass::jonathanjenne,Username::j.jenne@digitaldata.works,Password::DigitalData01!,BaseUrl::http://data.api.wisag.de:8090 + False|0 0 0/1 * * ?|QueryConfigFolder::E:\JenneJ\GraphQL diff --git a/Service.JobRunner/JobRunner.vb b/Service.JobRunner/JobRunner.vb index f5fc2ba2..b35d8917 100644 --- a/Service.JobRunner/JobRunner.vb +++ b/Service.JobRunner/JobRunner.vb @@ -1,5 +1,4 @@ Imports System.Collections.Specialized -Imports System.Text.RegularExpressions Imports DigitalData.Modules.Database Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Logging @@ -65,7 +64,7 @@ Public Class JobRunner {"Args", oJobConfig.Arguments} } - Dim oJobDetail = JobBuilder.Create(Of T)(). + Dim oJob = JobBuilder.Create(Of T)(). WithIdentity(oJobIdentity). UsingJobData(oJobData). Build() @@ -77,11 +76,28 @@ Public Class JobRunner Build() If oJobConfig.Enabled Then - Await _scheduler.ScheduleJob(oJobDetail, oTrigger) - _Logger.Info("Job {0} started.", JobName) + Await _scheduler.ScheduleJob(oJob, oTrigger) + + _Logger.Info("Job {0} scheduled.", JobName) Else _Logger.Info("Job {0} is disabled.", JobName) End If + + ' If StartImmediately is True, start Job after 10 Seconds + If oJobConfig.StartImmediately Then + Dim oDebugJob = JobBuilder.Create(Of T)(). + WithIdentity(oJobIdentity & "-DEBUG"). + UsingJobData(oJobData). + Build() + + Dim oDebugTrigger = TriggerBuilder.Create(). + WithIdentity(oTriggerIdentity & "-DEBUG"). + StartAt(DateBuilder.FutureDate(10, IntervalUnit.Second)). + Build() + + _Logger.Info("Job {0} will start in 10 Seconds.", JobName) + Await _scheduler.ScheduleJob(oDebugJob, oDebugTrigger) + End If End Function Public Async Sub [Stop]() @@ -92,7 +108,7 @@ Public Class JobRunner Private Class LogProvider Implements ILogProvider - Private _Logger As DigitalData.Modules.Logging.Logger + Private _Logger As Modules.Logging.Logger Public Sub New(Logger As DigitalData.Modules.Logging.Logger) MyBase.New() diff --git a/Service.JobRunner/JobRunner.vbproj b/Service.JobRunner/JobRunner.vbproj index 74db8716..c1f26d4d 100644 --- a/Service.JobRunner/JobRunner.vbproj +++ b/Service.JobRunner/JobRunner.vbproj @@ -147,6 +147,10 @@ + + {44982f9b-6116-44e2-85d0-f39650b1ef99} + Config + {EAF0EA75-5FA7-485D-89C7-B2D843B03A96} Database diff --git a/Service.JobRunner/Jobs/GraphQLJob.vb b/Service.JobRunner/Jobs/GraphQLJob.vb index 33ae9cdc..d2ebf3dc 100644 --- a/Service.JobRunner/Jobs/GraphQLJob.vb +++ b/Service.JobRunner/Jobs/GraphQLJob.vb @@ -11,10 +11,7 @@ Public Class GraphQLJob Dim oLogConfig As LogConfig = oJobData.Item("LogConfig") Dim oArgs As Dictionary(Of String, String) = oJobData.Item("Args") Dim oJobArgs = New GraphQLArgs With { - .CertificateFile = oArgs.Item("CertFile"), - .CertificatePassword = oArgs.Item("CertPass"), - .Email = oArgs.Item("Username"), - .Password = oArgs.Item("Password") + .QueryConfigPath = oArgs.Item("QueryConfigFolder") } Dim oGraphQLJob As New Modules.Jobs.GraphQLJob(oLogConfig) diff --git a/Service.JobRunner/My Project/AssemblyInfo.vb b/Service.JobRunner/My Project/AssemblyInfo.vb index 9c9ed951..95c930bb 100644 --- a/Service.JobRunner/My Project/AssemblyInfo.vb +++ b/Service.JobRunner/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/Service.JobRunner/My Project/Settings.Designer.vb b/Service.JobRunner/My Project/Settings.Designer.vb index 81faf3f3..4ed5c023 100644 --- a/Service.JobRunner/My Project/Settings.Designer.vb +++ b/Service.JobRunner/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase @@ -138,9 +138,7 @@ Namespace My _ + Global.System.Configuration.DefaultSettingValueAttribute("False|0 0 0/1 * * ?|QueryConfigFolder::E:\JenneJ\GraphQL")> _ Public ReadOnly Property GRAPHQL_CONFIG() As String Get Return CType(Me("GRAPHQL_CONFIG"),String) diff --git a/Service.JobRunner/My Project/Settings.settings b/Service.JobRunner/My Project/Settings.settings index c9f788c8..98b0505b 100644 --- a/Service.JobRunner/My Project/Settings.settings +++ b/Service.JobRunner/My Project/Settings.settings @@ -30,7 +30,7 @@ True|10/0 * * * * ?|Foo::Bar - False|0 0 0/1 * * ?|CertPath::E:\jonathanjenne.pfx,CertPass::jonathanjenne,Username::j.jenne@digitaldata.works,Password::DigitalData01!,BaseUrl::http://data.api.wisag.de:8090 + False|0 0 0/1 * * ?|QueryConfigFolder::E:\JenneJ\GraphQL \ No newline at end of file