Add WidigShared Project, seperate all logig into this shared project

This commit is contained in:
Jonathan Jenne
2021-08-02 10:54:43 +02:00
parent 3d55af8502
commit b8250583e1
25 changed files with 955 additions and 790 deletions

View File

@@ -1,16 +0,0 @@
Imports DigitalData.Modules.Config.ConfigAttributes
Public Class ClassConfig
' Global Settings (from computerconfig, overridable by userconfig)
<ConnectionString>
Public Property ConnectionString As String = ""
Public Property WMUsername As String = ""
Public Property WMUserPW As String = ""
Public Property WMDrive As String = ""
Public Property WMRelPath As String = ""
Public Property WMServer As String = ""
Public Property Domain As String = ""
Public Property LOG_DEBUG As Boolean = False
End Class

View File

@@ -1,68 +0,0 @@
Imports System.Security.Cryptography
Public Class ClassEncryption
Private TripleDes As New TripleDESCryptoServiceProvider
Sub New(ByVal key As String)
' Initialize the crypto provider.
TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ 8)
TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ 8)
End Sub
Private Function TruncateHash(
ByVal key As String,
ByVal length As Integer) As Byte()
Dim sha1 As New SHA1CryptoServiceProvider
' Hash the key.
Dim keyBytes() As Byte =
System.Text.Encoding.Unicode.GetBytes(key)
Dim hash() As Byte = sha1.ComputeHash(keyBytes)
' Truncate or pad the hash.
ReDim Preserve hash(length - 1)
Return hash
End Function
Public Function EncryptData(
ByVal plaintext As String) As String
' Convert the plaintext string to a byte array.
Dim plaintextBytes() As Byte =
System.Text.Encoding.Unicode.GetBytes("!Didalog35452Heuchelheim=" & plaintext)
' Create the stream.
Dim ms As New System.IO.MemoryStream
' Create the encoder to write to the stream.
Dim encStream As New CryptoStream(ms,
TripleDes.CreateEncryptor(),
System.Security.Cryptography.CryptoStreamMode.Write)
' Use the crypto stream to write the byte array to the stream.
encStream.Write(plaintextBytes, 0, plaintextBytes.Length)
encStream.FlushFinalBlock()
' Convert the encrypted stream to a printable string.
Return Convert.ToBase64String(ms.ToArray)
End Function
'Entschlüsselt die Zeichenfolge
Public Function DecryptData(
ByVal encryptedtext As String) As String
' Convert the encrypted text string to a byte array.
Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext)
' Create the stream.
Dim ms As New System.IO.MemoryStream
' Create the decoder to write to the stream.
Dim decStream As New CryptoStream(ms,
TripleDes.CreateDecryptor(),
System.Security.Cryptography.CryptoStreamMode.Write)
' Use the crypto stream to write the byte array to the stream.
decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
decStream.FlushFinalBlock()
Dim result = System.Text.Encoding.Unicode.GetString(ms.ToArray)
result = result.Replace("!Didalog35452Heuchelheim=", "")
' Convert the plaintext stream to a string.
Return result
End Function
End Class

View File

@@ -12,7 +12,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("WIDIG")>
<Assembly: AssemblyCopyright("Copyright © 2020")>
<Assembly: AssemblyCopyright("Copyright © 2021")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' indem Sie "*" wie unten gezeigt eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.2.0.0")>
<Assembly: AssemblyVersion("1.3.8.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@@ -1,19 +0,0 @@
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Config
Module Runtime
Public LOGCONFIG As LogConfig
Public LOGGER As Logger
Public WINDREAM As Windream
Public CONFIG As ConfigManager(Of ClassConfig)
Public oMode As String = "IMPV"
Public oErrorParse As Boolean = False
Public oErrorMessage As String
Public oErrorImport As Boolean = True
Public oSourceFile As String
Public oTargetPath As String
Public oWMObjecttype As String
Public oIndexArr As String()
Public WMIndices As List(Of String)
Public OExtension As String
End Module

View File

@@ -58,6 +58,10 @@
<Reference Include="DigitalData.Modules.Config">
<HintPath>..\..\DDMonorepo\Modules.Config\bin\Debug\DigitalData.Modules.Config.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Encryption, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDMonorepo\Encryption\bin\Debug\DigitalData.Modules.Encryption.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Logging">
<HintPath>..\..\DDMonorepo\Modules.Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
</Reference>
@@ -68,10 +72,6 @@
<HintPath>..\..\DDMonorepo\Modules.Windream\bin\Debug\Interop.WINDREAMLib.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Interop.WMOBRWSLib">
<HintPath>..\..\..\Interop.WMOBRWSLib.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.0\lib\net45\NLog.dll</HintPath>
@@ -106,8 +106,6 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="ClassConfig.vb" />
<Compile Include="ClassEncryption.vb" />
<Compile Include="frmMain.vb">
<SubType>Form</SubType>
</Compile>
@@ -130,7 +128,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Runtime.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="frmMain.resx">
@@ -160,5 +157,11 @@
<ItemGroup>
<Content Include="filedownload.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WiDigShared\WiDigShared.vbproj">
<Project>{a5d032d4-abdc-44bf-8666-5fbe42af0ab7}</Project>
<Name>WiDigShared</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>

View File

@@ -1,221 +1,111 @@
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Config
Imports DigitalData.GUIs.WiDigShared
Imports DigitalData.Modules.Encryption
Public Class frmMain
Private _ArgumentLength As Integer
Private LogConfig As LogConfig
Private Logger As Logger
Private Config As ConfigManager(Of ClassConfig)
Private WiDig As ClassWIDig
Private Windream As Windream
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Me.Hide()
Me.Visible = False
Dim oLogConfig As New LogConfig(LogConfig.PathType.AppData, Nothing, "Form", "Digital Data", "WIDig")
LOGCONFIG = oLogConfig
LOGGER = LOGCONFIG.GetLogger
InitUserConfig()
LOGCONFIG.Debug = CONFIG.Config.LOG_DEBUG
LOGGER = LOGCONFIG.GetLogger
Dim oUserPW = GetUserPWPlain()
LOGGER.Debug("Initializing MainForm....")
Me.txtPW.Text = oUserPW
LogConfig = oLogConfig
Logger = LogConfig.GetLogger
If Connect2Windream(oUserPW) = True Then
Config = New ConfigManager(Of ClassConfig)(LogConfig, ClassWIDig.GetAppDataPath, ClassWIDig.GetAppDataPath)
LogConfig.Debug = Config.Config.LOG_DEBUG
Logger = LogConfig.GetLogger
Logger.Debug("Initializing MainForm....")
WiDig = New ClassWIDig(LogConfig, Config.Config)
Dim oUserPW = WiDig.GetUserPWPlain()
Me.txtPW.Text = oUserPW
If WiDig.Connect2Windream(oUserPW) = True Then
Dim oArguments As String() = Environment.GetCommandLineArgs()
If ParseArgs(oArguments) = True Then
If StreamIndexFile() = True Then
oErrorImport = False
If WiDig.ParseArgs(oArguments) = True Then
If WiDig.StreamORIndexFile() = True Then
WiDig.ErrorWhileImporting = False
Else
oErrorImport = True
WiDig.ErrorWhileImporting = True
End If
Else
BarStaticinfo.Caption = $"Error in ParseArgs - {Now.ToString}"
BarStaticinfo.ItemAppearance.Normal.BackColor = Color.Red
End If
Else
oErrorMessage = "Could not initialize windream"
WiDig.ErrorMessage = "Could not initialize windream"
End If
txtUser.Text = CONFIG.Config.WMUsername
txtUser.Text = Config.Config.WMUsername
Me.txtPW.Text = oUserPW
txtWMDrive.Text = CONFIG.Config.WMDrive
txtWMRelpath.Text = CONFIG.Config.WMRelPath
txtWMServer.Text = CONFIG.Config.WMUserPW
txtDomain.Text = CONFIG.Config.Domain
txtWMDrive.Text = Config.Config.WMDrive
txtWMRelpath.Text = Config.Config.WMRelPath
txtWMServer.Text = Config.Config.WMUserPW
txtDomain.Text = Config.Config.Domain
'txtCommands.Text = CONFIG.Config.Arguments
txtCommands.Text = My.Settings.TestParams
If oErrorParse = True Then
MsgBox("Error in Parsing or Indexing!", MsgBoxStyle.Critical)
If WiDig.ErrorWhileParsing = True Then
MsgBox("Error in Parsing or Indexing!", MsgBoxStyle.Critical, Text)
Me.Visible = True
End If
Catch ex As Exception
LOGGER.Error(ex)
MsgBox("Error while initializing: " & vbNewLine & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text)
Logger.Error(ex)
End Try
End Sub
Public Sub InitUserConfig()
Dim oProgramDataPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Digital Data", "WIDig")
Dim oUserAppDataPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Digital Data", "WIDig")
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, oUserAppDataPath, oProgramDataPath)
End Sub
Private Function Connect2Windream(oPW As String)
Try
WINDREAM = New Windream(LOGCONFIG, False, CONFIG.Config.WMDrive, CONFIG.Config.WMRelPath, True, CONFIG.Config.WMServer, CONFIG.Config.WMUsername, oPW, CONFIG.Config.Domain)
If Not IsNothing(WINDREAM) Then
If WINDREAM.SessionLoggedin = True Then
LOGGER.Debug("windream initialisiert")
bsiWMConnect.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
Return True
End If
End If
Catch ex As Exception
LOGGER.Warn("CHECKING WMConnectivity: " & ex.Message)
Return False
End Try
End Function
Private Function GetUserPWPlain()
Try
Dim PWplainText As String
Dim wrapper As New ClassEncryption("!35452didalog=")
If CONFIG.Config.WMUserPW = String.Empty Then
PWplainText = ""
Else
PWplainText = wrapper.DecryptData(CONFIG.Config.WMUserPW)
End If
Return PWplainText
Catch ex As Exception
LOGGER.Warn("Error in GetUserPWPlain - the password [" & CONFIG.Config.WMUserPW & "] could not be decrypted", False)
Return String.Empty
End Try
End Function
Public Function ParseArgs(pArguments As String(), Optional pTest As Boolean = False)
Try
If pArguments.Length <= 3 Then
_ArgumentLength = pArguments.Length
LOGGER.Warn($"Insufficient number of arguments [{pArguments.Length}]!")
BarStaticinfo.Caption = $"Insufficient number of arguments - {Now.ToString}"
oErrorMessage = BarStaticinfo.Caption
BarStaticinfo.ItemAppearance.Normal.BackColor = Color.Red
oErrorParse = True
Return False
End If
Dim ocount As Integer = 0
For Each oArg As String In pArguments
LOGGER.Debug($"[{ocount}] {oArg}")
oArg = oArg.Replace("""", "")
If oArg.StartsWith("-Source@") Then
oSourceFile = oArg.Replace("-Source@", "")
If System.IO.File.Exists(oSourceFile) = False Then
LOGGER.Warn($"Parser@Sourcefile - File [{oSourceFile}] is not existing!")
oErrorMessage &= vbNewLine & $"Parser@Sourcefile - File [{oSourceFile}] is not existing!"
oErrorParse = True
Return False
End If
ElseIf oArg.StartsWith("-Mode@") Then
oMode = oArg.Replace("-Mode@", "").ToUpper
ElseIf oArg.StartsWith("-Target@") Then
oTargetPath = oArg.Replace("-Target@", "")
Dim oWMFolder = System.IO.Path.GetDirectoryName(oTargetPath)
Dim oWindowsPath = oTargetPath
OExtension = IO.Path.GetExtension(oWindowsPath)
Dim oNormalizePath = WINDREAM.GetNormalizedPath(oTargetPath)
If WINDREAM.TestFileExists(oTargetPath) = False Then
LOGGER.Info($"WMFile [{oTargetPath}] not existing!")
End If
If oMode = "IMPV" Then
Dim oWMCheckPath = WINDREAM.VersionWMFilename(oTargetPath, System.IO.Path.GetExtension(oTargetPath))
If oNormalizePath.ToUpper <> oWMCheckPath.ToString.ToUpper Then
LOGGER.Info($"Target [{oNormalizePath}] already existed!! - NewWMFilename [{oWMCheckPath}]")
oTargetPath = oWMCheckPath
End If
End If
ElseIf oArg.StartsWith("-WMOT@") Then
oWMObjecttype = oArg.Replace("-WMOT@", "")
Dim oexists As Boolean = False
Dim myWMOTypes = WINDREAM.ObjectTypes
For Each otype As String In myWMOTypes
If oWMObjecttype = otype Then
oexists = True
Exit For
End If
Next
If oexists = False Then
LOGGER.Info($"WMObjekttype [{oWMObjecttype}] not existing!!")
oErrorMessage &= vbNewLine & $"WMObjekttype [{oWMObjecttype}] not existing!!"
Return False
oErrorParse = True
Else
WMIndices = WINDREAM.GetIndiciesByObjecttype(oWMObjecttype)
End If
ElseIf oArg.StartsWith("-index@") Then
Dim oINDEXInfotemp = oArg
oINDEXInfotemp = oINDEXInfotemp.Replace("-index@{", "")
oINDEXInfotemp = oINDEXInfotemp.Replace("}", "")
Dim oSplit() = oINDEXInfotemp.ToString.Split(";")
LOGGER.Debug($" [{oSplit.Length}] Indices transmitted...")
oIndexArr = oSplit
End If
ocount += 1
Next
Return True
Catch ex As Exception
LOGGER.Warn("Error in ParseArgs:" & vbNewLine & ex.Message)
oErrorMessage &= vbNewLine & "Error in ParseArgs:" & vbNewLine & ex.Message
oErrorParse = True
BarStaticinfo.Caption = $"Error in ParseArgs - {Now.ToString}"
BarStaticinfo.ItemAppearance.Normal.BackColor = Color.Red
Return False
End Try
End Function
Private Function WMIndex_exists(pIndex As String)
Dim oexist As Boolean = False
For Each oWMIndex As String In WMIndices
If oWMIndex = pIndex Then
Return True
End If
Next
Return oexist
End Function
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
If oErrorImport = False Then
If WiDig?.ErrorWhileImporting = False Then
Me.Close()
End If
If oErrorParse = True And _ArgumentLength <> 1 Then
MsgBox("A unexpected error occured while Parsing arguments!" & vbNewLine & oErrorMessage, MsgBoxStyle.Critical)
Process.Start(LOGCONFIG.LogDirectory)
If WiDig?.ErrorWhileParsing = True And Environment.GetCommandLineArgs().Length <> 1 Then
MsgBox("A unexpected error occured while Parsing arguments!" & vbNewLine & WiDig?.ErrorMessage, MsgBoxStyle.Critical)
Process.Start(LogConfig.LogDirectory)
End If
If oErrorImport = True Then
MsgBox("A unexpected error occured while initializing!" & vbNewLine & oErrorMessage, MsgBoxStyle.Critical)
If WiDig?.ErrorWhileImporting = True Then
MsgBox("A unexpected error occured while initializing!" & vbNewLine & WiDig?.ErrorMessage, MsgBoxStyle.Critical)
End If
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Dim wrapper As New ClassEncryption("!35452didalog=")
Dim wrapper As New EncryptionLegacy("!35452didalog=")
Dim cipherText As String = wrapper.EncryptData(Me.txtPW.Text)
Dim pw As String = cipherText
CONFIG.Config.WMUserPW = pw
Config.Config.WMUserPW = pw
CONFIG.Config.WMUsername = txtUser.Text
CONFIG.Config.WMDrive = txtWMDrive.Text
CONFIG.Config.WMRelPath = txtWMRelpath.Text
CONFIG.Config.WMServer = txtWMServer.Text
CONFIG.Config.Domain = txtDomain.Text
CONFIG.Save()
Config.Config.WMUsername = txtUser.Text
Config.Config.WMDrive = txtWMDrive.Text
Config.Config.WMRelPath = txtWMRelpath.Text
Config.Config.WMServer = txtWMServer.Text
Config.Config.Domain = txtDomain.Text
Config.Save()
BarStaticinfo.Caption = $"WM-Settings saved - {Now.ToString}"
BarStaticinfo.ItemAppearance.Normal.BackColor = Color.Lime
End Sub
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
WINDREAM = New Windream(LOGCONFIG, False, txtWMDrive.Text, txtWMRelpath.Text, True, txtWMServer.Text, txtUser.Text, txtPW.Text, txtDomain.Text)
If Not IsNothing(WINDREAM) Then
Windream = New Windream(LogConfig, False, txtWMDrive.Text, txtWMRelpath.Text, True, txtWMServer.Text, txtUser.Text, txtPW.Text, txtDomain.Text)
If Not IsNothing(Windream) Then
MsgBox("Windream-Connext successfull!", MsgBoxStyle.Information)
End If
End Sub
@@ -228,7 +118,7 @@ Public Class frmMain
RibbonPageGroup1.Enabled = False
End Sub
Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick
Process.Start(LOGCONFIG.LogDirectory)
Process.Start(LogConfig.LogDirectory)
End Sub
Private Sub BarButtonItem5_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem5.ItemClick
@@ -237,85 +127,30 @@ Public Class frmMain
'CONFIG.Config.Arguments = txtCommands.Text
'CONFIG.Save()
Dim oArgs() As String = txtCommands.Text.Split("|")
LOGGER.Debug($"[{oArgs.Length}] Arguments will be checked...")
If IsNothing(WINDREAM) Then
Dim oUserPW = GetUserPWPlain()
Logger.Debug($"[{oArgs.Length}] Arguments will be checked...")
If IsNothing(Windream) Then
Dim oUserPW = WiDig.GetUserPWPlain()
If Connect2Windream(oUserPW) = False Then
If WiDig.Connect2Windream(oUserPW) = False Then
MsgBox("Windream could not be initialized!! Check Your log!", MsgBoxStyle.Critical)
Exit Sub
End If
End If
If ParseArgs(oArgs) = False Then
If WiDig.ParseArgs(oArgs) = False Then
MsgBox("An unexpected error occured while parsing arguments. Check the log!", MsgBoxStyle.Critical)
Process.Start(LOGCONFIG.LogDirectory)
Process.Start(LogConfig.LogDirectory)
Else
If StreamIndexFile() = True Then
If WiDig.StreamORIndexFile() = True Then
MsgBox("Import succeeded!", MsgBoxStyle.Information)
Else
MsgBox("Unexpected Error while streaming or indexing WMFile! Check the logfile!", MsgBoxStyle.Critical)
Process.Start(LOGCONFIG.LogDirectory)
Process.Start(LogConfig.LogDirectory)
End If
End If
End Sub
Public Function StreamIndexFile()
Try
'Checks and creates the path if necessary
WINDREAM.NewFolder(oTargetPath, oExtension)
Dim oResult As Boolean = False
If oMode = "IMPV" Then
oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath)
ElseIf oMode = "IMPO" Then
Dim oDeleted = WINDREAM.RemoveFile(oTargetPath)
If oDeleted = True Then
oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath)
Else
LOGGER.Warn($"Mode ImportOverwrite is active - but WMFile could not be deleted!!")
End If
ElseIf oMode = "NI" Then
oResult = True
End If
If oResult = True Then
LOGGER.Info($"File successfully streamed to windream [{oTargetPath}]! Now indexing...")
For Each oIndex2 As String In oIndexArr
Dim oIndexInfo() = oIndex2.Split("=")
Dim oIndexName = oIndexInfo(0)
Dim oIndexvalue = oIndexInfo(1)
If WMIndex_exists(oIndexName) = True Then
LOGGER.Info($"Setting Index: oIndexName [{oIndexName}] - oIndexvalue [{oIndexvalue}]")
If WINDREAM.SetFileIndex(oTargetPath, oIndexName, oIndexvalue, oWMObjecttype) = False Then
LOGGER.Info($"Index could not be set...")
If WINDREAM.RemoveFile(oTargetPath) = True Then
LOGGER.Info($"File deleted after error!")
End If
oResult = False
Exit For
End If
Else
LOGGER.Warn($"Transmitted index with name [{oIndexName}] is not existing in WM Objecttype!")
If WINDREAM.RemoveFile(oTargetPath) = True Then
LOGGER.Info($"File deleted after error!")
End If
oResult = False
Exit For
End If
Next
If oResult = True Then
LOGGER.Info("Import finished!")
oErrorImport = False
End If
End If
Return oResult
Catch ex As Exception
LOGGER.Warn($"Error while indexing: {ex.Message}")
End Try
End Function
Private Sub txtCommands_GotFocus(sender As Object, e As EventArgs) Handles txtCommands.GotFocus
RibbonPageGroup3.Enabled = True
End Sub
@@ -324,10 +159,6 @@ Public Class frmMain
RibbonPageGroup3.Enabled = False
End Sub
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub GroupBox2_Enter(sender As Object, e As EventArgs) Handles GroupBox2.Enter
RibbonPageGroup3.Enabled = False
End Sub