Enhancing Code Quality through UiPath Custom Workflow Analyzer Rules
The Motivation:
In the realm of software development, ensuring the highest quality in our code is paramount. At times, during the meticulous process of reviewing code for a project, we stumble upon certain oversights that could have significant consequences. One such scenario we noticed was the absence of a crucial check in some HTTP requests utilizing the POST method.
Specifically, we observed that in some instances, developers were not verifying whether the expected HTTP status code was returned by the server in response to their POST requests. This seemingly minor omission can have profound implications. Without confirming the status code of a particular HTTP request, we cannot guarantee that the request successfully reached the intended endpoint and was processed as intended.
To address this issue and bolster the robustness of our codebase, we are excited to introduce our custom workflow analyzer. This innovative tool is designed to enforce the inclusion of response status checks in every HTTP request within our projects. By doing so, we aim to significantly enhance the reliability and accountability of our code, ensuring that each request not only reaches its destination but also meets the expected criteria for success.
In this blog post, we’ll delve deeper into the motivation behind our custom workflow analyzer and explore how it can be a game-changer in our development processes. We’ll also highlight the benefits of incorporating response status checks into our HTTP requests and discuss how this simple yet crucial step can elevate the quality and integrity of our code. So, let’s embark on this journey to improve code quality and make our development workflow even more robust with the introduction of our custom analyzer.
Introduction to UiPath Workflow Analyzer:
UiPath Workflow Analyzer is a static code analyzer as part of UiPath Studio that ensures your automation meets best practices and standards. This static code analyzer checks for inconsistencies without actually executing the project, as opposed to dynamic analyzers which step in during execution.
To build custom rules, you need the UiPath.Activities.Api package from the Official feed. The SDK package must be used as a development dependency in your custom project.
Prerequisites:
When building custom rules, target the .NET version depending on the version of Studio and the project compatibility:
- Studio 2021.4 and earlier: .NET Framework 4.6.1.
- Studio 2021.10.6 and later: .NET Framework 4.6.1 for Windows-legacy projects, .NET 6 for Windows and cross-platform projects.
Workflow Analyzer Key Concepts:
1. Rules and Counters
A rule represents a requirement that must be met. It can be set to check the inspection object against the rule definition.
A counter represents a check done for revealing the number of times a particular event or condition has occurred.
2. Inspection Object
There are three different type of Inspection Objects available
- Activity: it is the smallest inspection object. For example, Variables Naming Convention, Variable Length Exceeded, and File Activities Stats are three out-of-the-box rules that can be set to inspect activities.
- Workflow: rules or counters may be set to perform checks in just a single project file. High Arguments Count and Empty Sequence are just two predefined rules that have workflow as their scope.
- Project: checks are performed at the project level, ensuring project reliability is met. Unused Dependencies is a rule applied at the project scope.
Implementation Steps and Demostration:
This project will be responsible to validate/inspect the HTTP request activity object and returning the inspection result based on the logic implemented.
Note: For Demostration purpose, i have implemented only one logical check and it’s outcome is here. Based on your need, you can enhance this implementation or after understanding the key concepts, you can develop a brand new workflow analyzer with relevant scope (Project/ Workflow/ Activity)
Step 1: Create a Class Library project on Visual Studio and name it as in the below inline screenshots. You can choose framework version based on requirement. Recommending .Net 6.0 for Windows compatibility projects
Step 2: Implement the IRegisterAnalyzerConfiguration
interface with the following method Initialize(IAnalyzerConfigurationService workflowAnalyzerConfigService)
. The below inline screenshot contains constants to be used through the project as well alone with Interface implemnentation.
Fig 2.1 IRegisterAnalyzerConfiguration implementationan and constants
Note: This methiod offers an injection point to the implementing assembly in order to access UiPath.Studio.Activities.Api.Analyzer.IAnalyzerConfigurationService capabilities.
Step 3: Create a Static method to build Rule object for specific scope. In this case, scope is set at Activity Level. This static method is already called inside Initialize(IAnalyzerConfigurationService workflowAnalyzerConfigService)
implementation.
Step 4: Building the logic which is responsible for inspect each Activity Object and return the InspectionResult object with relevant properties.
Step 5: Build the project and copy the dll from current project directory to UiPath Workflow Analyzer Rule directory( Ideally C:\Program Files\UiPath\Studio\Rules\net6.0).
Step 6: Close and re-open UiPath Studio to get it reflected on the Workflow Analyzer Window
Step 7: Click on Analize Project and Error List Panel will be showing the inspection result if you are not storing the Response status on a variable.
Note: “By adding extra logic, we can also check whether we used the Response status variable used further in the code to enusre that the HTTP request returns expected status code”
Debugging Workflow Analyzer:
- Once you have compiled your rules into a library, *.dll, copy the dll into the path of UiPath Studio. Usually this is C:\Program Files\UiPath\Studio\Rules\net6.0).
- Open UiPath Studio to a project you wish to analyze.
- Use the debug option in Visual Studio to attach to a process.
4. You should see a process called UiPath.Studio.Analyzer.exe. Select it and click the “Attach” button.
5. At this point you can set a break point in Visual Studio. The rule I am debugging is at the project scope, so use the Analyze Project option in UiPath.
6. The debugger should halt on the break point, allowing your to examine the values of all local variables.
Conclusion:
In the dynamic world of automation, consistency and adherence to best practices are the cornerstones of success. Ensuring that your workflows and automation projects align with industry standards is not just a desirable goal but a critical necessity. UiPath, a leading name in the automation sphere, recognizes this need and provides a powerful tool to make it happen — the UiPath Workflow Analyzer.
Streamlining Your Workflow Standards:
The UiPath Workflow Analyzer is your ally in ensuring that your automation projects consistently adhere to established best practices. It’s your compass for maintaining a high level of quality and uniformity across your automation solutions.
Enforcement with Ease:
The key to unlocking the full potential of the Workflow Analyzer lies in enabling its enforcement. By configuring this feature in the Design Settings of UiPath Studio, you can effortlessly ensure that your projects adhere to best practices automatically. This enforcement can take place during various critical phases, such as Publish, Run, or Check-In, depending on your workflow requirements.
Experience the Benefits:
Enforcing best practices and standards through the UiPath Workflow Analyzer is a game-changer for any automation enthusiast or developer. Here are some compelling reasons to make it an integral part of your automation journey:
Consistency: Say goodbye to inconsistencies and haphazard coding practices. With the Workflow Analyzer, your projects will maintain a uniform and structured approach, regardless of team size or project complexity.
Efficiency: Save valuable time and resources by addressing potential issues early in the development cycle. The Workflow Analyzer identifies and rectifies deviations from best practices, allowing you to focus on creating efficient automation solutions.
Reliability: Automation solutions built with the Workflow Analyzer are inherently more reliable. You can trust that your workflows will consistently meet the standards, reducing the risk of errors and failures.
Embrace Automation Excellence:
Incorporating the UiPath Workflow Analyzer into your development process is a pivotal step toward building automation solutions that are robust, efficient, and reliable. It’s your tool for creating a future where automation consistently delivers excellence.
So, let’s take a proactive approach to elevating the quality of our automation solutions. Enable the UiPath Workflow Analyzer, and together, we’ll embark on a journey of automation excellence. Happy Automation!