{"id":18837228,"url":"https://github.com/clarenceb/logic-apps-bre","last_synced_at":"2025-06-26T02:33:35.562Z","repository":{"id":259568358,"uuid":"877697378","full_name":"clarenceb/logic-apps-bre","owner":"clarenceb","description":"Basic example of a Logic Apps BRE (Business Rules Engine) app.  Covers VSCode use, IaC (Bicep), and build and deploy workflow to the Logic App plan, CI/CD.","archived":false,"fork":false,"pushed_at":"2025-04-07T00:36:25.000Z","size":369,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-29T19:37:58.452Z","etag":null,"topics":["azure-piplines","bre","business-rules-engine","demo","logicapps"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clarenceb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-24T04:57:35.000Z","updated_at":"2025-04-07T00:36:29.000Z","dependencies_parsed_at":"2024-11-28T22:25:13.325Z","dependency_job_id":"21d0b481-e94c-4154-8afa-230e3787b3eb","html_url":"https://github.com/clarenceb/logic-apps-bre","commit_stats":null,"previous_names":["clarenceb/logic-apps-bre"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clarenceb/logic-apps-bre","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Flogic-apps-bre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Flogic-apps-bre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Flogic-apps-bre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Flogic-apps-bre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clarenceb","download_url":"https://codeload.github.com/clarenceb/logic-apps-bre/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Flogic-apps-bre/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261986737,"owners_count":23240700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-piplines","bre","business-rules-engine","demo","logicapps"],"created_at":"2024-11-08T02:34:29.300Z","updated_at":"2025-06-26T02:33:35.508Z","avatar_url":"https://github.com/clarenceb.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logic Apps BRE\n\nA simple example of building and deploying a Logic App with Business Rules Engine (BRE).\n\nTwo Logic App Workflows which use the BRE are included:\n\n* `MyRulesWorkflow`\n* `PurchaseOrderWorkflow`\n\nYou can test these with the REST Client file `TestBRE.http` located in the `LogicApp` directory.\n\n## Deploy infrastructure\n\nCreates the Logic Apps Standard Single Tenant plan.\n\n```bash\nRESOURCE_GROUP_NAME=la-bre-cicd\nLOCATION=australiaeast\nSUBSCRIPTION_ID=xxxx-xxxx-xxxx-xxxx\n\naz login\naz account set --subscription $SUBSCRIPTION_ID\n\naz group create --name $RESOURCE_GROUP_NAME --location $LOCATION\n\naz bicep upgrade\naz deployment group create --resource-group $RESOURCE_GROUP_NAME --template-file infra/bicep/deploy.bicep [--parameters @deploy.parameters.json]\n```\n\n## Build Logic App with BRE\n\nBuilds the Logic App with Business Rules Engine (BRE) assemblies bundled into a ZIP file.\n\nLogic Apps with BRE require compiling and then adding any of your custom code libraries, including your .NET facts assemblies, to the `lib/custom/net472` folder in your logic app project where workflows look for custom functions to run.\n\n```bash\n# Build the Function App as a custom code library for Logic Apps\ncd MyLogicAppRulesWorkspace/Function\ndotnet restore ./RulesFunction.csproj\ndotnet build ./RulesFunction.csproj\n\ncd ../LogicApp\nrm -rf ./staging\nmkdir -p ./staging\n\ncp -a ./Artifacts ./staging\ncp -a ./lib ./staging\nWORKFLOW_DIRS=(\"PurchaseOrderWorkflow\" \"MyRulesWorkflow\")\nfor WORKFLOW_DIR in \"${WORKFLOW_DIRS[@]}\"; do\n  cp -a ./$WORKFLOW_DIR ./staging\ndone\ncp connections.json ./staging\ncp parameters.azure.json ./staging/parameters.json\ncp host.json ./staging\nif [ -d .debug ]; then\n  cp -a .debug ./staging\nfi\n\ncd ./staging\nzip -r logicapps.zip . -x appsettings.json -x local.settings.json\nunzip -t logicapps.zip | grep \"lib/custom\" \u0026\u0026 echo \"Custom Function is packaged\" || echo \"Missing Custom Function\"\n```\n\n## Deploy Logic App with BRE\n\nDeploys the Logic App with Business Rules Engine (BRE) assemblies bundled into a ZIP file to a Logic Apps Standard plan.\n\n```bash\ncd ..\nOUTLOOK_RUNTIME_CONN_URL=\"$(az deployment group show --resource-group $RESOURCE_GROUP_NAME --name deploy --query properties.outputs.outlookRuntimeConnectionUrl.value -o tsv)\"\necho $OUTLOOK_RUNTIME_CONN_URL\njq \".\\\"outlook-ConnectionRuntimeUrl\\\" = \\\"$OUTLOOK_RUNTIME_CONN_URL\\\"\" appsettings.json \u003e ./staging/appsettings.json\n\nLOGIC_APP_NAME=\"$(az deployment group show --resource-group $RESOURCE_GROUP_NAME --name deploy --query properties.outputs.logicAppName.value -o tsv)\"\n\naz functionapp deploy --resource-group $RESOURCE_GROUP_NAME --name $LOGIC_APP_NAME --src-path ./staging/logicapps.zip --type zip\n```\n\nIf your Logic App using Connections (`connections.json`) or Parameters (`parameters.json`) files, you should include them in the ZIP file.  Do not include secrets in these files.  Either use Azure Key Vault references or App Settings for secrets.\n\n## Deploying App Settings to your Logic App (Standard)\n\nIf your Logic App uses App Settings for configuration, you should create a `appsettings.json` file, e.g.\n\n```json\n{\n  \"setting1\": \"value1\",\n  \"setting2\": \"value2\"\n}\n```\n\nThen apply the `appsettings.json` file to the Logic App:\n\n```bash\naz functionapp config appsettings set -g $RESOURCE_GROUP_NAME -n $LOGIC_APP_NAME --settings @staging/appsettings.json\n```\n\n## Deploying new or updated RuleSets\n\nYou can directly deploy individual RuleSet files to the logic app plan's local filesystem after deploying the Logic App.  The RuleSets are located in the directory `/home/site/wwwroot/Artifacts/Rules/`.\n\ne.g.\n\n```bash\naz functionapp deploy \\\n  --resource-group $RESOURCE_GROUP_NAME \\\n  --name $LOGIC_APP_NAME \\\n  --src-path MyLogicAppRulesWorkspace\\LogicApp\\Artifacts\\Rules\\SampleRuleSet.xml \\\n  --type static \\\n  --target-path /home/site/wwwroot/Artifacts/Rules/SampleRuleSet.xml\n```\n\nThe new rulesets are accessible in your workflows without having to restart the Logic App.\n\n## Azure Pipelines automation\n\nThe simplest way to deploy this sample is via a CI/CD pipeline.  Azure DevOps Pipelines is used for this example but you can map the steps from this pipeline to any other CI/CD tool.\n\nCreate a new Azure DevOps project and import the `azure-pipelines.yml` file to automate the build and deployment of the Logic App with BRE.\n\nThis pipeline is using the new YAML-based multi-stage pipelines feature in Azure DevOps.\n\nIt deploys infrastructure, builds the Logic App with BRE, and deploys the Logic App to a Logic Apps Standard plan.\n\nYou can change sample to segregate the infrastructure deployment and Logic App deployment into their own separate pipelines.\n\n![azdo-pipelines](img/azdo-pipelines.png)\n\nBe sure to define the following pipeline variables in your Azure DevOps project:\n\n* `recipientEmail` (for the Outlook connector used in the `PurchaseOrderWorkflow` workflow)\n* `subscriptionId` (your Azure subscription Id, used in the Bicep deployment)\n\n![azdo-pipeline-variables](img/azdo-pipeline-variables.png)\n\nAfter deploying the logic app, you'll need to manually authorise the Outlook connector used in the `PurchaseOrderWorkflow` workflow via the Azure Portal.\n\n## Editing, testing, and debugging locally in VSCode\n\nAssumes a Windows OS and Visual Studio Code (VSCode) with Azure Functions and Azure Logic Apps (Standard) extensions installed.  You'll also need the Azurite extension for Functions local storage.  If you received storage errors, you may need to start Azurite manually (CTRL+SHIFT+P, `Azurite: Start Blob Service`, repeat for `Azurite: Start Table Service`, etc.)\n\nStart VSCode and then open the Workspace file:\n\n* Navigate to the menu option **File** / **Open Workspace from File**\n* Select the file `MyLogicAppRulesWorkspace.code-workspace`\n* **or** start VSCode with `code MyLogicAppRulesWorkspace.code-workspace` from the terminal\n* Build the Functions project with the default build task (`CTRL+SHIFT+B`) or open a Terminal window in VSCode:\n\n```powershell\n# Build the Function App as a custom code library for Logic Apps\ncd MyLogicAppRulesWorkspace\\Function\ndotnet restore .\\RulesFunction.csproj\ndotnet build .\\RulesFunction.csproj\n\ncd ..\\LogicApp\ncp local.settings.json.template local.settings.json\n```\n\n* Select the **Run and Debug** icon on the left-hand side of the VSCode window (or `CTRL+SHIFT+D`)\n* From the **Run and Debug** menu, select **Attach to Logic App (Logic App)**\n* Click the **Start Debugging** button (or `F5`)\n* (Optional - if you want to debug the Function) From the **Run and Debug** menu, select **Attach to .NET Functions (Functions)**\n* (Optional - if you want to debug the Function) Click the **Start Debugging** button (or `F5`)\n* Validate that both Logic App and Function (if you attached to it) are running locally\n* In the Workspace Explorer, navigate to the Logic App file `PurchaseOrder\\workflow.json`\n* Right-click on the file and select **Use Connectors from Azure** -- select the `LogicApp` folder, you should see new app settings added to `local.settings.json`\n* Right-click on the file and select **Open Designer** -- it should render with no errors\n* Right-click on the file and select **Overview** -- it should render with no errors\n* Copy the Logic App URL and paste it into a `.env` file (see `.env-template` as an example)\n* Open the [Rest Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) file `TestBRE.http` and run the request to test the Logic App\n* Click the latest run to view the run details\n* Click the action **Call a local rules function in this logic app** to view the action inputs and outputs\n* Stop the Function and Logic App debugging sessions (`SHIFT+F5`)\n\n## Debug Tracking when running in VSCode\n\nYou [log tracking information](https://learn.microsoft.com/en-us/biztalk/core/how-to-log-tracking-information-to-file) to a local file, similar to the Microsoft Rules Composer test output pane.\n\nThe tracking information does not give deep insights into fact values or other information you might want to see.\nYou can achieve this by creating a custom `IRuleSetTrackingInterceptor` implementation.  See the file [DebugTracking/LocalDebugTrackingInterceptor.cs](./DebugTracking/LocalDebugTrackingInterceptor.cs) for a sample implementation of a tracking interceptor with an additional `TrackDebugMessage` method to log this type of information.\n\n```csharp\n// Example\nLocalDebugTrackingInterceptor interceptor = new LocalDebugTrackingInterceptor(\"TrackingOutput.txt\");\n// ...\ninterceptor.TrackDebugMessage(\"Debug Final state .NET Fact\", \"currentPurchase\", currentPurchase);\ninterceptor.TrackDebugMessage(\"Debug Final Response\", \"RuleExecutionResult\", ruleExectionOutput);\n```\n\nThe tracking interceptor is enabled when you set the following environment variable in the file `LogicApp\\.vscode\\tasks.json`:\n\n```json\n\"DEBUG_TRACKING\": \"true\"\n```\n\nThen you can examine tracking output in the log file: `LogicApp\\TrackingOutput.txt`\n\nSample output:\n\n```text\n------------- DEBUG MESSAGE 11/11/2024 10:42:10 PM\nRule Engine Instance Identifier: 0f774388-a33e-467a-9bf6-f8f352a26adc\nRuleset Name: SampleRuleSet\nTitle: Debug Final state .NET Fact\nMessage: currentPurchase\nValue: ContosoPurchase - PurchaseAmount: 1100, ZipCode: 98052, TaxRate: 10, SalesTax: 110\n\n------------- DEBUG MESSAGE 11/11/2024 10:42:10 PM\nRule Engine Instance Identifier: 0f774388-a33e-467a-9bf6-f8f352a26adc\nRuleset Name: SampleRuleSet\nTitle: Debug Final Response\nMessage: RuleExecutionResult\nValue: XmlDoc:\n\u003cns0:Root xmlns:ns0=\"http://BizTalk_Server_Project1.SchemaUser\"\u003e\n  \u003cUserDetails\u003e\n    \u003cAge\u003e70\u003c/Age\u003e\n    \u003cName\u003eUserName\u003c/Name\u003e\n    \u003czipCode\u003e98053\u003c/zipCode\u003e\n  \u003c/UserDetails\u003e\n  \u003cStatus\u003e\n    \u003cGold\u003etrue\u003c/Gold\u003e\n    \u003cDiscount\u003e15\u003c/Discount\u003e\n  \u003c/Status\u003e\n\u003c/ns0:Root\u003e\nPurchaseAmountPostTax: 1210\n```\n\n## Testing Rule Sets locally with Microsoft Rules Composer\n\nDownload and install the [Microsoft Rules Composer](https://go.microsoft.com/fwlink/?linkid=2274238).\n\nRun the `RuleComposer.exe` application from the installation directory.\n\n* Load the rule set `Artifacts\\Rules\\SampleRuleSet.xml` from **Rule Store** / **Load...** menu (`CTRL+L`).\n* Select **RuleSets** / **SampleRuleSets** / **Version 1.0**\n* Right-click and select **Test RuleSet...**\n* Add an instance of the XML document of type `SchemaUser`: `Artifacts\\Rules\\SchemaUser.xml`\n* Click **Test**\n\nSample input file `SchemaUser.xml`:\n\n```xml\n\u003cns0:Root xmlns:ns0=\"http://BizTalk_Server_Project1.SchemaUser\"\u003e\n  \u003cUserDetails\u003e\n    \u003cAge\u003e70\u003c/Age\u003e\n    \u003cName\u003eUserName\u003c/Name\u003e\n    \u003czipCode\u003e98052\u003c/zipCode\u003e\n  \u003c/UserDetails\u003e\n  \u003cStatus\u003e\n    \u003cGold\u003efalse\u003c/Gold\u003e\n    \u003cDiscount\u003e0\u003c/Discount\u003e\n  \u003c/Status\u003e\n\u003c/ns0:Root\u003e\n```\n\nSample ouput file after testing the rule set:\n\n```xml\n\u003cns0:Root xmlns:ns0=\"http://BizTalk_Server_Project1.SchemaUser\"\u003e\n  \u003cUserDetails\u003e\n    \u003cAge\u003e70\u003c/Age\u003e\n    \u003cName\u003eUserName\u003c/Name\u003e\n    \u003czipCode\u003e98052\u003c/zipCode\u003e\n  \u003c/UserDetails\u003e\n  \u003cStatus\u003e\n    \u003cGold\u003etrue\u003c/Gold\u003e\n    \u003cDiscount\u003e5\u003c/Discount\u003e\n  \u003c/Status\u003e\n\u003c/ns0:Root\u003e\n```\n\nHowever, there are rules that use the .NET Fact classes like `ContosoPurchase.cs` in both conditions and actions.  So, this is not the expected output.  It should look like this:\n\n```xml\n\u003cns0:Root xmlns:ns0=\"http://BizTalk_Server_Project1.SchemaUser\"\u003e\n  \u003cUserDetails\u003e\n    \u003cAge\u003e70\u003c/Age\u003e\n    \u003cName\u003eUserName\u003c/Name\u003e\n    \u003czipCode\u003e98052\u003c/zipCode\u003e\n  \u003c/UserDetails\u003e\n  \u003cStatus\u003e\n    \u003cGold\u003etrue\u003c/Gold\u003e\n    \u003cDiscount\u003e15\u003c/Discount\u003e\n  \u003c/Status\u003e\n\u003c/ns0:Root\u003e\n```\n\nThe discount was incorrect without the .NET Fact class `ContosoPurchase` being added to the test.\n\nWe need to add an instance of the .NET Fact class `ContosoNamespace.ContosoPurchase` to the test.  This is not possible in the Microsoft Rules Composer without a Fact Creator.\n\nSee the Fact Creator sample `MyFactCreator.cs`.\n\nBuild the `Functions` project then copy the `RulesFunction.dll` to the `LogicApps\\Artifacts\\Rules` directory, along with the ruleset `SampleRuleSet.xml` and sample input file `SchemaUser.xml`.\n\nNow, add the Fact Creator and re-test the rule set (see below).\n\n![fact-creator1.png](img/fact-creator1.png)\n![fact-creator2.png](img/fact-creator2.png)\n\nYou may need to restart the Microsoft Rules Composer for the fact creator to be recognized (e.g. if you rebuilt and copied the `RulesFunction.dll` assembly).\n\nNote: Only .NET Fact values assigned back into the input document will be visible in the output document.  However, as you can see in the `RulesFunction.cs` file, the `ContosoPurchase` fact values can be returned to your LogicApp workflow, e.g.\n\n```csharp\nvar ruleExectionOutput = new RuleExecutionResult()\n    {\n        // XML Fact document with updated values\n        XmlDoc = updatedDoc.OuterXml,\n\n        // .NET Facts returned to the Logic App\n        PurchaseAmountPostTax = currentPurchase.PurchaseAmount + currentPurchase.GetSalesTax()\n    };\n```\n\n## Resources\n\n* [Logic Apps (Standard) – Azure DevOps sample](https://github.com/Azure/logicapps/tree/master/azure-devops-sample)\n* [Walkthrough: Creating a Simple Business Policy](https://learn.microsoft.com/en-us/biztalk/core/walkthrough-creating-a-simple-business-policy) - for Purchase Order example\n* [Walkthrough: Testing the Policy](https://learn.microsoft.com/en-us/biztalk/core/walkthrough-testing-the-policy) - for Purchase Order example\n* [Microsoft.Web/connections](https://github.com/Azure/azure-quickstart-templates/blob/master/demos/arm-template-retrieve-azure-storage-access-keys/main.bicep#L45) - example usage\n* [Microsoft.Web/connections/accessPolicies](https://dev.to/leonards/parameterising-logic-app-standard-connectionsjson-with-bicep-part-3-57d7) - example usage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarenceb%2Flogic-apps-bre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclarenceb%2Flogic-apps-bre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarenceb%2Flogic-apps-bre/lists"}