Skip to content

Commit

Permalink
improved several code analyzer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenwezel committed Nov 7, 2024
1 parent 1814bde commit 2079aeb
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@
<Import Include="System.Windows.Forms" />
</ItemGroup>

<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CompuMaster.TaskManagement\CompuMaster.TaskManagement.vbproj" />
</ItemGroup>
Expand Down
20 changes: 10 additions & 10 deletions CompuMaster.TaskManagement.UI.WinForms/MultiTaskProgessForm.vb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ Public Class MultiTaskProgessForm
With Nothing
Dim ETA = Me.TaskBundle.EstimatedTimeOfArrival
If ETA.HasValue Then
NewFormTitle &= " - ETA: " & ETA.Value.ToString("d\.hh\:mm\:ss")
NewFormTitle &= " - ETA: " & ETA.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture)
Else
Dim ETR = Me.TaskBundle.EstimatedTimeToRun
If ETR.HasValue Then
NewFormTitle &= " - ETA: " & ETR.Value.ToString("d\.hh\:mm\:ss")
NewFormTitle &= " - ETA: " & ETR.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture)
End If
End If
End With
Expand Down Expand Up @@ -146,7 +146,7 @@ Public Class MultiTaskProgessForm
Private Sub UpdateProgressBar(control As ProgressingTaskControl, taskItem As ProgressingTaskItem)
Dim ProgressMaximum As Integer = taskItem.TotalStepsCount * 100
Dim StepProgressValue As Integer = If(taskItem.RunningStep?.EstimatedTimeToRun.HasValue AndAlso taskItem.RunningStep?.ConsumedTime.HasValue, System.Math.Min(100, CInt(taskItem.RunningStep.ConsumedTime.Value.TotalSeconds / taskItem.RunningStep.EstimatedTimeToRun.Value.TotalSeconds * 100)), 0)
Dim StepProgressValueText As String = If(taskItem.RunningStep?.EstimatedTimeToRun.HasValue, " (ca. " & StepProgressValue.ToString() & " %)", "")
Dim StepProgressValueText As String = If(taskItem.RunningStep?.EstimatedTimeToRun.HasValue, " (ca. " & StepProgressValue.ToString(System.Globalization.CultureInfo.InvariantCulture) & " %)", "")
Dim NewProgressValue As Integer = System.Math.Min(ProgressMaximum, taskItem.RunningTotalStepNumber.GetValueOrDefault * 100 + StepProgressValue)
control.Visible = True
control.GroupBox.Text = taskItem.TaskTitle
Expand All @@ -156,21 +156,21 @@ Public Class MultiTaskProgessForm
Case ProgressingTaskItem.ProgressingTaskStatus.NotStarted
control.LabelStepInfo.Text = "Noch nicht gestartet, insgesamt " & taskItem.TotalStepsCount & " Schritte"
If taskItem.EstimatedTimeOfArrival.HasValue Then
control.LabelStepInfo.Text &= System.Environment.NewLine & "ETA: " & taskItem.EstimatedTimeOfArrival.Value.ToString("d\.hh\:mm\:ss") & ""
control.LabelStepInfo.Text &= System.Environment.NewLine & "ETA: " & taskItem.EstimatedTimeOfArrival.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture) & ""
End If
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressInformation)
Case ProgressingTaskItem.ProgressingTaskStatus.InProgress
control.LabelStepInfo.Text = "In Bearbeitung: Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle & StepProgressValueText
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressInformation)
If taskItem.EstimatedTimeOfArrival.HasValue Then
control.LabelStepInfo.Text &= System.Environment.NewLine & "ETA: " & taskItem.EstimatedTimeOfArrival.Value.ToString("d\.hh\:mm\:ss") & ""
control.LabelStepInfo.Text &= System.Environment.NewLine & "ETA: " & taskItem.EstimatedTimeOfArrival.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture) & ""
End If
Case ProgressingTaskItem.ProgressingTaskStatus.FailingInCriticalState
control.LabelStepInfo.Text = "Fehlschlag erkannt, aktuell in Bearbeitung: Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle & StepProgressValueText
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressErrors)
CType(control, ProgressingTaskControl).GroupBox.BackColor = Color.Red
If taskItem.EstimatedTimeOfArrival.HasValue Then
control.LabelStepInfo.Text &= System.Environment.NewLine & "ETA: " & taskItem.EstimatedTimeOfArrival.Value.ToString("d\.hh\:mm\:ss") & ""
control.LabelStepInfo.Text &= System.Environment.NewLine & "ETA: " & taskItem.EstimatedTimeOfArrival.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture) & ""
End If
Case ProgressingTaskItem.ProgressingTaskStatus.FailingWithRollbackOption
control.LabelStepInfo.Text = "Fehlschlag erkannt, aktuell in Bearbeitung: Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle & StepProgressValueText
Expand All @@ -181,17 +181,17 @@ Public Class MultiTaskProgessForm
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressErrors)
CType(control, ProgressingTaskControl).GroupBox.BackColor = Color.Yellow
Case ProgressingTaskItem.ProgressingTaskStatus.Completed
control.LabelStepInfo.Text = "Erfolgreich abgeschlossen in " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss") & " (d.hh:min:sec)"
control.LabelStepInfo.Text = "Erfolgreich abgeschlossen in " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture) & " (d.hh:min:sec)"
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressInformation)
CType(control, ProgressingTaskControl).GroupBox.BackColor = Color.Green
Case ProgressingTaskItem.ProgressingTaskStatus.FailedWithRollbackOption
control.LabelStepInfo.Text = "Fehlgeschlagen nach " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss") & " (d.hh:min:sec): Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle
control.LabelStepInfo.Text = "Fehlgeschlagen nach " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture) & " (d.hh:min:sec): Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressErrors)
CType(control, ProgressingTaskControl).GroupBox.BackColor = Color.Yellow
control.ProgressBar.Value = control.ProgressBar.Maximum 'stops the animation effect
control.ProgressBar.Value = NewProgressValue
Case ProgressingTaskItem.ProgressingTaskStatus.FailedInCriticalState
control.LabelStepInfo.Text = "Fehlgeschlagen nach " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss") & " (d.hh:min:sec): Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle
control.LabelStepInfo.Text = "Fehlgeschlagen nach " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture) & " (d.hh:min:sec): Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressErrors)
CType(control, ProgressingTaskControl).GroupBox.BackColor = Color.Red
control.ProgressBar.Value = control.ProgressBar.Maximum 'stops the animation effect
Expand All @@ -200,7 +200,7 @@ Public Class MultiTaskProgessForm
control.LabelStepInfo.Text = "Übersprungen"
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressInformation)
Case ProgressingTaskItem.ProgressingTaskStatus.Aborted
control.LabelStepInfo.Text = "Abgebrochen nach " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss") & " (d.hh:min:sec): Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle
control.LabelStepInfo.Text = "Abgebrochen nach " & taskItem.ConsumedTime.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture) & " (d.hh:min:sec): Schritt " & taskItem.RunningTotalStepNumber.Value & "/" & taskItem.TotalStepsCount & ": " & taskItem.RunningStep.StepTitle
SetToolTipForTaskControl(control, taskItem.SummaryText, TaskResultToolTipType.ProgressErrors)
CType(control, ProgressingTaskControl).GroupBox.BackColor = Color.Yellow
control.ProgressBar.Value = control.ProgressBar.Maximum 'stops the animation effect
Expand Down
21 changes: 21 additions & 0 deletions CompuMaster.TaskManagement/Exceptions/StepException.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Namespace Exceptions

#Disable Warning CA2237 ' Mark ISerializable types with serializable
#Disable Warning CA1032 ' Implement standard exception constructors
Public Class StepException

#Enable Warning CA1032 ' Implement standard exception constructors
#Enable Warning CA2237 ' Mark ISerializable types with serializable
Inherits System.Exception

Public Sub New(message As String)
MyBase.New(message)
End Sub

Public Sub New(message As String, innerException As Exception)
MyBase.New(message, innerException)
End Sub

End Class

End Namespace
2 changes: 1 addition & 1 deletion CompuMaster.TaskManagement/ProgressingTaskBundle.vb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Public Class ProgressingTaskBundle
Private Async Function RunAllTasksAsync(cancellationToken As Threading.CancellationToken) As Task
' Überprüfung auf doppelte Instanzen (Objektidentität)
Dim duplicates = Tasks.GroupBy(Function(t) t).Where(Function(g) g.Count() > 1).Select(Function(g) g.Key).ToList()
If duplicates.Any() Then
If duplicates.Count <> 0 Then
Throw New InvalidOperationException("Doppelte Instanzen von ProgressingTaskItem in der Aufgabenliste gefunden.")
End If

Expand Down
21 changes: 11 additions & 10 deletions CompuMaster.TaskManagement/ProgressingTaskItem.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Option Strict On

Imports System.Threading
Imports CompuMaster.TaskManagement.ProgressingTaskStepBase
Imports CompuMaster.TaskManagement.Exceptions

Public Class ProgressingTaskItem

Expand Down Expand Up @@ -44,11 +45,11 @@ Public Class ProgressingTaskItem
''' <summary>
''' Must always run (for e.g. rollback tasks), even if previous tasks failed or were cancelled
''' </summary>
RunAlways
RunAlways = 0
''' <summary>
''' Run only if previous tasks completed successfully and no cancellation was requested, otherweise skip
''' </summary>
SkipIfPreviousTasksFailedOrCancelled
SkipIfPreviousTasksFailedOrCancelled = 1
End Enum

''' <summary>
Expand Down Expand Up @@ -178,7 +179,7 @@ Public Class ProgressingTaskItem
''' <returns></returns>
Public Function TotalStepItem(totalStepIndex As Integer) As ProgressingTaskStepBase
If totalStepIndex < 0 OrElse totalStepIndex >= TotalStepsCount Then
Throw New ArgumentOutOfRangeException(NameOf(totalStepIndex), "Argument totalStepIndex=" & totalStepIndex.ToString & ", but allowed range=0.." & TotalStepsCount - 1)
Throw New ArgumentOutOfRangeException(NameOf(totalStepIndex), "Argument totalStepIndex=" & totalStepIndex.ToString(System.Globalization.CultureInfo.InvariantCulture) & ", but allowed range=0.." & TotalStepsCount - 1)
End If
If totalStepIndex < FirstStepsWhichCanBeRolledBack.Count Then
Return FirstStepsWhichCanBeRolledBack(totalStepIndex)
Expand Down Expand Up @@ -247,15 +248,15 @@ Public Class ProgressingTaskItem
Next
Catch ex As Exceptions.UserAbortedMessageException
'Log exception
LoggedExceptions.Add(New Exception("Step " & _RunningStepNumber.Value & " aborted: " & CurrentStep.StepTitle, ex))
LoggedExceptions.Add(New StepException("Step " & _RunningStepNumber.Value & " aborted: " & CurrentStep.StepTitle, ex))
Status = ProgressingTaskItem.ProgressingTaskStatus.Aborting
_EndTime = DateTime.Now

'Rollback
CreateRollbackTaskItemAndAppendToTaskBundle()
Catch ex As Exception
'Log exception
LoggedExceptions.Add(New Exception("Step " & _RunningStepNumber.Value & " failed: " & CurrentStep.StepTitle, ex))
LoggedExceptions.Add(New StepException("Step " & _RunningStepNumber.Value & " failed: " & CurrentStep.StepTitle, ex))
Status = ProgressingTaskItem.ProgressingTaskStatus.FailingWithRollbackOption
_EndTime = DateTime.Now

Expand Down Expand Up @@ -429,9 +430,9 @@ Public Class ProgressingTaskItem
Public Function ConsumedTimeStatisticsInfo(Optional fullLength As Boolean = False) As String
Dim Result As New Text.StringBuilder
Result.AppendLine("Consumed time statistics for task:")
If Me.EstimatedTimeToRun.HasValue Then Result.AppendLine("* Estimated time: " & Me.EstimatedTimeToRun.Value.ToString("d\.hh\:mm\:ss"))
If Me.EstimatedTimeToRun.HasValue Then Result.AppendLine("* Estimated time: " & Me.EstimatedTimeToRun.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture))
'Show consumed time statistics for each step if full length is requested or if there are less than 40 steps
If Me.ConsumedTime.HasValue Then Result.AppendLine("* Consumed time: " & Me.ConsumedTime.Value.ToString("d\.hh\:mm\:ss"))
If Me.ConsumedTime.HasValue Then Result.AppendLine("* Consumed time: " & Me.ConsumedTime.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture))
If Not Me.EstimatedTimeToRun.HasValue AndAlso Not Me.ConsumedTime.HasValue Then Result.AppendLine("* No time information available")

Dim StartIndex As Integer
Expand All @@ -449,8 +450,8 @@ Public Class ProgressingTaskItem
Dim CurrentStep As ProgressingTaskStepBase = Me.TotalStepItem(MyCounter)
Result.AppendLine()
Result.AppendLine("Step " & MyCounter + 1 & ": " & CurrentStep.StepTitle)
If CurrentStep.EstimatedTimeToRun.HasValue Then Result.AppendLine("* Estimated time: " & CurrentStep.EstimatedTimeToRun.Value.ToString("d\.hh\:mm\:ss"))
If CurrentStep.ConsumedTime.HasValue Then Result.AppendLine("* Consumed time: " & CurrentStep.ConsumedTime.Value.ToString("d\.hh\:mm\:ss"))
If CurrentStep.EstimatedTimeToRun.HasValue Then Result.AppendLine("* Estimated time: " & CurrentStep.EstimatedTimeToRun.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture))
If CurrentStep.ConsumedTime.HasValue Then Result.AppendLine("* Consumed time: " & CurrentStep.ConsumedTime.Value.ToString("d\.hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture))
If Not CurrentStep.EstimatedTimeToRun.HasValue AndAlso Not CurrentStep.ConsumedTime.HasValue Then Result.AppendLine("* No time information available")
Next
Return Result.ToString
Expand Down Expand Up @@ -517,7 +518,7 @@ Public Class ProgressingTaskItem
''' Erstellen eines StackTrace ohne die letzte Methode
''' </summary>
''' <returns></returns>
Private Function GetStackTraceWithoutLastMethod() As String
Private Shared Function GetStackTraceWithoutLastMethod() As String
' Holen Sie sich den vollständigen StackTrace
Dim fullStackTrace As String = Environment.StackTrace

Expand Down
7 changes: 4 additions & 3 deletions CompuMaster.TaskManagement/ProgressingTaskStepBase.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Imports CompuMaster.TaskManagement.ProgressingTaskBundle
Imports CompuMaster.TaskManagement.Exceptions

Public MustInherit Class ProgressingTaskStepBase

Expand Down Expand Up @@ -51,7 +52,7 @@ Public MustInherit Class ProgressingTaskStepBase
Me.Status = ProgressingTaskStepStatus.Failed
_EndTime = DateTime.Now
Me.FoundException = ex
Throw New Exception("Fehlgeschlagener Einzelschritt: " & StepTitle, ex)
Throw New StepException("Fehlgeschlagener Einzelschritt: " & StepTitle, ex)
End Try
Case ProgressingTaskStepStatus.InProgress
Throw New InvalidOperationException("This step is already in progress")
Expand Down Expand Up @@ -89,7 +90,7 @@ Public MustInherit Class ProgressingTaskStepBase
Failed = 3
End Enum

Public Status As ProgressingTaskStepStatus = ProgressingTaskStepStatus.NotStarted
Public Property Status As ProgressingTaskStepStatus = ProgressingTaskStepStatus.NotStarted

Public Enum ProgressingTaskStepFailAction
''' <summary>
Expand Down Expand Up @@ -126,7 +127,7 @@ Public MustInherit Class ProgressingTaskStepBase
CollectedWarnings.Add(New ValueTuple(Of String, String)(warning, stacktrace))
End Sub

Private Function GetStackTraceWithoutLastMethod() As String
Private Shared Function GetStackTraceWithoutLastMethod() As String
' Holen Sie sich den vollständigen StackTrace
Dim fullStackTrace As String = Environment.StackTrace

Expand Down
Loading

0 comments on commit 2079aeb

Please sign in to comment.