Skip to content

Commit

Permalink
Properly handle failed file processing from FileProcessingQueue tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonQ committed Oct 17, 2017
1 parent 9eb0288 commit bce440f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions FileProcessingQueue.vb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Class FileProcessingQueue

Dim Result As ReturnObject = Nothing
Dim SuccessMessage = ""
Dim FailureMessage = ""

MyFileProcessingInfo.CancelState.Token.ThrowIfCancellationRequested()

Expand All @@ -199,29 +200,35 @@ Class FileProcessingQueue
MyLog.Write(MyFileProcessingInfo.ProcessID, "Processing directory: " & MyFileProcessingInfo.FilePath, Information)
Result = MyFileProcessingInfo.FileParser.DeleteDirectoryInSyncFolder()
SuccessMessage = "Directory deleted:"
FailureMessage = "Directory deletion failed:"
Case Is = FileProcessingInfo.ActionType.Deleted
MyLog.Write(MyFileProcessingInfo.ProcessID, "Processing file: " & MyFileProcessingInfo.FilePath, Information)
Result = MyFileProcessingInfo.FileParser.DeleteInSyncFolder()
SuccessMessage = "File deleted:"
FailureMessage = "File deletion failed:"
Case Is = FileProcessingInfo.ActionType.Renamed
MyLog.Write(MyFileProcessingInfo.ProcessID, "Processing file: " & MyFileProcessingInfo.FilePath, Information)
Result = MyFileProcessingInfo.FileParser.RenameInSyncFolder(MyFileProcessingInfo.OldFilePath)
SuccessMessage = "File processed:"
FailureMessage = "File processing failed:"
Case Is = FileProcessingInfo.ActionType.Created
MyLog.Write(MyFileProcessingInfo.ProcessID, "Processing file: " & MyFileProcessingInfo.FilePath, Information)
Result = MyFileProcessingInfo.FileParser.TransferToSyncFolder()
SuccessMessage = "File processed:"
FailureMessage = "File processing failed:"
Case Is = FileProcessingInfo.ActionType.Changed
MyLog.Write(MyFileProcessingInfo.ProcessID, "Processing file: " & MyFileProcessingInfo.FilePath, Information)
Result = MyFileProcessingInfo.FileParser.DeleteInSyncFolder()
If Result.Success Then Result = MyFileProcessingInfo.FileParser.TransferToSyncFolder()
SuccessMessage = "File processed:"
FailureMessage = "File processing failed:"
End Select

If Result.Success Then
MyFileProcessingInfo.ResultMessages = {SuccessMessage, MyFileProcessingInfo.FilePath.Substring(UserGlobalSyncSettings.SourceDirectory.Length)}
Return New ReturnObject(True, "", MyFileProcessingInfo)
Else
MyFileProcessingInfo.ResultMessages = {FailureMessage, MyFileProcessingInfo.FilePath.Substring(UserGlobalSyncSettings.SourceDirectory.Length)}
Return New ReturnObject(False, Result.ErrorMessage, MyFileProcessingInfo)
End If

Expand Down
10 changes: 7 additions & 3 deletions TrayApp.vb
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,14 @@ Public Class TrayApp
If Not MyFileProcessingInfo.CancelState.IsCancellationRequested Then
Dim ResultStrings As String() = MyFileProcessingInfo.ResultMessages()

If Result.Success AndAlso ResultStrings.Length >= 2 Then
If Tray.Visible Then Tray.ShowBalloonTip(BalloonTime, ResultStrings(0), ResultStrings(1), ToolTipIcon.Info)
If ResultStrings.Length >= 2 Then
If Result.Success Then
If Tray.Visible Then Tray.ShowBalloonTip(BalloonTime, ResultStrings(0), ResultStrings(1), ToolTipIcon.Info)
Else
If Tray.Visible Then Tray.ShowBalloonTip(BalloonTime, ResultStrings(0), ResultStrings(1), ToolTipIcon.Error)
End If
Else
If Tray.Visible Then Tray.ShowBalloonTip(BalloonTime, ResultStrings(0), ResultStrings(1), ToolTipIcon.Error)
If Tray.Visible Then Tray.ShowBalloonTip(BalloonTime, "File processing failed!", Result.ErrorMessage, ToolTipIcon.Error)
End If
End If

Expand Down

0 comments on commit bce440f

Please sign in to comment.