jj: Update TesTGUI & EDM Designer

This commit is contained in:
Jonathan Jenne 2018-10-08 16:44:01 +02:00
parent bad26b316a
commit fb976bc43a
6 changed files with 48 additions and 215 deletions

View File

@ -1,179 +0,0 @@
Imports NLog
Imports NLog.Config
Imports NLog.Targets
Imports NLog.Targets.Wrappers
Imports NLog.Targets.Wrappers.BufferingTargetWrapperOverflowAction
Imports System.IO
Public Class ClassLogger
Private Const FileNameFormat As String = "${shortdate}-${var:product}.log"
Private Const FileNameFormatDetail As String = "${shortdate}-${var:product}-Detail.log"
Private Const FileNameFormatDebug As String = "${shortdate}-${var:product}-Debug.log"
Private Const TARGET_DEFAULT As String = "default"
Private Const TARGET_DEFAULT_EX As String = "defaultEx"
Private Const TARGET_DETAIL As String = "detail"
Private Const TARGET_DEBUG As String = "debug"
Private Const defaultLogFormat As String = "${longdate}|${level:uppercase=true}|${logger}|${message}"
Private Const exceptionLogFormat As String = "${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=message}|${exception:format=toString}"
Private config As LoggingConfiguration
Private debugOn As Boolean = False
Private ReadOnly failSafePath As String = Path.GetTempPath()
Private ReadOnly basePath As String = failSafePath
Public Enum PathType As Integer
AppData = 0
CurrentDirectory = 1
CustomPath = 2
End Enum
Public LogFile As String
Public Property Debug As Boolean
Get
Return debugOn
End Get
Set(value As Boolean)
If debugOn <> value Then
debugOn = value
If value = True Then
ActivateDebugLog()
Else
DeactivateDebugLog()
End If
End If
End Set
End Property
''' <summary>
''' Initializes a new Logger for a specific "Product"
''' </summary>
''' <param name="product">An name that identifies the Logs</param>
''' <param name="logPath">The basepath to write logs to. Can be AppData, CurrentDirectory or CustomPath.</param>
''' <param name="customLogPath">If `logPath` is set to custom, this defines the custom logPath</param>
Public Sub New(product As String, logPath As PathType, Optional customLogPath As String = Nothing)
If logPath = PathType.AppData Then
Dim appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
basePath = Path.Combine(appDataDir, "Digital Data", product)
ElseIf logPath = PathType.CurrentDirectory Then
basePath = "Log"
Else 'Custom Path
basePath = customLogPath
End If
config = New LoggingConfiguration()
config.Variables("product") = product
config.AddTarget(TARGET_DEFAULT_EX, WrapTargetInBuffered(GetDefaultLogTargetWithExceptions(basePath)))
config.AddTarget(TARGET_DEFAULT, WrapTargetInBuffered(GetDefaultLogTarget(basePath)))
config.AddTarget(TARGET_DETAIL, WrapTargetInBuffered(GetDetailLogTarget(basePath)))
config.AddTarget(TARGET_DEBUG, WrapTargetInBuffered(GetDebugLogTarget(basePath)))
AddDefaultLogTargets()
LogManager.Configuration = config
End Sub
Private Function WrapTargetInBuffered(target As FileTarget) As Target
Dim bufferedWrapper = New BufferingTargetWrapper()
bufferedWrapper.WrappedTarget = target
' Number of log events to be buffered. When the limit is reached,
' then a synchronous flush is performed.
bufferedWrapper.BufferSize = 100
' Action to be taken when the buffer exceeds the set bufferSize.
bufferedWrapper.OverflowAction = Flush
' Timeout (in milliseconds) after a write, until the entire buffer
' is asynchronously flushed. Use -1 to disable timed flushes.
bufferedWrapper.FlushTimeout = 100
Return bufferedWrapper
End Function
Private Sub ActivateDebugLog()
' Clear Logging Rules
config.LoggingRules.Clear()
' Add default targets and debug target
AddDefaultLogTargets()
config.AddRuleForOneLevel(LogLevel.Debug, TARGET_DEBUG)
' Reload all running loggers
LogManager.ReconfigExistingLoggers()
End Sub
Private Sub DeactivateDebugLog()
' Clear Logging Rules
config.LoggingRules.Clear()
' Add default targets
AddDefaultLogTargets()
' Reload all running loggers
LogManager.ReconfigExistingLoggers()
End Sub
Private Sub AddDefaultLogTargets()
config.AddRuleForOneLevel(LogLevel.Error, TARGET_DEFAULT_EX)
config.AddRuleForOneLevel(LogLevel.Fatal, TARGET_DEFAULT_EX)
config.AddRuleForOneLevel(LogLevel.Warn, TARGET_DEFAULT)
config.AddRuleForOneLevel(LogLevel.Info, TARGET_DETAIL)
End Sub
#Region "Log Targets"
Private Function GetDefaultLogTarget(basePath As String) As FileTarget
Dim defaultFilePath As String = Path.Combine(basePath, FileNameFormat)
Dim defaultLog As New FileTarget() With {
.FileName = defaultFilePath,
.Layout = defaultLogFormat,
.MaxArchiveFiles = 30,
.KeepFileOpen = True
}
Return defaultLog
End Function
Private Function GetDefaultLogTargetWithExceptions(basePath As String) As FileTarget
Dim defaultFilePath As String = Path.Combine(basePath, FileNameFormat)
Dim defaultLogWithExceptionData As New FileTarget() With {
.FileName = defaultFilePath,
.Layout = exceptionLogFormat,
.MaxArchiveFiles = 30,
.KeepFileOpen = True
}
Return defaultLogWithExceptionData
End Function
Private Function GetDetailLogTarget(basePath As String) As FileTarget
Dim detailFilePath As String = Path.Combine(basePath, FileNameFormatDetail)
Dim detailLog As New FileTarget() With {
.FileName = detailFilePath,
.Layout = defaultLogFormat,
.MaxArchiveFiles = 1,
.KeepFileOpen = True
}
Return detailLog
End Function
Private Function GetDebugLogTarget(basePath As String) As FileTarget
Dim debugFilePath As String = Path.Combine(basePath, FileNameFormatDebug)
Dim debugLog As New FileTarget() With {
.FileName = debugFilePath,
.Layout = defaultLogFormat,
.MaxArchiveFiles = 1,
.KeepFileOpen = True
}
Return debugLog
End Function
#End Region
End Class

View File

@ -111,7 +111,6 @@
<ItemGroup>
<Compile Include="ClassCurrentUser.vb" />
<Compile Include="ClassInit.vb" />
<Compile Include="ClassLogger.vb" />
<Compile Include="FrmConnection.Designer.vb">
<DependentUpon>FrmConnection.vb</DependentUpon>
</Compile>

View File

@ -1,12 +1,13 @@
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Public Class FrmConnection
Public Property LogFactory As NLog.LogFactory
Public Property LogConfig As LogConfig
Private _logger As NLog.Logger
Private Sub FrmConnection_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_logger = LogFactory.GetCurrentClassLogger()
_logger = LogConfig.GetLogger()
FbDatabaseLocationTextBox.DataBindings.Add("Text", My.Settings, "fbDatabaseLocation")
FbDatasourceTextBox.DataBindings.Add("Text", My.Settings, "fbDatasource")
@ -18,7 +19,7 @@ Public Class FrmConnection
Dim dbTest As Firebird
Try
dbTest = New Firebird(LogFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
dbTest = New Firebird(LogConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
If dbTest.ConnectionFailed Then
MsgBox("Connection failed!", MsgBoxStyle.Information, "Database Connection")

View File

@ -6,7 +6,7 @@ Public Class FrmMain
Private _selectedTable As Integer
Private _selectedTableName As String
Private _logger As NLog.Logger
Private _logger As Logger
Private _logConfig As LogConfig
Private _firebird As Firebird
@ -56,7 +56,7 @@ Public Class FrmMain
End Function
Private Sub Init()
_firebird = New Firebird(_logConfig.LogFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
_firebird = New Firebird(_logConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
If _firebird.ConnectionFailed Then
MsgBox("Database connection failed. Please check the log.", vbCritical)
@ -72,13 +72,25 @@ Public Class FrmMain
End Sub
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
_logConfig = New LogConfig(ClassLogger.PathType.CurrentDirectory)
_logger = _logConfig.LogFactory.GetCurrentClassLogger()
_logConfig = New LogConfig(LogConfig.PathType.CurrentDirectory)
_logger = _logConfig.GetLogger() '_logConfig.LogFactory.GetCurrentClassLogger(GetType(Logger))
_logger.NewBlock("STARTUP")
_logger.Info("INFO")
_logger.Warn("WARN")
_logger.NewBlock("ERROR")
Try
Throw New Exception("ERROR")
Catch ex As Exception
_logger.Error(ex)
End Try
' Check for existing database credentials
While Not DatabaseSettingsExist()
Dim form As New FrmConnection With {
.LogFactory = _logConfig.LogFactory
.LogConfig = _logConfig
}
Dim result As DialogResult = form.ShowDialog()
@ -151,7 +163,7 @@ Public Class FrmMain
End Sub
Private Sub NeueTabelleToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeueTabelleToolStripMenuItem.Click
Dim oForm As New FrmNewTable(_logConfig.LogFactory)
Dim oForm As New FrmNewTable(_logConfig)
oForm.ShowDialog()
Dim oTables As DataTable = LoadTables()

View File

@ -1,24 +1,24 @@
Imports NLog
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Public Class FrmNewTable
Private _logFactory As LogFactory
Private _logConfig As LogConfig
Private _logger As Logger
Private _db As Firebird
Public Sub New(LogFactory As LogFactory)
Public Sub New(LogConfig As LogConfig)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
_logFactory = LogFactory
_logger = _logFactory.GetCurrentClassLogger()
_logConfig = LogConfig
_logger = _logConfig.GetLogger()
End Sub
Private Sub FrmNewTable_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
_db = New Firebird(_logFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
_db = New Firebird(_logConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
Catch ex As Exception
MsgBox("Connection to DB failed!", MsgBoxStyle.Critical)
_logger.Error(ex)

View File

@ -4,19 +4,18 @@ Imports System.ComponentModel
Public Class Form1
Dim MyLogger As LogConfig
Shared Logger As NLog.Logger
Dim Logger As Logger
Protected _windream As Windream
Protected _windream2 As Windream2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim serverName As String = TextBox1.Text
' Windream.vb
'_windream = New Windream("W", True, False)
'_windream2 = New Windream("W", True, False)
' Windream2.vb
Try
_windream2 = New ConnectionBuilder(MyLogger.LogFactory).
_windream2 = New ConnectionBuilder(MyLogger).
WithDriveLetter("W").
WithSessionReconnect().
With64BitSupport().
@ -40,7 +39,7 @@ Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
MyLogger = New LogConfig(LogConfig.PathType.CurrentDirectory, Nothing, "MAIN")
Logger = MyLogger.LogFactory.GetCurrentClassLogger()
Logger = MyLogger.GetLogger()
Dim MySecondLogger = New LogConfig(LogConfig.PathType.CurrentDirectory, Nothing, "MAIN2")
Dim SecondLogger = MySecondLogger.LogFactory.GetCurrentClassLogger()
@ -56,42 +55,43 @@ Public Class Form1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles GetValue.Click
My.Settings.Save()
If IsNothing(_windream) Then
If IsNothing(_windream2) Then
MsgBox("windream initialisieren")
Exit Sub
End If
Dim result As DataTable = _windream.GetValueforIndex(txtWMFile.Text, txtWMIndex.Text)
If result.Rows.Count = 0 Then
Dim result As List(Of String) = _windream2.GetIndexValue(txtWMFile.Text, txtWMIndex.Text)
If result.Count = 0 Then
MsgBox("No result")
Else
txtWMValue.Text = result.Rows(0).Item(0).ToString
txtWMValue.Text = result.Item(0).ToString
End If
End Sub
Private Sub IndexFile_Click(sender As Object, e As EventArgs) Handles IndexFile.Click
My.Settings.Save()
If IsNothing(_windream) Then
If IsNothing(_windream2) Then
MsgBox("windream initialisieren")
Exit Sub
End If
Dim arrValue() As String = Nothing
ReDim Preserve arrValue(0)
arrValue(0) = txtWMValue.Text
If _windream.NewIndexFile(txtWMFile.Text, txtWMIndex.Text, arrValue) = True Then
MsgBox("Success")
Else
MsgBox("no indexing")
End If
'If _windream2.NewIndexFile(txtWMFile.Text, txtWMIndex.Text, arrValue) = True Then
' MsgBox("Success")
'Else
' MsgBox("no indexing")
'End If
End Sub
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
My.Settings.Save()
If IsNothing(_windream) Then
If IsNothing(_windream2) Then
MsgBox("windream initialisieren")
Exit Sub
End If
Dim DTResults As DataTable = _windream.GetSearchDocuments(txtwmsearch.Text, "Dokument-ID")
Dim DTResults As DataTable = _windream2.GetSearchDocuments(txtwmsearch.Text, "Dokument-ID")
If DTResults.Rows.Count > 0 Then
GridControl1.DataSource = DTResults
Else
@ -103,13 +103,13 @@ Public Class Form1
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim items As New List(Of String)
items = _windream.GetChoicelistItems(ComboBox1.Text)
items = _windream2.GetChoiceListItems(ComboBox1.Text)
MsgBox("choicelist items:" & vbNewLine & (String.Join(vbNewLine, items.ToArray)))
End Sub
Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
Dim lists = _windream.GetChoiceLists()
Dim lists = _windream2.GetChoiceLists()
ComboBox1.Items.Clear()