jj: Add Tests for Filesystem module, flush on file write in Filesystem

This commit is contained in:
Jonathan Jenne 2018-11-19 16:29:26 +01:00
parent 83a63ff25d
commit 0f105b6ebf
13 changed files with 621 additions and 17 deletions

View File

@ -43,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Licenses", "Licenses", "{59
EndProject EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Logging.Test", "Modules.Logging.Test\Logging.Test.vbproj", "{3207D8E7-36E3-4714-9B03-7B5B3D6D351A}" Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Logging.Test", "Modules.Logging.Test\Logging.Test.vbproj", "{3207D8E7-36E3-4714-9B03-7B5B3D6D351A}"
EndProject EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Filesystem.Test", "Filesystem.Test\Filesystem.Test.vbproj", "{D982D755-D587-4574-9841-1E2024DB5F7C}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{3207D8E7-36E3-4714-9B03-7B5B3D6D351A}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -114,6 +120,7 @@ Global
{3DCD6D1A-C830-4241-B7E4-27430E7EA483} = {F98C0329-C004-417F-B2AB-7466E88D8220} {3DCD6D1A-C830-4241-B7E4-27430E7EA483} = {F98C0329-C004-417F-B2AB-7466E88D8220}
{991D0231-4623-496D-8BD0-9CA906029CBC} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} {991D0231-4623-496D-8BD0-9CA906029CBC} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC}
{3207D8E7-36E3-4714-9B03-7B5B3D6D351A} = {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 EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286} SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286}

View File

@ -56,18 +56,19 @@ Public Class FrmMain
End Function End Function
Private Sub Init() 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 ' Get info about the logged in user
MsgBox("Database connection failed. Please check the log.", vbCritical) 'CurrentUser = New ClassCurrentUser(DBFirebird)
Exit Sub
End If 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 End Sub

View File

@ -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
<TestClass()> 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
<AssemblyInitialize()>
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
<AssemblyCleanup()>
Public Shared Sub Cleanup()
IO.File.Delete(FILENAME_VALID)
End Sub
<TestCleanup()>
Public Sub TestCleanup()
IO.File.Delete(CONTAINER_FILE_VALID)
End Sub
<TestMethod()>
<ExpectedException(GetType(ArgumentNullException))>
Public Sub TestConstructorPasswordNothing()
Dim oContainer = New FileContainer(_logConfig, Nothing)
End Sub
<TestMethod()>
Public Sub TestConstructorValidPassword()
Dim oContainer = New FileContainer(_logConfig, "foobar")
End Sub
<TestMethod()>
<ExpectedException(GetType(FileNotFoundException))>
Public Sub TestAddFileNonExistentFilePath()
Dim oContainer As New FileContainer(_logConfig, PASSWORD)
oContainer.AddFile(FILENAME_NONEXISTENT)
End Sub
<TestMethod()>
<ExpectedException(GetType(ArgumentNullException))>
Public Sub TestAddFileNothingFilePath()
Dim oContainer As New FileContainer(_logConfig, PASSWORD)
oContainer.AddFile(Nothing)
End Sub
<TestMethod()>
Public Sub TestAddFileValidFilePath()
Dim oContainer As New FileContainer(_logConfig, PASSWORD)
oContainer.AddFile(FILENAME_VALID)
End Sub
<TestMethod()>
Public Sub TestFilesPropertyCount()
Dim oContainer As New FileContainer(_logConfig, PASSWORD)
oContainer.AddFile(FILENAME_VALID)
Assert.AreEqual(1, oContainer.Files.Count)
End Sub
<TestMethod()>
Public Sub TestFilesPropertyType()
Dim oContainer As New FileContainer(_logConfig, PASSWORD)
oContainer.AddFile(FILENAME_VALID)
Assert.IsInstanceOfType(oContainer.Files.First(), GetType(FileEntry))
End Sub
<TestMethod()>
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
<TestMethod()>
<ExpectedException(GetType(UnauthorizedAccessException))>
Public Sub TestSavePathNotWritable()
Dim oContainer As New FileContainer(_logConfig, PASSWORD)
oContainer.AddFile(FILENAME_VALID)
oContainer.Save(CONTAINER_FILE_NOWRITE)
End Sub
<TestMethod()>
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

View File

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D982D755-D587-4574-9841-1E2024DB5F7C}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Filesystem.Test</RootNamespace>
<AssemblyName>Filesystem.Test</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>Filesystem.Test.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>Filesystem.Test.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\Modules.Logging\bin\Debug\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
<Import Include="System.Threading.Tasks" />
<Import Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
<ItemGroup>
<Compile Include="FileContainerTest.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Filesystem\Filesystem.vbproj">
<Project>{991d0231-4623-496d-8bd0-9ca906029cbc}</Project>
<Name>Filesystem</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
<Name>Logging</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" />
</Project>

View File

@ -0,0 +1,13 @@
'------------------------------------------------------------------------------
' <auto-generated>
' 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.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>false</MySubMain>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>1</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

View File

@ -0,0 +1,18 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
<Assembly: AssemblyTitle("Filesystem.Test")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("Filesystem.Test")>
<Assembly: AssemblyCopyright("Copyright © 2018")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
<Assembly: Guid("bcf93c0e-40e0-4888-aa19-963e234dc0d1")>
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@ -0,0 +1,62 @@
'------------------------------------------------------------------------------
' <auto-generated>
' 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.
' </auto-generated>
'------------------------------------------------------------------------------
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.
'''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Returns the cached ResourceManager instance used by this class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
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
'''<summary>
''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
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

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,73 @@
'------------------------------------------------------------------------------
' <auto-generated>
' 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.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
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
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
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
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
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

View File

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.2.1" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.2.1" targetFramework="net461" />
</packages>

View File

@ -57,7 +57,6 @@ Public Class FileContainer
End Get End Get
End Property End Property
''' <summary> ''' <summary>
''' Gibt eine Auflistung der Dateien in Container zurück. ''' Gibt eine Auflistung der Dateien in Container zurück.
''' </summary> ''' </summary>
@ -212,7 +211,7 @@ Public Class FileContainer
''' </summary> ''' </summary>
''' <param name="FilePath">Der Pfad zur Datei, die im Container gespeichert werden soll</param> ''' <param name="FilePath">Der Pfad zur Datei, die im Container gespeichert werden soll</param>
''' <exception cref="FileNotFoundException" /> ''' <exception cref="FileNotFoundException" />
Public Sub AddFile(FilePath As String) Public Function AddFile(FilePath As String) As String
Try Try
Dim oFileInfo As New FileInfo(FilePath) Dim oFileInfo As New FileInfo(FilePath)
@ -220,14 +219,14 @@ Public Class FileContainer
Throw New FileNotFoundException($"{FilePath} is not a valid path.") Throw New FileNotFoundException($"{FilePath} is not a valid path.")
End If End If
AddFile(IO.File.ReadAllBytes(FilePath)) Return AddFileAsByteArray(IO.File.ReadAllBytes(FilePath))
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
Throw ex Throw ex
End Try End Try
End Sub End Function
Public Sub AddFile(FileContents As Byte()) Public Function AddFileAsByteArray(FileContents As Byte()) As String
Try Try
Dim oFileEntry As New FileEntry With { Dim oFileEntry As New FileEntry With {
.Contents = FileContents, .Contents = FileContents,
@ -235,11 +234,13 @@ Public Class FileContainer
} }
_inner.Files.Add(oFileEntry) _inner.Files.Add(oFileEntry)
Return oFileEntry.FileId
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
Throw ex Throw ex
End Try End Try
End Sub End Function
Public Function GetFile(FileId As String) As FileEntry Public Function GetFile(FileId As String) As FileEntry
Return _inner.Files.Where(Function(f) f.FileId = FileId).FirstOrDefault() Return _inner.Files.Where(Function(f) f.FileId = FileId).FirstOrDefault()
@ -260,7 +261,10 @@ Public Class FileContainer
End Function End Function
Private Sub BytesToFile(Data As Byte(), FilePath As String) 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 End Sub
Private Function FileToBytes(FilePath As String) As Byte() Private Function FileToBytes(FilePath As String) As Byte()
@ -277,8 +281,9 @@ Public Class FileContainer
End Function End Function
Private Async Sub BytesToFileAsync(Data As Byte(), FilePath As String) 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.WriteAsync(Data, 0, Data.Length)
Await oSourceStream.FlushAsync()
End Using End Using
End Sub End Sub
End Class End Class