Imports System.IO
Imports System.Xml
Imports FPCommon
Public Class Main
Dim _bShowErrors As Boolean
'this class is designed to bubble events up to the calling class
'the calling class can subscribe to the events and display progress
Public Event Status(ByVal StatusText As String)
Sub New(bShowErrors As Boolean)
Try
_bShowErrors = bShowErrors
App.ReadConfigFile("Credit Plus", "DDIntegration.config")
Catch ex As Exception
ErrorHandler.globalErrorHandler(ex, _bShowErrors)
End Try
End Sub
Public Sub Main()
work()
End Sub
Sub work()
Try
Dim strArchiveName As String = ""
Dim intDeleteFilesOrderThanDays As Int16 = App.DeleteFilesOlderThanDays
'get the root directory
Dim strDirectory As String = App.RootDirectory
'the done and error directories will be subdirectories
Dim strDirectoryDone As String = Path.Combine(strDirectory, "done")
Dim strDirectoryError As String = Path.Combine(strDirectory, "error")
'create the sub directories if they do not exist
FileHandler.CreateDirectory(strDirectoryDone)
FileHandler.CreateDirectory(strDirectoryError)
'delete saved documents
FileHandler.DeleteDocumentsByAge(strDirectoryDone, intDeleteFilesOrderThanDays)
'main work loop
Dim oFiles As New DirectoryInfo(strDirectory)
For Each oFile As FileInfo In oFiles.GetFiles("*.*")
Try
'get the 'archivename'
strArchiveName = String.Format("{0}_{1:ddMMyy_hhmmss}{2}", Path.GetFileNameWithoutExtension(oFile.Name), Now, Path.GetExtension(oFile.Name))
'process one document
Process(oFile.Name)
'move the file to done
FileHandler.MoveFile(oFile.FullName, Path.Combine(strDirectoryDone, strArchiveName))
Catch ex As Exception
'it's possible to get an exception in the exception handler
'so we create a list of exceptions
Dim exList As New List(Of Exception)
exList.Add(ex)
Try
File.Move(oFile.FullName, Path.Combine(strDirectoryError, strArchiveName))
Catch ex2 As Exception
exList.Add(ex2)
End Try
ErrorHandler.globalErrorHandler(exList, _bShowErrors)
End Try
Next
Catch ex As Exception
ErrorHandler.globalErrorHandler(ex, _bShowErrors)
End Try
End Sub
Sub Process(ByVal strDocument As String)
Try
'do some work here to process the document
Catch ex As Exception
Throw ex
End Try
End Sub
End Class