diff --git a/DDMonorepo.sln b/DDMonorepo.sln index c9ee0dfc..8bf0cc42 100644 --- a/DDMonorepo.sln +++ b/DDMonorepo.sln @@ -43,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Licenses", "Licenses", "{59 EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Logging.Test", "Modules.Logging.Test\Logging.Test.vbproj", "{3207D8E7-36E3-4714-9B03-7B5B3D6D351A}" EndProject +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Filesystem.Test", "Filesystem.Test\Filesystem.Test.vbproj", "{D982D755-D587-4574-9841-1E2024DB5F7C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -97,6 +99,10 @@ Global {3207D8E7-36E3-4714-9B03-7B5B3D6D351A}.Debug|Any CPU.Build.0 = Debug|Any CPU {3207D8E7-36E3-4714-9B03-7B5B3D6D351A}.Release|Any CPU.ActiveCfg = Release|Any CPU {3207D8E7-36E3-4714-9B03-7B5B3D6D351A}.Release|Any CPU.Build.0 = Release|Any CPU + {D982D755-D587-4574-9841-1E2024DB5F7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D982D755-D587-4574-9841-1E2024DB5F7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D982D755-D587-4574-9841-1E2024DB5F7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D982D755-D587-4574-9841-1E2024DB5F7C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -114,6 +120,7 @@ Global {3DCD6D1A-C830-4241-B7E4-27430E7EA483} = {F98C0329-C004-417F-B2AB-7466E88D8220} {991D0231-4623-496D-8BD0-9CA906029CBC} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} {3207D8E7-36E3-4714-9B03-7B5B3D6D351A} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} + {D982D755-D587-4574-9841-1E2024DB5F7C} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286} diff --git a/EDMDesigner/FrmMain.vb b/EDMDesigner/FrmMain.vb index a40f81e9..c345b463 100644 --- a/EDMDesigner/FrmMain.vb +++ b/EDMDesigner/FrmMain.vb @@ -56,18 +56,19 @@ Public Class FrmMain End Function Private Sub Init() - _firebird = New Firebird(_logConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword) + Try + _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) - Exit Sub - End If + ' Get info about the logged in user + 'CurrentUser = New ClassCurrentUser(DBFirebird) + + Dim dt As DataTable = LoadTables() + CreateTableNodesFromDatatable(dt, _firebird.DatabaseName) + Catch ex As Exception + MsgBox(ex.Message) + End Try - ' Get info about the logged in user - 'CurrentUser = New ClassCurrentUser(DBFirebird) - Dim dt As DataTable = LoadTables() - CreateTableNodesFromDatatable(dt, _firebird.DatabaseName) End Sub diff --git a/Filesystem.Test/FileContainerTest.vb b/Filesystem.Test/FileContainerTest.vb new file mode 100644 index 00000000..2e6e5f92 --- /dev/null +++ b/Filesystem.Test/FileContainerTest.vb @@ -0,0 +1,146 @@ +Imports System.Text +Imports System.IO +Imports Microsoft.VisualStudio.TestTools.UnitTesting +Imports DigitalData.Modules.Filesystem +Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Filesystem.FileContainer + + Public Class FileContainerTest + + Const PASSWORD = "foobar" + Const FILENAME_VALID = "Textfile.txt" + Const FILENAME_NONEXISTENT = "Nonexistent.txt" + Const CONTAINER_FILE_VALID = "Container.enc" + Const CONTAINER_FILE_NOWRITE = "C:\Windows\System32\Container.enc" + + Private Shared _logger As Logger + Private Shared _logConfig As LogConfig + + + Public Shared Sub Init(ctx As TestContext) + _logConfig = New LogConfig(LogConfig.PathType.CurrentDirectory) + _logger = _logConfig.GetLogger() + + Dim oContents As String = "" + + For oIndex As Integer = 0 To 10000 + oContents = oContents & PASSWORD + Next + + IO.File.WriteAllText(FILENAME_VALID, oContents) + End Sub + + + Public Shared Sub Cleanup() + IO.File.Delete(FILENAME_VALID) + End Sub + + + Public Sub TestCleanup() + IO.File.Delete(CONTAINER_FILE_VALID) + End Sub + + + + Public Sub TestConstructorPasswordNothing() + Dim oContainer = New FileContainer(_logConfig, Nothing) + End Sub + + + Public Sub TestConstructorValidPassword() + Dim oContainer = New FileContainer(_logConfig, "foobar") + End Sub + + + + Public Sub TestAddFileNonExistentFilePath() + Dim oContainer As New FileContainer(_logConfig, PASSWORD) + + oContainer.AddFile(FILENAME_NONEXISTENT) + End Sub + + + + Public Sub TestAddFileNothingFilePath() + Dim oContainer As New FileContainer(_logConfig, PASSWORD) + + oContainer.AddFile(Nothing) + End Sub + + + Public Sub TestAddFileValidFilePath() + Dim oContainer As New FileContainer(_logConfig, PASSWORD) + + oContainer.AddFile(FILENAME_VALID) + End Sub + + + Public Sub TestFilesPropertyCount() + Dim oContainer As New FileContainer(_logConfig, PASSWORD) + + oContainer.AddFile(FILENAME_VALID) + Assert.AreEqual(1, oContainer.Files.Count) + End Sub + + + Public Sub TestFilesPropertyType() + Dim oContainer As New FileContainer(_logConfig, PASSWORD) + + oContainer.AddFile(FILENAME_VALID) + Assert.IsInstanceOfType(oContainer.Files.First(), GetType(FileEntry)) + End Sub + + + + Public Sub TestSaveValidPath() + Dim oContainer As New FileContainer(_logConfig, PASSWORD) + + oContainer.AddFile(FILENAME_VALID) + oContainer.Save(CONTAINER_FILE_VALID) + + Assert.IsTrue(IO.File.Exists(CONTAINER_FILE_VALID)) + End Sub + + + + Public Sub TestSavePathNotWritable() + Dim oContainer As New FileContainer(_logConfig, PASSWORD) + + oContainer.AddFile(FILENAME_VALID) + oContainer.Save(CONTAINER_FILE_NOWRITE) + End Sub + + + Public Sub TestSaveLoadSameContents() + Dim oContainer As FileContainer + Dim oFileContents As String = "dasisteintest" + + ' Test String in Textdatei schreiben + IO.File.WriteAllText(FILENAME_VALID, oFileContents) + + oContainer = New FileContainer(_logConfig, PASSWORD) + ' Textdatei zu einem Container hinzufügen + oContainer.AddFile(FILENAME_VALID) + + ' Container speichern + oContainer.Save(CONTAINER_FILE_VALID) + + Assert.IsTrue(IO.File.Exists(CONTAINER_FILE_VALID)) + + ' Textdatei löschen + IO.File.Delete(FILENAME_VALID) + + oContainer = Nothing + oContainer = New FileContainer(_logConfig, PASSWORD) + ' Container wieder laden + oContainer.Load(CONTAINER_FILE_VALID) + + ' Textdatei-Inhalt aus Container in Textdatei schreiben + IO.File.WriteAllBytes(FILENAME_VALID, oContainer.Files.First().Contents) + + ' Textdatei-Inhalt aus Textdatei lesen + Dim oFileContents2 = IO.File.ReadAllText(FILENAME_VALID) + + Assert.AreEqual(oFileContents, oFileContents2) + End Sub +End Class \ No newline at end of file diff --git a/Filesystem.Test/Filesystem.Test.vbproj b/Filesystem.Test/Filesystem.Test.vbproj new file mode 100644 index 00000000..cf288186 --- /dev/null +++ b/Filesystem.Test/Filesystem.Test.vbproj @@ -0,0 +1,140 @@ + + + + + Debug + AnyCPU + {D982D755-D587-4574-9841-1E2024DB5F7C} + Library + Filesystem.Test + Filesystem.Test + 512 + Windows + v4.6.1 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + true + true + bin\Debug\ + Filesystem.Test.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + pdbonly + false + true + true + bin\Release\ + Filesystem.Test.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + + ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\Modules.Logging\bin\Debug\NLog.dll + + + + + + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + + {991d0231-4623-496d-8bd0-9ca906029cbc} + Filesystem + + + {903b2d7d-3b80-4be9-8713-7447b704e1b0} + Logging + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + + + \ No newline at end of file diff --git a/Filesystem.Test/My Project/Application.Designer.vb b/Filesystem.Test/My Project/Application.Designer.vb new file mode 100644 index 00000000..88dd01c7 --- /dev/null +++ b/Filesystem.Test/My Project/Application.Designer.vb @@ -0,0 +1,13 @@ +'------------------------------------------------------------------------------ +' +' 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 + diff --git a/Filesystem.Test/My Project/Application.myapp b/Filesystem.Test/My Project/Application.myapp new file mode 100644 index 00000000..758895de --- /dev/null +++ b/Filesystem.Test/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + false + false + 0 + true + 0 + 1 + true + diff --git a/Filesystem.Test/My Project/AssemblyInfo.vb b/Filesystem.Test/My Project/AssemblyInfo.vb new file mode 100644 index 00000000..2731f5fa --- /dev/null +++ b/Filesystem.Test/My Project/AssemblyInfo.vb @@ -0,0 +1,18 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + + + + + + + + + + + + +' + + diff --git a/Filesystem.Test/My Project/Resources.Designer.vb b/Filesystem.Test/My Project/Resources.Designer.vb new file mode 100644 index 00000000..81d342eb --- /dev/null +++ b/Filesystem.Test/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("Filesystem.Test.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/Filesystem.Test/My Project/Resources.resx b/Filesystem.Test/My Project/Resources.resx new file mode 100644 index 00000000..af7dbebb --- /dev/null +++ b/Filesystem.Test/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/Filesystem.Test/My Project/Settings.Designer.vb b/Filesystem.Test/My Project/Settings.Designer.vb new file mode 100644 index 00000000..365aec20 --- /dev/null +++ b/Filesystem.Test/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.Filesystem.Test.My.MySettings + Get + Return Global.Filesystem.Test.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/Filesystem.Test/My Project/Settings.settings b/Filesystem.Test/My Project/Settings.settings new file mode 100644 index 00000000..85b890b3 --- /dev/null +++ b/Filesystem.Test/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Filesystem.Test/packages.config b/Filesystem.Test/packages.config new file mode 100644 index 00000000..09089438 --- /dev/null +++ b/Filesystem.Test/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Filesystem/FileContainer.vb b/Filesystem/FileContainer.vb index 7015e7b2..e0319f49 100644 --- a/Filesystem/FileContainer.vb +++ b/Filesystem/FileContainer.vb @@ -57,7 +57,6 @@ Public Class FileContainer End Get End Property - ''' ''' Gibt eine Auflistung der Dateien in Container zurück. ''' @@ -212,7 +211,7 @@ Public Class FileContainer ''' ''' Der Pfad zur Datei, die im Container gespeichert werden soll ''' - Public Sub AddFile(FilePath As String) + Public Function AddFile(FilePath As String) As String Try Dim oFileInfo As New FileInfo(FilePath) @@ -220,14 +219,14 @@ Public Class FileContainer Throw New FileNotFoundException($"{FilePath} is not a valid path.") End If - AddFile(IO.File.ReadAllBytes(FilePath)) + Return AddFileAsByteArray(IO.File.ReadAllBytes(FilePath)) Catch ex As Exception _logger.Error(ex) Throw ex End Try - End Sub + End Function - Public Sub AddFile(FileContents As Byte()) + Public Function AddFileAsByteArray(FileContents As Byte()) As String Try Dim oFileEntry As New FileEntry With { .Contents = FileContents, @@ -235,11 +234,13 @@ Public Class FileContainer } _inner.Files.Add(oFileEntry) + + Return oFileEntry.FileId Catch ex As Exception _logger.Error(ex) Throw ex End Try - End Sub + End Function Public Function GetFile(FileId As String) As FileEntry Return _inner.Files.Where(Function(f) f.FileId = FileId).FirstOrDefault() @@ -260,7 +261,10 @@ Public Class FileContainer End Function Private Sub BytesToFile(Data As Byte(), FilePath As String) - IO.File.WriteAllBytes(FilePath, Data) + Using oSourceStream As New FileStream(FilePath, FileMode.Append, FileAccess.Write, FileShare.None) + oSourceStream.Write(Data, 0, Data.Length) + oSourceStream.Flush() + End Using End Sub Private Function FileToBytes(FilePath As String) As Byte() @@ -277,8 +281,9 @@ Public Class FileContainer End Function Private Async Sub BytesToFileAsync(Data As Byte(), FilePath As String) - Using oSourceStream As New FileStream(FilePath, FileMode.Append, FileAccess.Write, FileShare.None, bufferSize:=4096, useAsync:=True) + Using oSourceStream As New FileStream(FilePath, FileMode.Append, FileAccess.Write, FileShare.None, 4096, True) Await oSourceStream.WriteAsync(Data, 0, Data.Length) + Await oSourceStream.FlushAsync() End Using End Sub End Class