59 lines
2.1 KiB
VB.net
59 lines
2.1 KiB
VB.net
Imports System.IO
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Base
|
|
Imports MultiTool.Common.Templates
|
|
|
|
Namespace Documents
|
|
Public Class DocumentCleaner
|
|
Inherits BaseClass
|
|
|
|
Private ReadOnly Template As Template
|
|
Private ReadOnly FileEx As FilesystemEx
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pTemplate As Template)
|
|
MyBase.New(pLogConfig)
|
|
Template = pTemplate
|
|
FileEx = New FilesystemEx(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()
|
|
|
|
If oImportedDocuments.Count = 0 Then
|
|
Logger.Debug("No exported files found. Skipping.")
|
|
Return True
|
|
End If
|
|
|
|
Logger.Debug("Cleaning [{0}] exported files, moving to [{1}]", oImportedDocuments.Count, oOutputDirectory)
|
|
|
|
Dim oRemovedDocuments As New List(Of Document)
|
|
|
|
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)
|
|
oRemovedDocuments.Add(oDocument)
|
|
|
|
Logger.Debug("File [{0}] successfully moved.", oFileinfo.Name)
|
|
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
|
|
|
|
Logger.Debug("Moved [{0}] files successfully.", oRemovedDocuments.Count)
|
|
|
|
pDocuments = pDocuments.
|
|
Except(oRemovedDocuments).
|
|
ToList()
|
|
|
|
Return oResult
|
|
End Function
|
|
End Class
|
|
End Namespace |