40 lines
1.5 KiB
VB.net
40 lines
1.5 KiB
VB.net
Imports System.IO
|
|
Imports DigitalData.Modules.Logging
|
|
Imports MultiTool.Shared.Templates
|
|
|
|
Namespace Documents
|
|
Public Class DocumentCleaner
|
|
Inherits BaseClass
|
|
|
|
Private ReadOnly Template As Template
|
|
Private ReadOnly FileEx As DigitalData.Modules.Filesystem.File
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pTemplate As Template)
|
|
MyBase.New(pLogConfig)
|
|
Template = pTemplate
|
|
FileEx = New DigitalData.Modules.Filesystem.File(LogConfig)
|
|
End Sub
|
|
|
|
Public Function CleanImportedDocuments(pDocuments As List(Of Document)) As Boolean
|
|
Dim oResult = True
|
|
Dim oOutputDirectory = FileEx.CreateDateDirectory(Template.ArchiveDirectory)
|
|
Dim oImportedDocuments = pDocuments.
|
|
Where(Function(doc) doc.Imported = True).
|
|
ToList()
|
|
|
|
For Each oDocument As Document In oImportedDocuments
|
|
Try
|
|
Dim oFileinfo = New FileInfo(oDocument.FullName)
|
|
Dim oDestination = Path.Combine(oOutputDirectory, oFileinfo.Name)
|
|
File.Move(oFileinfo.FullName, oDestination)
|
|
Catch ex As Exception
|
|
Logger.Warn("File [{0}] could not be moved to output directory!", oDocument.FullName)
|
|
Logger.Error(ex)
|
|
oResult = False
|
|
End Try
|
|
Next
|
|
|
|
Return oResult
|
|
End Function
|
|
End Class
|
|
End Namespace |