jj: oh my god /o\
This commit is contained in:
6
Jobs/App.config
Normal file
6
Jobs/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
||||
99
Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb
Normal file
99
Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb
Normal file
@@ -0,0 +1,99 @@
|
||||
Imports System.Collections.Generic
|
||||
Imports System.IO
|
||||
Imports System.Linq
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Interfaces
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
|
||||
Public Class ImportZUGFeRDFiles
|
||||
Implements IJob
|
||||
|
||||
Private _logger As Logger
|
||||
Private _logConfig As LogConfig
|
||||
Private _zugferd As ZUGFeRDInterface
|
||||
Private _firebird As Firebird
|
||||
Private _filesystem As Filesystem.File
|
||||
|
||||
Public Class WorkerArgs
|
||||
Public WatchDirectories As List(Of String)
|
||||
Public SuccessDirectory As String
|
||||
Public ErrorDirectory As String
|
||||
Public PropertyMap As Dictionary(Of String, String)
|
||||
|
||||
Public Sub New()
|
||||
WatchDirectories = New List(Of String)
|
||||
SuccessDirectory = Nothing
|
||||
ErrorDirectory = Nothing
|
||||
PropertyMap = New Dictionary(Of String, String)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Firebird As Firebird)
|
||||
_logConfig = LogConfig
|
||||
_logger = LogConfig.GetLogger()
|
||||
_firebird = Firebird
|
||||
_filesystem = New Filesystem.File(_logConfig)
|
||||
_zugferd = New ZUGFeRDInterface(_logConfig)
|
||||
End Sub
|
||||
|
||||
Public Sub Start(Arguments As Object) Implements IJob.Start
|
||||
Dim args As WorkerArgs = Arguments
|
||||
|
||||
_logger.Info("Starting Job {0}", Me.GetType.Name)
|
||||
For Each oPath As String In args.WatchDirectories
|
||||
Dim oDirInfo As New DirectoryInfo(oPath)
|
||||
|
||||
_logger.Info($"Start processing directory {oDirInfo.FullName}")
|
||||
|
||||
If oDirInfo.Exists Then
|
||||
Dim oFiles As List(Of FileInfo) = oDirInfo.GetFiles().ToList()
|
||||
Dim oFileCount = oFiles.Count
|
||||
Dim oCurrentFileCount = 0
|
||||
|
||||
_logger.Info("Found {0} files", oFileCount)
|
||||
|
||||
For Each oFile In oFiles
|
||||
oCurrentFileCount += 1
|
||||
_logger.Info($"({oCurrentFileCount}/{oFileCount}) Start processing file {oFile.Name}")
|
||||
|
||||
Dim oMoveDirectory As String = args.SuccessDirectory
|
||||
Dim oDocument As CrossIndustryDocumentType
|
||||
Dim oValues As New Dictionary(Of String, String)
|
||||
Dim oGuid As String = Path.GetFileNameWithoutExtension(oFile.FullName)
|
||||
|
||||
Try
|
||||
oDocument = _zugferd.ExtractZUGFeRDFile(oFile.FullName)
|
||||
|
||||
For Each mapping In args.PropertyMap
|
||||
Dim propertyValue As String = PropertyValues.GetPropValue(oDocument, mapping.Value)
|
||||
_logger.Info("Mapping Property {0} to value {1}. Will be inserted into column {2}", mapping.Value, propertyValue, mapping.Key)
|
||||
|
||||
' TODO: Check for missing values
|
||||
If String.IsNullOrEmpty(propertyValue) Then
|
||||
Throw New Exception($"Property {mapping.Value} not found or empty.")
|
||||
End If
|
||||
|
||||
oValues.Add(mapping.Key, propertyValue)
|
||||
Next
|
||||
|
||||
' TODO: Insert into scheise
|
||||
|
||||
Catch ex As Exception
|
||||
oMoveDirectory = args.ErrorDirectory
|
||||
_logger.Error(ex)
|
||||
Finally
|
||||
_filesystem.MoveTo(oFile.FullName, oMoveDirectory)
|
||||
_logger.Info("Finished processing file {0}", oFile.Name)
|
||||
End Try
|
||||
Next
|
||||
End If
|
||||
|
||||
_logger.Info("Finished processing directory {0}", oPath)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
End Class
|
||||
68
Jobs/EDMI/ZUGFeRD/PropertyValues.vb
Normal file
68
Jobs/EDMI/ZUGFeRD/PropertyValues.vb
Normal file
@@ -0,0 +1,68 @@
|
||||
Imports System.Reflection
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Public Class PropertyValues
|
||||
Private Shared _indexPattern = "\((\d+)\)"
|
||||
Private Shared _indexRegex As Regex = New Regex(_indexPattern)
|
||||
|
||||
Public Shared Function GetPropValue(Obj As Object, PropertyName As String)
|
||||
Dim oNameParts As String() = PropertyName.Split("."c)
|
||||
Dim oIndexReplaceRegex = "\(\d+\)"
|
||||
|
||||
If IsNothing(Obj) Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
If oNameParts.Length = 1 Then
|
||||
Return Obj.GetType().GetProperty(PropertyName).GetValue(Obj, Nothing)
|
||||
End If
|
||||
|
||||
For Each oPart As String In oNameParts
|
||||
Dim oType As Type = Obj.GetType()
|
||||
Dim oPartName = oPart
|
||||
Dim oIndex As Integer = Nothing
|
||||
Dim oHasIndex As Boolean = HasIndex(oPartName)
|
||||
|
||||
If oHasIndex Then
|
||||
oPartName = StripIndex(oPart)
|
||||
oIndex = GetIndex(oPart)
|
||||
End If
|
||||
|
||||
Dim oInfo As PropertyInfo = oType.GetProperty(oPartName)
|
||||
|
||||
If IsNothing(oInfo) Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Obj = oInfo.GetValue(Obj, Nothing)
|
||||
|
||||
If oHasIndex Then
|
||||
Obj = Obj(0)
|
||||
End If
|
||||
Next
|
||||
|
||||
Return Obj
|
||||
End Function
|
||||
|
||||
Private Shared Function GetIndex(Prop As String) As Integer
|
||||
If Regex.IsMatch(Prop, _indexPattern) Then
|
||||
Dim oMatch = _indexRegex.Match(Prop)
|
||||
Dim oGroup = oMatch.Groups.Item(1)
|
||||
Dim oValue = oGroup.Value
|
||||
|
||||
Return Integer.Parse(oValue)
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Private Shared Function StripIndex(Prop As String) As String
|
||||
Return Regex.Replace(Prop, _indexPattern, "")
|
||||
End Function
|
||||
|
||||
Private Shared Function HasIndex(Prop As String) As Boolean
|
||||
Return Regex.IsMatch(Prop, _indexPattern)
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
3
Jobs/IJob.vb
Normal file
3
Jobs/IJob.vb
Normal file
@@ -0,0 +1,3 @@
|
||||
Public Interface IJob
|
||||
Sub Start(Arguments As Object)
|
||||
End Interface
|
||||
101
Jobs/Jobs.vbproj
Normal file
101
Jobs/Jobs.vbproj
Normal file
@@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{39EC839A-3C30-4922-A41E-6B09D1DDE5C3}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>DigitalData.Modules.Jobs</RootNamespace>
|
||||
<AssemblyName>DigitalData.Modules.Jobs</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Empty</MyType>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>
|
||||
</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>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<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.Database\Database.vbproj">
|
||||
<Project>{EAF0EA75-5FA7-485D-89C7-B2D843B03A96}</Project>
|
||||
<Name>Database</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Modules.Interfaces\Interfaces.vbproj">
|
||||
<Project>{AB6F09BF-E794-4F6A-94BB-C97C0BA84D64}</Project>
|
||||
<Name>Interfaces</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
|
||||
<Project>{903B2D7D-3B80-4BE9-8713-7447B704E1B0}</Project>
|
||||
<Name>Logging</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EDMI\ZUGFeRD\ImportZUGFeRDFiles.vb" />
|
||||
<Compile Include="EDMI\ZUGFeRD\PropertyValues.vb" />
|
||||
<Compile Include="IJob.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
34
Jobs/My Project/AssemblyInfo.vb
Normal file
34
Jobs/My Project/AssemblyInfo.vb
Normal file
@@ -0,0 +1,34 @@
|
||||
Imports System
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
' die einer Assembly zugeordnet sind.
|
||||
|
||||
' Werte der Assemblyattribute überprüfen
|
||||
|
||||
<Assembly: AssemblyTitle("Modules.Jobs")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Jobs")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2018")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
|
||||
<Assembly: Guid("48b3071f-049c-4c84-b272-f197c1db2652")>
|
||||
|
||||
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
'
|
||||
' Hauptversion
|
||||
' Nebenversion
|
||||
' Buildnummer
|
||||
' Revision
|
||||
'
|
||||
' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
4
Jobs/packages.config
Normal file
4
Jobs/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="4.5.11" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user