Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handler Report #3998

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region License
#region License
/*
Copyright © 2014-2024 European Support Limited

Expand Down Expand Up @@ -69,6 +69,7 @@ public class ErrorHandler : Activity, IErrorHandler
{
private eHandlerType mHandlerType;
public bool IsSelected { get; set; }
public bool IsAddedToReport { get; set; } = false;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider following existing property patterns and adding documentation

The new IsAddedToReport property deviates from the established patterns in the class:

  1. Missing the [IsSerializedForLocalRepository] attribute that other properties have
  2. No XML documentation explaining its purpose
  3. Different implementation pattern compared to other properties (auto-property vs. backing field)

Consider applying this refactor to maintain consistency:

+        private bool mIsAddedToReport;
+        /// <summary>
+        /// Indicates whether this error handler has been added to the report
+        /// </summary>
+        [IsSerializedForLocalRepository]
+        public bool IsAddedToReport
+        {
+            get { return mIsAddedToReport; }
+            set { if (mIsAddedToReport != value) { mIsAddedToReport = value; OnPropertyChanged(nameof(IsAddedToReport)); } }
+        }
-        public bool IsAddedToReport { get; set; } = false;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public bool IsAddedToReport { get; set; } = false;
private bool mIsAddedToReport;
/// <summary>
/// Indicates whether this error handler has been added to the report
/// </summary>
[IsSerializedForLocalRepository]
public bool IsAddedToReport
{
get { return mIsAddedToReport; }
set { if (mIsAddedToReport != value) { mIsAddedToReport = value; OnPropertyChanged(nameof(IsAddedToReport)); } }
}

[IsSerializedForLocalRepository]
public eHandlerType HandlerType
Expand Down
22 changes: 21 additions & 1 deletion Ginger/GingerCoreNET/Run/GingerExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3997,7 +3997,7 @@ public void RunActivity(Activity activity, bool doContinueRun = false, bool stan
PostScopeVariableHandling(activity.Variables);

NotifyActivityEnd(activity);

CalculateErrorHandlersActivtyEnd(activity);
mLastExecutedActivity = activity;
CurrentBusinessFlow.PreviousActivity = activity;
GiveUserFeedback();
Expand Down Expand Up @@ -5863,5 +5863,25 @@ public void ClearBindings()
CurrentBusinessFlow.PropertyChanged -= CurrentBusinessFlow_PropertyChanged;
}
}

private void CalculateErrorHandlersActivtyEnd(Activity activity)
{

var errorHandlerList = CurrentBusinessFlow.Activities.Where(x => x.GetType() == typeof(ErrorHandler) && x.Status != eRunStatus.Skipped);

foreach (ErrorHandler errActivity in errorHandlerList)
{
if ( activity.EndTimeStamp > errActivity.EndTimeStamp && activity.Status == eRunStatus.Failed && !errActivity.IsAddedToReport)
{
uint evetTime = RunListenerBase.GetEventTime();
foreach (RunListenerBase runnerListener in mRunListeners)
{
runnerListener.ActivityEnd(evetTime, errActivity);
}
errActivity.IsAddedToReport = true;
}
}

}
Comment on lines +5866 to +5885
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Review error handler activity end time calculation logic

The new method has some potential issues:

  1. The LINQ query to filter error handlers could be optimized by combining conditions
  2. The timestamp comparison lacks null checks which could cause NullReferenceException
  3. The method name has a typo ("Activty" instead of "Activity")
  4. The code formatting is inconsistent with extra blank lines

Here's a suggested refactor to address these issues:

-private void CalculateErrorHandlersActivtyEnd(Activity activity)
+private void CalculateErrorHandlerActivityEnd(Activity activity) 
 {
-    var errorHandlerList = CurrentBusinessFlow.Activities.Where(x => x.GetType() == typeof(ErrorHandler) && x.Status != eRunStatus.Skipped);
+    if (activity?.EndTimeStamp == null || activity.Status != eRunStatus.Failed)
+    {
+        return;
+    }

+    var errorHandlerList = CurrentBusinessFlow.Activities
+        .OfType<ErrorHandler>()
+        .Where(x => x.Status != eRunStatus.Skipped && 
+                    x.EndTimeStamp != null && 
+                    !x.IsAddedToReport);

-    foreach (ErrorHandler errActivity in errorHandlerList)
-    {
-        if ( activity.EndTimeStamp > errActivity.EndTimeStamp && activity.Status == eRunStatus.Failed && !errActivity.IsAddedToReport)
-        {
-            uint evetTime = RunListenerBase.GetEventTime();
-            foreach (RunListenerBase runnerListener in mRunListeners)
-            {
-                runnerListener.ActivityEnd(evetTime, errActivity);
-            }
-            errActivity.IsAddedToReport = true;
-        }
-    }
+    foreach (ErrorHandler errHandler in errorHandlerList)
+    {
+        if (activity.EndTimeStamp > errHandler.EndTimeStamp)
+        {
+            uint eventTime = RunListenerBase.GetEventTime();
+            foreach (RunListenerBase runnerListener in mRunListeners)
+            {
+                runnerListener.ActivityEnd(eventTime, errHandler);
+            }
+            errHandler.IsAddedToReport = true;
+        }
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private void CalculateErrorHandlersActivtyEnd(Activity activity)
{
var errorHandlerList = CurrentBusinessFlow.Activities.Where(x => x.GetType() == typeof(ErrorHandler) && x.Status != eRunStatus.Skipped);
foreach (ErrorHandler errActivity in errorHandlerList)
{
if ( activity.EndTimeStamp > errActivity.EndTimeStamp && activity.Status == eRunStatus.Failed && !errActivity.IsAddedToReport)
{
uint evetTime = RunListenerBase.GetEventTime();
foreach (RunListenerBase runnerListener in mRunListeners)
{
runnerListener.ActivityEnd(evetTime, errActivity);
}
errActivity.IsAddedToReport = true;
}
}
}
private void CalculateErrorHandlerActivityEnd(Activity activity)
{
if (activity?.EndTimeStamp == null || activity.Status != eRunStatus.Failed)
{
return;
}
var errorHandlerList = CurrentBusinessFlow.Activities
.OfType<ErrorHandler>()
.Where(x => x.Status != eRunStatus.Skipped &&
x.EndTimeStamp != null &&
!x.IsAddedToReport);
foreach (ErrorHandler errHandler in errorHandlerList)
{
if (activity.EndTimeStamp > errHandler.EndTimeStamp)
{
uint eventTime = RunListenerBase.GetEventTime();
foreach (RunListenerBase runnerListener in mRunListeners)
{
runnerListener.ActivityEnd(eventTime, errHandler);
}
errHandler.IsAddedToReport = true;
}
}
}

}
}
Loading