Private Sub fswDocumentDirectoryMonitor_Changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles fswDocumentDirectoryMonitor.Changed
Debug_LogFileChanged(e.FullPath)
End Sub
''' <summary>
''' Logs that a file has changed in the debug log list view.
''' </summary>
''' <param name="pathToFile">The path to the file that was changed.</param>
''' <remarks>
''' Assumes pathToFile is not null.
''' </remarks>
Private Sub Debug_LogFileChanged(ByVal pathToFile As String)
Dim count As Integer = lbMonitorDebug.Items.Count + 1
Dim message As String = String.Format("{0}- {1} Changed {2}", count, DateTime.Now, pathToFile)
lbMonitorDebug.Items.Add(message)
End Sub
Private Sub fswDocumentDirectoryMonitor_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
Debug_LogFileCreated(e.FullPath)
ReturnCreatedFileAfterPrompting(e.FullPath)
End Sub
''' <summary>
''' Logs that a file was created in the debug list box.
''' </summary>
''' <param name="fullPath">The full path to the file.</param>
Private Sub Debug_LogFileCreated(ByVal fullPath As String)
Dim count As Integer = lbMonitorDebug.Items.Count + 1
Dim message As String = String.Format("{0}- {1} Created {2}", count, DateTime.Now, fullPath)
lbMonitorDebug.Items.Add(message)
End Sub
Private Sub ReturnCreatedFileAfterPrompting(ByVal filePath As String)
Dim createdFile As New System.IO.FileInfo(filePath)
Select Case createdFile.Extension.ToLower()
' TODO: [AW] Magic list
Case ".doc", ".docx",
MessageBox.Show(createdFile.ToString)
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
fswDocumentDirectoryMonitor.IncludeSubdirectories = True
Catch ex As Exception
' TODO: [AW] Swallows all exceptions
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
''' <summary>
''' Toggles the state of the file system watcher.
''' </summary>
Private Sub StartMonitorState()
Try
If fswDocumentDirectoryMonitor.Path = "" Then
Dim message As String = "Please choose a directory to monitor"
MessageBox.Show(message)
Exit Sub
End If
fswDocumentDirectoryMonitor.EnableRaisingEvents = True
Catch ex As Exception
' TODO: Swallows all exceptions
' TODO: What errors are expected?
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub