Skip to content

cleanup and error handler activity#3975

Merged
Maheshkale447 merged 3 commits into
masterfrom
Enhancement/CleanUpActRunset
Oct 28, 2024
Merged

cleanup and error handler activity#3975
Maheshkale447 merged 3 commits into
masterfrom
Enhancement/CleanUpActRunset

Conversation

@AmanPrasad43

@AmanPrasad43 AmanPrasad43 commented Oct 28, 2024

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Enhanced event handling in the Runner Item Page for improved user interactions.
    • Streamlined execution logic in the Ginger Execution Engine to process all activities sequentially without skipping.
  • Bug Fixes

    • Resolved issues related to activity execution flow, ensuring all activities are processed correctly.
  • Refactor

    • Improved code readability and maintainability through simplified type handling and event management.
    • Refactored loading logic for child runner items to enhance type safety and clarity.

@coderabbitai

coderabbitai Bot commented Oct 28, 2024

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve refactoring the RunnerItemPage and GingerExecutionEngine classes to improve type handling, event management, and execution flow. In RunnerItemPage.xaml.cs, the logic for loading child runner items has been simplified using pattern matching and LINQ. Additionally, several new events have been added to enhance interaction. In GingerExecutionEngine.cs, the execution logic has been modified to ensure all activities are processed without skipping, altering the control flow of the RunBusinessFlow method.

Changes

File Path Change Summary
Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs - Updated LoadChildRunnerItems method to use pattern matching for improved type handling.
- Modified the constructor for RunnerItemPage to enhance property binding and event handler registration.
- Added multiple new events for better interaction.
Ginger/GingerCoreNET/Run/GingerExecutionEngine.cs - Removed code that skipped ErrorHandler and CleanUpActivity types in RunBusinessFlow method.
- Updated method signature to include a new parameter for resetting error handler execution flag.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

🐇 In the code we hop and play,
With events and types, we find our way.
No more skips, all flows align,
In the garden of logic, our code will shine!
Let's celebrate with a joyful cheer,
For clarity and order, we hold dear! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
Ginger/GingerCoreNET/Run/GingerExecutionEngine.cs (1)

Let me analyze the findings from the script execution to generate the final response.

Update required: Multiple calls to RunBusinessFlow need the new parameter

Several calls to RunBusinessFlow in test files and implementation code are missing the new doResetErrorHandlerExecutedFlag parameter:

  • GingerCoreNET/RosLynLib/GingerScriptGlobals.cs: Method signature needs update
  • GingerTest/Variable Dependancies/VariableDependancyTest.cs: Missing parameter in two calls
  • GingerCoreNETUnitTest/RunTestslib/GingerRunnerTest.cs: Missing parameter
  • GingerCoreNETUnitTest/RunListeners/ExecutionListenerTest.cs: Missing parameter
  • GingerCoreNETUnitTest/Reports/NewHTMLReportTest.cs: Missing parameter
  • GingerCoreNETUnitTest/RunListeners/RunnerListenerTest.cs: Missing parameter
  • GingerCoreNETUnitTest/GingerRunnerTests/CleanUpActivityTests.cs: Missing parameter in multiple calls
  • GingerCoreNETUnitTest/GingerRunnerTests/ErrorHandlerActivityTest.cs: Missing parameter in multiple calls

The interface IGingerExecutionEngine correctly defines the parameter, but several implementations need to be updated to maintain consistency.

🔗 Analysis chain

Line range hint 2104-2104: Verify all calls to RunBusinessFlow are updated with the new parameter

The method signature of RunBusinessFlow has been updated to include the new parameter bool doResetErrorHandlerExecutedFlag = false. Please ensure that all calls to RunBusinessFlow throughout the codebase are updated accordingly to include this parameter, and that the default value does not introduce any unintended behavior.

Run the following script to identify calls to RunBusinessFlow and verify the correct usage of the new parameter:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to RunBusinessFlow and check for the new parameter.
# Expected result: All calls to RunBusinessFlow include the 'doResetErrorHandlerExecutedFlag' parameter.

rg --type cs --multiline --pcre2 'RunBusinessFlow\(\s*[^\)]*' -A 1

Length of output: 5871

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d5b2cf6 and f35ecdc.

📒 Files selected for processing (2)
  • Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs (3 hunks)
  • Ginger/GingerCoreNET/Run/GingerExecutionEngine.cs (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Codacy Static Code Analysis
Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs

[warning] 190-190: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L190
Remove this commented out code.


[warning] 195-195: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L195
Remove this commented out code.

🔇 Additional comments (4)
Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs (2)

24-24: LGTM: Well-structured event handling with proper memory management.

The implementation follows good practices:

  • Uses WeakEventManager to prevent memory leaks
  • Comprehensive cleanup in ClearBindings
  • Clear event documentation

Also applies to: 31-31, 33-33


209-224: Verify null handling in event handlers.

The code should handle potential null references when accessing properties and methods. Consider adding null checks before accessing:

  • acts collection
  • Context property
  • Event handlers
Ginger/GingerCoreNET/Run/GingerExecutionEngine.cs (2)

Line range hint 2155-2159: Ensure proper handling of doResetErrorHandlerExecutedFlag in RunActivity calls

In the RunBusinessFlow method, the calls to RunActivity now pass the resetErrorHandlerExecutedFlag parameter. Please verify that the resetErrorHandlerExecutedFlag is being used correctly in RunActivity and that it aligns with the intended control flow, especially in scenarios involving error handling and activity retries.


4485-4485: ⚠️ Potential issue

Remove extraneous line 4485~

There is an unnecessary line 4485~ in the code. It appears to be a leftover from code annotations or line numbering. Please remove it to maintain code cleanliness and readability.

Apply this diff to remove the extraneous line:

Likely invalid or redundant comment.

Comment on lines +245 to +248
else if (ItemObject is Activity activity) //.GetType() == typeof(GingerCore.Activity) || ItemObject.GetType() == typeof(CleanUpActivity) || ItemObject.GetType() == typeof(ErrorHandler))
{
GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xStatus, StatusItem.StatusProperty, ItemObject, nameof(Activity.Status), BindingMode.OneWay);
PropertyChangedEventManager.AddHandler(source: ((Activity)ItemObject), handler: RunnerItem_ActivityPropertyChanged, propertyName: allProperties);
PropertyChangedEventManager.AddHandler(source: activity, handler: RunnerItem_ActivityPropertyChanged, propertyName: allProperties);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove inline comment containing old code.

The pattern matching improvement is good, but the inline comment containing the old code should be removed for better readability.

Apply this diff:

- else if (ItemObject is Activity activity) //.GetType() == typeof(GingerCore.Activity) || ItemObject.GetType() == typeof(CleanUpActivity) || ItemObject.GetType() == typeof(ErrorHandler))
+ else if (ItemObject is Activity activity)
📝 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
else if (ItemObject is Activity activity) //.GetType() == typeof(GingerCore.Activity) || ItemObject.GetType() == typeof(CleanUpActivity) || ItemObject.GetType() == typeof(ErrorHandler))
{
GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xStatus, StatusItem.StatusProperty, ItemObject, nameof(Activity.Status), BindingMode.OneWay);
PropertyChangedEventManager.AddHandler(source: ((Activity)ItemObject), handler: RunnerItem_ActivityPropertyChanged, propertyName: allProperties);
PropertyChangedEventManager.AddHandler(source: activity, handler: RunnerItem_ActivityPropertyChanged, propertyName: allProperties);
else if (ItemObject is Activity activity)
{
GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xStatus, StatusItem.StatusProperty, ItemObject, nameof(Activity.Status), BindingMode.OneWay);
PropertyChangedEventManager.AddHandler(source: activity, handler: RunnerItem_ActivityPropertyChanged, propertyName: allProperties);

Comment on lines +187 to +208
else if (ItemObject is Activity activity)
{
IEnumerable<GingerCore.Actions.Act> acts = null;
//Activity activity = null;
//if (ItemObject.GetType() == typeof(Activity))
//{
acts = ((Activity)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
activity = (Activity)ItemObject;
//}

//if (ItemObject.GetType() == typeof(CleanUpActivity))
//{
// acts = ((CleanUpActivity)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
// activity = (CleanUpActivity)ItemObject;
//}

//if (ItemObject.GetType() == typeof(ErrorHandler))
//{
// acts = ((ErrorHandler)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
// activity = (ErrorHandler)ItemObject;
//}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Clean up commented code blocks and simplify type casting.

The code has been improved with pattern matching, but there are a few cleanup items needed:

  1. Remove the commented code blocks as they're no longer needed and add noise.
  2. Remove the redundant cast since we've already pattern matched with is.

Apply this diff to clean up the code:

 else if (ItemObject is Activity activity)
 {
-    IEnumerable<GingerCore.Actions.Act> acts = null;
-    //Activity activity = null;
-    //if (ItemObject.GetType() == typeof(Activity))
-    //{
-        acts = ((Activity)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
-        activity = (Activity)ItemObject;
-    //}
-
-    //if (ItemObject.GetType() == typeof(CleanUpActivity))
-    //{
-    //    acts = ((CleanUpActivity)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
-    //    activity = (CleanUpActivity)ItemObject;
-    //}
-
-    //if (ItemObject.GetType() == typeof(ErrorHandler))
-    //{
-    //    acts = ((ErrorHandler)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
-    //    activity = (ErrorHandler)ItemObject;
-    //}
-
+    var acts = activity.Acts.OfType<GingerCore.Actions.Act>();
     if (acts != null)
     {
📝 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
else if (ItemObject is Activity activity)
{
IEnumerable<GingerCore.Actions.Act> acts = null;
//Activity activity = null;
//if (ItemObject.GetType() == typeof(Activity))
//{
acts = ((Activity)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
activity = (Activity)ItemObject;
//}
//if (ItemObject.GetType() == typeof(CleanUpActivity))
//{
// acts = ((CleanUpActivity)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
// activity = (CleanUpActivity)ItemObject;
//}
//if (ItemObject.GetType() == typeof(ErrorHandler))
//{
// acts = ((ErrorHandler)ItemObject).Acts.OfType<GingerCore.Actions.Act>();
// activity = (ErrorHandler)ItemObject;
//}
else if (ItemObject is Activity activity)
{
var acts = activity.Acts.OfType<GingerCore.Actions.Act>();
if (acts != null)
{
🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis

[warning] 190-190: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L190
Remove this commented out code.


[warning] 195-195: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L195
Remove this commented out code.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f35ecdc and 372104f.

📒 Files selected for processing (1)
  • Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs (3 hunks)
🧰 Additional context used
🪛 GitHub Check: Codacy Static Code Analysis
Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs

[warning] 190-190: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L190
Remove this commented out code.


[warning] 195-195: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L195
Remove this commented out code.

Comment on lines +189 to +205
IEnumerable<GingerCore.Actions.Act> acts = null;
if (acts != null)
{
RunnerItemPage ri = new RunnerItemPage(Runnerobj: act, runnerItemEventHandler: _runnerItemEventHandler);
this.Context.Activity = (Activity)ItemObject;
ri.Context = this.Context;
act.Context = this.Context;
ri.xItemSeparator.Visibility = Visibility.Collapsed;
ri.ItemName = act.Description;
ri.ItemGuid = act.Guid;
ri.xViewRunnerItem.Visibility = Visibility.Visible;
ri.xDetailView.ToolTip = "Expand / Collapse Action";
mItemChilds.Add(ri);

foreach (GingerCore.Actions.Act act in acts)
{
RunnerItemPage ri = new RunnerItemPage(Runnerobj: act, runnerItemEventHandler: _runnerItemEventHandler);
this.Context.Activity = activity;
ri.Context = this.Context;
act.Context = this.Context;
ri.xItemSeparator.Visibility = Visibility.Collapsed;
ri.ItemName = act.Description;
ri.ItemGuid = act.Guid;
ri.xViewRunnerItem.Visibility = Visibility.Visible;
ri.xDetailView.ToolTip = "Expand / Collapse Action";
mItemChilds.Add(ri);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix logic error: acts is always null, causing actions not to load

In the LoadChildRunnerItems method, the variable acts is initialized to null and is not assigned any value before the null check. This means the condition if (acts != null) will always be false, and the subsequent foreach loop will never execute. As a result, the actions associated with the activity will not be loaded.

Apply this diff to fix the issue:

- IEnumerable<GingerCore.Actions.Act> acts = null;
- if (acts != null)
+ var acts = activity.Acts.OfType<GingerCore.Actions.Act>();
+ if (acts.Any())
📝 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
IEnumerable<GingerCore.Actions.Act> acts = null;
if (acts != null)
{
RunnerItemPage ri = new RunnerItemPage(Runnerobj: act, runnerItemEventHandler: _runnerItemEventHandler);
this.Context.Activity = (Activity)ItemObject;
ri.Context = this.Context;
act.Context = this.Context;
ri.xItemSeparator.Visibility = Visibility.Collapsed;
ri.ItemName = act.Description;
ri.ItemGuid = act.Guid;
ri.xViewRunnerItem.Visibility = Visibility.Visible;
ri.xDetailView.ToolTip = "Expand / Collapse Action";
mItemChilds.Add(ri);
foreach (GingerCore.Actions.Act act in acts)
{
RunnerItemPage ri = new RunnerItemPage(Runnerobj: act, runnerItemEventHandler: _runnerItemEventHandler);
this.Context.Activity = activity;
ri.Context = this.Context;
act.Context = this.Context;
ri.xItemSeparator.Visibility = Visibility.Collapsed;
ri.ItemName = act.Description;
ri.ItemGuid = act.Guid;
ri.xViewRunnerItem.Visibility = Visibility.Visible;
ri.xDetailView.ToolTip = "Expand / Collapse Action";
mItemChilds.Add(ri);
}
var acts = activity.Acts.OfType<GingerCore.Actions.Act>();
if (acts.Any())
{
foreach (GingerCore.Actions.Act act in acts)
{
RunnerItemPage ri = new RunnerItemPage(Runnerobj: act, runnerItemEventHandler: _runnerItemEventHandler);
this.Context.Activity = activity;
ri.Context = this.Context;
act.Context = this.Context;
ri.xItemSeparator.Visibility = Visibility.Collapsed;
ri.ItemName = act.Description;
ri.ItemGuid = act.Guid;
ri.xViewRunnerItem.Visibility = Visibility.Visible;
ri.xDetailView.ToolTip = "Expand / Collapse Action";
mItemChilds.Add(ri);
}
🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis

[warning] 190-190: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L190
Remove this commented out code.


[warning] 195-195: Ginger/Ginger/RunSetPageLib/RunnerItemPage.xaml.cs#L195
Remove this commented out code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants