Skip to content

Commit 51f6a01

Browse files
committed
Review
1 parent 253269a commit 51f6a01

1 file changed

Lines changed: 48 additions & 21 deletions

File tree

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/csharp/extensibility-api-howtos/create-microflows-calculations.md

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ weight: 8
77

88
## Introduction
99

10-
This how-to describes how you can create microflows which perform some calculations and return the result.
10+
This how-to describes how to create microflows that perform calculations and return the result.
1111

12-
You can download the example in this how-to in [this GitHub repository](https://github.com/mendix/ExtensionAPI-Samples).
12+
You can download the example in this how-to from [this GitHub repository](https://github.com/mendix/ExtensionAPI-Samples).
1313

14-
## Creating an Extension Class that Creates Microflows
14+
## Creating an Extension Class That Creates Microflows
1515

16-
1. Open the project that you previously created when you [created a menu extension](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
17-
2. Add a new folder *MicroflowTutorial* to your solution.
16+
1. Open the project you created when following [Create a Menu Extension](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
17+
2. Add a new folder named *MicroflowTutorial* to your solution.
1818
3. Create a `MenuExtension` class.
19-
4. Add a new class to the project and call it `CreateMicroflowsMenu.cs`.
20-
5. Replace the code in the file with the code below.
19+
4. Add a new class named `CreateMicroflowsMenu.cs`.
20+
5. Replace the code in the file with the code below:
2121

2222
```csharp
2323
using Mendix.StudioPro.ExtensionsAPI.UI.Menu;
@@ -43,11 +43,14 @@ You can download the example in this how-to in [this GitHub repository](https://
4343
}
4444
```
4545

46-
As you can see, the `GetMenus` method is overridden to add your own menus to Studio Pro. The class `CalculationsMicroflowCreator` (which you will add shortly) will be called from the action of your menu. You can see that this class has been injected in the constructor of your menu extension.
46+
The code overrides the `GetMenus` method to add your custom menus into Studio Pro. The `CalculationsMicroflowCreator` class (added in the next step) is injected via the constructor and triggered by the menu action.
4747

48-
## Microflow Creator
48+
## Add the Microflow Creator Class
4949

50-
In this section, you will add the class `CalculationsMicroflowCreator.cs`, which will be injected into your menu extension so that it can be called from your menu action. Make sure to add the `Export` attribute to the class; otherwise, it will not be injected into your menu extension. The `ImportingConstructor` attribute on the constructor is also very important, as this allows the class to receive any required services via dependency injection.
50+
Add the `CalculationsMicroflowCreator.cs` class and follow the steps below:
51+
52+
1. Add the `Export` attribute to allow injection.
53+
2. Add the `ImportingConstructor` attribute to support dependency injection.
5154

5255
```csharp
5356
using Mendix.StudioPro.ExtensionsAPI.Model;
@@ -67,7 +70,11 @@ class CalculationsMicroflowCreator(IMicroflowService microflowService, IMicroflo
6770
}
6871
```
6972

70-
This class contains one public method, which is the one called by your menu. The method `CreateMicroflows` requires the current app as the parameter. The `CreateMicroflowsMenu` extension has access to the `CurrentApp` property, so it will pass it to the method when calling it from the menu action. The `CurrentApp` property is the `IModel` for the app that is currently open in Studio Pro. Every extension that inherits the type `UIExtensionBase` (such as a `MenuBarExtension`) has access to the `CurrentApp` property and can interact and modify the model.
73+
This class includes one public method called `CreateMicroflows`, which is triggered when you click your custom menu. It needs the current app as a parameter to work.
74+
75+
The `CreateMicroflowsMenu` extension can access the current app through the `CurrentApp` property. When the menu is clicked, it passes `CurrentApp` to `CreateMicroflows`.
76+
77+
The `CurrentApp` is the `IModel` that represents the app currently open in Studio Pro. Every extension that inherits from `UIExtensionBase` (like `MenuBarExtension`) has access to `CurrentApp`, which allows it to interact with and change the app's model.
7178

7279
Add the method as follows:
7380

@@ -84,22 +91,32 @@ public void CreateMicroflows(IModel currentApp)
8491
}
8592
```
8693

87-
As you can see, the `CreateMicroflows` method starts a new transaction, by calling `currentApp.StartTransaction`, which is the only way an extension can modify the model of the app. If your class tried to create microflows outside of a transaction, an error will be thrown. For more information, see [Interact with the Model API Using C#](/apidocs-mxsdk/apidocs/interact-with-model-api-11/).
94+
The `CreateMicroflows` method starts a new transaction by calling `currentApp.StartTransaction`, which is required to modify the model. If your class attempts to create microflows outside a transaction, it will result in an error. For more details, see [Interact with the Model API Using C#](/apidocs-mxsdk/apidocs/interact-with-model-api-11/).
95+
96+
Use `IMicroflowService` to create microflows. For more information, see [Create a Microflow and Add Activities Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-microflow-add-activities/). It requires:
8897

89-
`IMicroflowService` enables creating microflows. For details, see [Create a Microflow and Add Activities Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-microflow-add-activities/). It requires the current model (`IModel`), the containing module or folder inside a module (`IFolderBase`), a name, and an optional `MicroflowReturnValue`. The return value is actually used in the example, so you will see how to create one as well.
98+
* `IModel` (the current mode),
99+
* `IFolderBase` (module or folder)
100+
* Microflow name
101+
* `MicroflowReturnValue` (optional)
90102

91-
A microflow returns a value with `IMicroflowExpression`. This can be achieved by using your `IMicroflowExpressionService`, which returns an expression from a String input, and set that expression as the microflow's return value.
103+
A microflow returns a value with `IMicroflowExpression`. This can be done by using `IMicroflowExpressionService`, which returns an expression from a string input, and sets the expression as the microflow's return value.
92104

93-
A very simple `MicroflowReturnValue` can be created as follows:
105+
An example simple return value is seen below:
94106

95107
```csharp
96108
new MicroflowReturnValue(DataType.Boolean, microflowExpressionService.CreateFromString("true or false"));
97109
```
98110

99111
However, the example will have more complicated expressions, which use parameter names. These parameter names match the return values from called microflows.
100-
This simple extension will create three microflows. Two of them will perform mathematical calculations (multiplication and addition) and each of them will return their result. The other microflow will call these two microflows in sequence, compute their two results (subtract the addition result from the multiplication result), and return true or false if the value is larger than 0.
101112

102-
The method `CreateMicroflowsInFolder` will create the two microflows and the return values. Add the method.
113+
This extension creates three microflows:
114+
115+
1. Multiplication microflow – multiplies integers and returns the result
116+
2. Addition microflow – adds decimals and returns the result
117+
3. Main microflow – Calls the above two microflows in sequence, subtracts the addition result from the multiplication result, and returns `true` or `false` if the value is larger than 0.
118+
119+
Use the `CreateMicroflowsInFolder` method to create the two microflows and their return values:
103120

104121
```csharp
105122
void CreateMicroflowsInFolder(IModel currentApp, IFolderBase folder)
@@ -117,9 +134,9 @@ void CreateMicroflowsInFolder(IModel currentApp, IFolderBase folder)
117134
}
118135
```
119136

120-
To create a microflow which performs a multiplication between two input parameters (two numbers in this case), you can use the code below. As you can see, the String `multiplication1` and the String `multiplication2` match the parameters used in the expression for the return value. Note that for an expression, the dollar sign `$` must be put in front of the parameter name in order to be recognized as a variable input.
137+
### Multiplication Microflow
121138

122-
You can also see that the `DataType` of both parameters is integer.
139+
To create a microflow that performs multiplication between two input parameters, use the code below.
123140

124141
```csharp
125142
void CreateMultiplicationMicroflow(IModel currentApp, IFolderBase folder, IMicroflow callingMicroflow, string outputVariableName)
@@ -142,9 +159,15 @@ void CreateMultiplicationMicroflow(IModel currentApp, IFolderBase folder, IMicro
142159
}
143160
```
144161

162+
The strings `multiplication1` and `multiplication2` match the parameters used in the expression for the return value. Note that for an expression, the dollar sign `$` must be put in front of the parameter name in order to be recognized as a variable input.
163+
164+
You can also see that the `DataType` of both parameters is integer.
165+
145166
{{< figure src="/attachments/apidocs-mxsdk/apidocs/extensibility-api/multiplication-microflow.png" >}}
146167

147-
To create a microflow that performs an addition between two decimal values, you can use the code below. Just like the multiplication microflow example above, you can see that the String `addition1` and the String `addition2` match the parameters used in the expression for the return value. You can also see that their `DataType` is decimal.
168+
### Addition Microflow
169+
170+
To create a microflow that performs addition between two decimal values, use the code below.
148171

149172
```csharp
150173
void CreateAdditionMicroflow(IModel currentApp, IFolderBase folder, IMicroflow callingMicroflow, string outputVariableName)
@@ -167,9 +190,13 @@ void CreateAdditionMicroflow(IModel currentApp, IFolderBase folder, IMicroflow c
167190
}
168191
```
169192

193+
Like the multiplication microflow example above, the strings `addition1` and `addition2` match the parameters used in the expression for the return value. Their `DataType` is decimal.
194+
170195
{{< figure src="/attachments/apidocs-mxsdk/apidocs/extensibility-api/addition-microflow.png" >}}
171196

172-
Once a microflow is created, in order to enable this microflow to be called by other microflows, you need to add a call activity (`IActionActivity`). In the example, you have a method called `CreatMicroflowCallActivity` that can be used by both your multiplication and addition microflows.
197+
## Create Microflow Activities That Call Java Actions
198+
199+
Once a microflow is created, you need to add a call activity (`IActionActivity`). In the example, you have a method called `CreatMicroflowCallActivity` that can be used by both your multiplication and addition microflows.
173200

174201
There are a few prerequisites that you must complete before a microflow can be called by another microflow. This method can be broken down into parts:
175202

0 commit comments

Comments
 (0)