jj
This commit is contained in:
parent
1ed569f7b0
commit
94376068d6
10
EDMI_ClientSuite/ApplicationEvents.vb
Normal file
10
EDMI_ClientSuite/ApplicationEvents.vb
Normal file
@ -0,0 +1,10 @@
|
||||
Namespace My
|
||||
' Für MyApplication sind folgende Ereignisse verfügbar:
|
||||
' Startup: Wird beim Starten der Anwendung noch vor dem Erstellen des Startformulars ausgelöst.
|
||||
' Shutdown: Wird nach dem Schließen aller Anwendungsformulare ausgelöst. Dieses Ereignis wird nicht ausgelöst, wenn die Anwendung mit einem Fehler beendet wird.
|
||||
' UnhandledException: Wird bei einem Ausnahmefehler ausgelöst.
|
||||
' StartupNextInstance: Wird beim Starten einer Einzelinstanzanwendung ausgelöst, wenn die Anwendung bereits aktiv ist.
|
||||
' NetworkAvailabilityChanged: Wird beim Herstellen oder Trennen der Netzwerkverbindung ausgelöst.
|
||||
Partial Friend Class MyApplication
|
||||
End Class
|
||||
End Namespace
|
||||
@ -2,67 +2,39 @@
|
||||
Imports DigitalData.Modules.Logging.LogConfig
|
||||
Imports System.ServiceModel
|
||||
Imports EDMI_ClientSuite.NetworkService_DDEDM
|
||||
Imports System.IO
|
||||
|
||||
|
||||
Public Class ClassInit
|
||||
Private _ChannelFactory As ChannelFactory(Of IEDMServiceChannel)
|
||||
Private _Channel As IEDMServiceChannel
|
||||
Private _Logger As Logger
|
||||
Private _LogConfig As LogConfig
|
||||
|
||||
Private CurrentRetry As Integer = 0
|
||||
|
||||
Private Const MAX_RETRIES = 10
|
||||
Private Const OPEN_TIMEOUT = 10
|
||||
Private Const MAX_MESSAGE_SIZE = 2147483647
|
||||
Private Const MAX_BUFFER_SIZE = 2147483647
|
||||
Private Const MAX_ARRAY_LENGTH = 2147483647
|
||||
Private Const MAX_STRING_LENGTH = 2147483647
|
||||
Private Const MAX_CONNECTIONS = 10000
|
||||
|
||||
Public Property _LogConfig As LogConfig
|
||||
|
||||
Public Sub New()
|
||||
_LogConfig = New LogConfig(PathType.AppData)
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
MyLogger = _Logger
|
||||
MyLogConfig = _LogConfig
|
||||
|
||||
|
||||
_ChannelFactory = ConfigureChannelFactory()
|
||||
_Logger.Debug("Service channelfactory created")
|
||||
|
||||
Connect()
|
||||
End Sub
|
||||
|
||||
Public Function ConfigureChannelFactory()
|
||||
Public Function CreateService() As ChannelFactory(Of IEDMServiceChannel)
|
||||
Return CreateChannelFactory()
|
||||
End Function
|
||||
|
||||
Private Function CreateChannelFactory() As ChannelFactory(Of IEDMServiceChannel)
|
||||
Dim oBinding As New NetTcpBinding()
|
||||
oBinding.Security.Mode = SecurityMode.Transport
|
||||
oBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows
|
||||
oBinding.MaxReceivedMessageSize = 2147483647
|
||||
oBinding.MaxBufferSize = 2147483647
|
||||
oBinding.MaxBufferPoolSize = 2147483647
|
||||
oBinding.MaxConnections = 10000
|
||||
oBinding.ReaderQuotas.MaxArrayLength = 2147483647
|
||||
oBinding.ReaderQuotas.MaxStringContentLength = 2147483647
|
||||
'oBinding.OpenTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT)
|
||||
oBinding.MaxReceivedMessageSize = MAX_MESSAGE_SIZE
|
||||
oBinding.MaxBufferSize = MAX_BUFFER_SIZE
|
||||
oBinding.MaxBufferPoolSize = MAX_BUFFER_SIZE
|
||||
oBinding.MaxConnections = MAX_CONNECTIONS
|
||||
oBinding.ReaderQuotas.MaxArrayLength = MAX_ARRAY_LENGTH
|
||||
oBinding.ReaderQuotas.MaxStringContentLength = MAX_STRING_LENGTH
|
||||
oBinding.OpenTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT)
|
||||
Dim oEndpointAddress = New EndpointAddress(My.Settings.EDM_NetworkService_Adress)
|
||||
|
||||
Return New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpointAddress)
|
||||
End Function
|
||||
|
||||
Private Sub Connect()
|
||||
Try
|
||||
_Channel = _ChannelFactory.CreateChannel()
|
||||
_Logger.Debug("Service channel created")
|
||||
_Logger.Debug("Opening service channel")
|
||||
AddHandler _Channel.Faulted, AddressOf Reconnect
|
||||
_Channel.Open()
|
||||
_Logger.Debug("Service channel opened")
|
||||
_Logger.Info("Connection to service established!")
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Sub
|
||||
Private Sub Reconnect(sender As Object, e As EventArgs)
|
||||
_Logger.Warn("Could not connect to service. Retrying.")
|
||||
_Channel.Abort()
|
||||
|
||||
Connect()
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
@ -164,6 +164,7 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ApplicationEvents.vb" />
|
||||
<Compile Include="ClassInit.vb" />
|
||||
<Compile Include="ClassLayout.vb" />
|
||||
<Compile Include="ClassUtils.vb" />
|
||||
@ -251,6 +252,7 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="MyApplication.vb" />
|
||||
<Compile Include="MyAppSettings.vb" />
|
||||
<Compile Include="Strings\ControlProperties.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
||||
@ -34,5 +34,10 @@ Namespace My
|
||||
Protected Overrides Sub OnCreateMainForm()
|
||||
Me.MainForm = Global.EDMI_ClientSuite.frmMain
|
||||
End Sub
|
||||
|
||||
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
|
||||
Protected Overrides Sub OnCreateSplashScreen()
|
||||
Me.SplashScreen = Global.EDMI_ClientSuite.frmSplash
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@ -6,5 +6,6 @@
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<SplashScreen>frmSplash</SplashScreen>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
||||
@ -1,8 +1,10 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Module MyAppSettings
|
||||
Public APP_DB_VERSION As String
|
||||
|
||||
Public USER_LANGUAGE As String = "de-DE"
|
||||
Public MyLogger As Logger
|
||||
Public MyLogConfig As LogConfig
|
||||
End Module
|
||||
Module MyAppSettings
|
||||
Public APP_DB_VERSION As String
|
||||
|
||||
Public USER_LANGUAGE As String = "de-DE"
|
||||
Public MyLogger As Logger
|
||||
Public MyLogConfig As LogConfig
|
||||
End Module
|
||||
|
||||
|
||||
38
EDMI_ClientSuite/MyApplication.vb
Normal file
38
EDMI_ClientSuite/MyApplication.vb
Normal file
@ -0,0 +1,38 @@
|
||||
Imports System.ServiceModel
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EDMI_ClientSuite.NetworkService_DDEDM
|
||||
|
||||
Namespace My
|
||||
''' <summary>
|
||||
''' Helper Class to hold User State
|
||||
''' </summary>
|
||||
Public Class User
|
||||
Public Username As String
|
||||
Public MachineName As String
|
||||
|
||||
Public Sub New()
|
||||
Username = Environment.UserName
|
||||
MachineName = Environment.MachineName
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
''' <summary>
|
||||
''' Extends the My Namespace
|
||||
''' </summary>
|
||||
<HideModuleName()>
|
||||
Module Extension
|
||||
Property LogConfig As LogConfig
|
||||
Property ChannelFactory As ChannelFactory(Of IEDMServiceChannel)
|
||||
Property Channel As IEDMServiceChannel
|
||||
End Module
|
||||
|
||||
''' <summary>
|
||||
''' Extends the My.Application Namespace
|
||||
''' </summary>
|
||||
Partial Class MyApplication
|
||||
' User Config
|
||||
Public User As New User()
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
|
||||
@ -6,13 +6,6 @@ Imports EDMI_ClientSuite.ClassLayout
|
||||
Imports System.IO
|
||||
|
||||
Public Class frmMain
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
|
||||
Dim oForm As New frmSplash()
|
||||
oForm.ShowDialog()
|
||||
End Sub
|
||||
|
||||
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
LabelCurrentUser.Caption = Environment.UserName
|
||||
LabelCurrentMachine.Caption = Environment.MachineName
|
||||
@ -33,8 +26,8 @@ Public Class frmMain
|
||||
oDataTable.Rows.Add(oRow)
|
||||
|
||||
ProcessManagerOverview.DataSource = oDataTable
|
||||
AddHandler ProcessManagerOverview.RowDoubleClicked, Sub(Row As DataRowView)
|
||||
MsgBox($"Clicked on Document {Row.Row.Item("DocName")}")
|
||||
AddHandler ProcessManagerOverview.RowDoubleClicked, Sub(RowView As DataRowView)
|
||||
MsgBox($"Clicked on Document {RowView.Row.Item("DocName")}")
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
@ -1,44 +1,73 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.Diagnostics
|
||||
Imports System.Threading
|
||||
Imports System.Globalization
|
||||
Imports System.ServiceModel
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Logging.LogConfig
|
||||
Imports EDMI_ClientSuite.NetworkService_DDEDM
|
||||
|
||||
Public NotInheritable Class frmSplash
|
||||
Private InitSteps As Integer = 2
|
||||
Private bw As New BackgroundWorker()
|
||||
Private _Worker As New BackgroundWorker()
|
||||
Private _ChannelFactory As ChannelFactory(Of IEDMServiceChannel)
|
||||
Private _Channel As IEDMServiceChannel
|
||||
Private _Logger As Logger
|
||||
|
||||
Private _CurrentRetry As Integer = 0
|
||||
|
||||
Private Const SLEEP_TIME = 600
|
||||
Private Const INIT_STEPS = 1
|
||||
Private Const MAX_RETRIES = 10
|
||||
Private Const OPEN_TIMEOUT = 10
|
||||
|
||||
Private Sub frmSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
|
||||
lblProductName.Text = My.Application.Info.ProductName
|
||||
lblCopyright.Text = My.Application.Info.Copyright
|
||||
lblVersion.Text = String.Format("Version {0}", My.Application.Info.Version.ToString)
|
||||
|
||||
Me.BringToFront()
|
||||
|
||||
InitProgram()
|
||||
BringToFront()
|
||||
StartWorker()
|
||||
End Sub
|
||||
|
||||
Private Sub InitProgram()
|
||||
bw.WorkerReportsProgress = True
|
||||
AddHandler bw.DoWork, AddressOf bw_DoWork
|
||||
AddHandler bw.ProgressChanged, AddressOf bw_ProgressChanged
|
||||
AddHandler bw.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted
|
||||
|
||||
bw.RunWorkerAsync()
|
||||
End Sub
|
||||
|
||||
Private Function CalcProgress(_step As Integer)
|
||||
Return _step * (100 / InitSteps)
|
||||
Private Function SetProgress(_step As Integer)
|
||||
Return _step * (100 / INIT_STEPS)
|
||||
End Function
|
||||
|
||||
<STAThread()>
|
||||
Private Sub bw_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
|
||||
bw.ReportProgress(CalcProgress(1), "Connecting to service..")
|
||||
Dim Init = New ClassInit()
|
||||
System.Threading.Thread.Sleep(600)
|
||||
Private Sub StartWorker()
|
||||
AddHandler _Worker.DoWork, AddressOf bw_DoWork
|
||||
AddHandler _Worker.ProgressChanged, AddressOf bw_ProgressChanged
|
||||
AddHandler _Worker.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted
|
||||
|
||||
bw.ReportProgress(CalcProgress(2), "Initialize User Settings")
|
||||
' Init.InitUserConfig()
|
||||
System.Threading.Thread.Sleep(600)
|
||||
_Worker.WorkerReportsProgress = True
|
||||
_Worker.RunWorkerAsync()
|
||||
End Sub
|
||||
|
||||
#Region "Worker"
|
||||
Private Sub bw_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
|
||||
Dim oInit As ClassInit
|
||||
|
||||
Try
|
||||
oInit = New ClassInit()
|
||||
My.LogConfig = oInit._LogConfig
|
||||
_Logger = My.LogConfig.GetLogger()
|
||||
Catch ex As Exception
|
||||
Throw New Exception($"Error while initializing Logger: {ex.Message}", ex)
|
||||
End Try
|
||||
|
||||
'------------------
|
||||
_Worker.ReportProgress(SetProgress(1), "Connecting to service..")
|
||||
Try
|
||||
My.ChannelFactory = oInit.CreateService()
|
||||
My.Channel = My.ChannelFactory.CreateChannel()
|
||||
|
||||
AddHandler My.Channel.Faulted, Sub()
|
||||
_Logger.Error("Could not connect to service")
|
||||
Throw New Exception("Could not connect to service")
|
||||
End Sub
|
||||
My.Channel.Open()
|
||||
Catch ex As Exception
|
||||
Throw New Exception($"Error while connectiong to service: {ex.Message}", ex)
|
||||
End Try
|
||||
System.Threading.Thread.Sleep(SLEEP_TIME)
|
||||
|
||||
' TODO: Initialize Usersettings and populate My.Application.User
|
||||
End Sub
|
||||
|
||||
Private Sub bw_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs)
|
||||
@ -50,11 +79,12 @@ Public NotInheritable Class frmSplash
|
||||
' Bei Fehler MsgBox anzeigen und Programm beenden
|
||||
If e.Error IsNot Nothing Then
|
||||
'ClassLogger.Add("Unexpected error in Initializing application....")
|
||||
MsgBox(e.Error.Message, MsgBoxStyle.Critical, "Unexpected error in Initializing application")
|
||||
MsgBox(e.Error.Message, MsgBoxStyle.Critical, "Critical Error")
|
||||
Application.Exit()
|
||||
End If
|
||||
|
||||
' Wenn kein Fehler, Splashscreen schließen
|
||||
Me.Close()
|
||||
End Sub
|
||||
#End Region
|
||||
End Class
|
||||
|
||||
@ -111,6 +111,9 @@ Public Class LogConfig
|
||||
Private Const LOG_FORMAT_EXCEPTION As String = LOG_FORMAT_BASE & " >> ${exception:format=Message}${newline}${exception:format=StackTrace}"
|
||||
Private Const LOG_FORMAT_DEBUG As String = LOG_FORMAT_BASE_LONG_DATE & " >> ${message}"
|
||||
|
||||
Private Const FOLDER_NAME_LOG = "Log"
|
||||
Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt"
|
||||
|
||||
Private ReadOnly failSafePath As String = Path.GetTempPath()
|
||||
Private ReadOnly basePath As String = failSafePath
|
||||
|
||||
@ -167,11 +170,11 @@ Public Class LogConfig
|
||||
|
||||
If logPath = PathType.AppData Then
|
||||
Dim appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||
basePath = Path.Combine(appDataDir, companyName, productName)
|
||||
basePath = Path.Combine(appDataDir, companyName, productName, FOLDER_NAME_LOG)
|
||||
ElseIf logPath = PathType.CurrentDirectory Then
|
||||
Dim currentDirectory As String = My.Application.Info.DirectoryPath
|
||||
|
||||
basePath = Path.Combine(currentDirectory, "Log")
|
||||
basePath = Path.Combine(currentDirectory, FOLDER_NAME_LOG)
|
||||
Else 'Custom Path
|
||||
basePath = customLogPath
|
||||
End If
|
||||
@ -188,7 +191,7 @@ Public Class LogConfig
|
||||
|
||||
' Try to create a file in `basePath` to check write permissions
|
||||
Try
|
||||
Dim fileAccessPath = Path.Combine(basePath, "accessTest.txt")
|
||||
Dim fileAccessPath = Path.Combine(basePath, FILE_NAME_ACCESS_TEST)
|
||||
Using fs As FileStream = File.Create(fileAccessPath)
|
||||
fs.WriteByte(0)
|
||||
End Using
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user