Package Builder

◷ Reading Time: 10 minutes

Introduction

To publish the created project, you should package it using the package builder. The packaging is a process by which to create Service Modules that are .frpd files or a folder containing all the dependent logic documents related to a scenario. A scenario can be any logic document (i.e., Flow, DRD, IRD, DT, etc). When you build a service module, the module becomes self-sufficient from the rest of the logic documents in your project. That means you can simply deploy the module by copying it to any destination.

Package Builder

When you open any logic document, you can find the Package Builder icon on the toolbar:

Or by going to Tools –> Publisher menu:

Package Builder has three tabs,

  1. Builder
  2. Package View
  3. Deployment

Builder

Once you launch the package builder, the window below will appear opening the Builder tab.

Properties

  • Platform: The platform you want to publish
  • Method: The method to publish
  • Store Package File: Select this if you want to save the project package.
  • File: <Path to save the package file>
  • Include Project assemblies in this package: <State whether you need to include project assemblies in this package>
  • Package File Settings
    • Identifier: Name of the package file
    • Version: Version of the package file
  • Service Information
    • Version: Version of the service

In the Builder tab, you can,

  1. Select a method that you would like to use for packaging
    1. Package file
    2. Folder
  2. Set some more detailed information for a package file
    1. Setting Identifier and Version of the package
    2. Manage metadata and certificate

There are two methods of building a package,

  1. Create a Package File: Single file that contains all related models
  2. Copy to Target Folder: Single folder that has all the related models

Create a Package File

This allows you to build a single file that has all the related models. You need to select the destination where the package file will be saved. To select the Package filename and its location, you need to click on the three dots button to browse and select the destination file path. Then in the “Select package file to save” window, select your file path and choose a name for your Package.

Including Assemblies

If you are using any extensions (ex: FlexRule.Extensions.Robotics.dll for RPA) you have to tick the box, Include project assemblies in this project.

Advanced Options

The package allows you to add,

  1. Digital signature
  2. Metadata

These options are available only if a Package File is used.

Digital Signature

When a package is signed by a digital signature, FlexRule Server will highlight that package and show a tick box on the list of packages.

Digital Signature

When a package is signed by a digital signature, FlexRule Server will highlight that package and show a tick box on the list of packages.

Package View

By switching to the Package View tab, you can see all of the logic documents and dependencies that are required for this deployment.

As you see in this example, we opened the Car Flow.xml document of the “Car Insurance” example.

Dynamic Routing Packages

If you are using a package with dynamic routing, this is where you should manually add the list of files that will be routed during runtime as they will not be added automatically.

Deployment

Deployment is the process of pushing the built package file to a server for hosting. By default, FlexRule Designer has direct integration with FlexRule Server.

  1. Switch to the Deployment tab
  2. In the combo box, please select the FlexRule Server.
Run it as a REST API

FlexRule Server is a product that allows you to host your logic of any kind as a service and consume it in a REST API manner. This enables you to use FlexRule in any technology stack (i.e., Python, PHP, JAVA, etc.), or if you want to build a Service Oriented Platform (SOA) based on your business logic.

Once the Deployment tab is selected, you will see the screen below.

Settings

In the deployment for FlexRule Server, below is the Configuration:

  • Server Address: is the address of the machine to where the FlexRule Server is installed (e.g., http://192.168.10.10:9000)
  • User Account: is the login name to the FlexRule Server that has the access to upload package. (Admin by default has the permission).
  • Password: is the password for the above credential (login).
  • Grant the package ownership to the current login: It will make the above login the package owner so it can manage the package.
  • Enable the package: when this is ticked, it starts the package and service automatically after deployment is finished.
  • Grant the applications below ownership for execution: This associates an application account for executing (calling) the service (by default app1 account is created during the installation).
Create a Package File

On the Builder tab, make sure the Packaging Logic Method is set to Create a Package File to be able to deploy it to FlexRule Server.

You can set it up as shown in the image below:

Press the Publish button and the package will be deployed to the server. Its logic is ready to be consumed as a REST API service.

Creating Engine from Package

Once a package is built using the File or Folder method, FlexRule Runtime can load it and create an engine to process requests.

File

// Get the stream for your package (i.e., from database, file system, Azure, etc.)
var xbrlStream = File.OpenRead("BalanceSheetClassified.frdp"); // in this example we are building a stream from file system
// pass the stream to PackageLoader class
var loader = new PackageLoader(xbrlStream);
// Your package always has only one module, get the first one
var module = loader.Modules.First();
// Create an engine using the service module RuleSet and Entry
var engine = RuntimeEngine.FromRuleSet(module.RuleSet, module.Entry);

Folder

When the Folder option is selected, then there are two options:

  1. Loading the folder as a ruleset, preserving the folder structure, and creating an engine with the ruleset OR
  2. Loading the logic document from the address.

RuleSet

// Get the stream for your package (i.e., from database, file system, Azure, etc.)
var xbrlStream = File.OpenRead("BalanceSheetClassified.frdp"); // in this example we are building a stream from file system
// pass the stream to PackageLoader class
var loader = new PackageLoader(xbrlStream);
// Your package always has only one module, get the first one
var module = loader.Modules.First();
// Create an engine using the service module RuleSet and Entry
var engine = RuntimeEngine.FromRuleSet(module.RuleSet, module.Entry);

Logic document

var baseFolder = @"C:\rules\xbrl\balancesheet";
var logic = @"Networks\BalanceSheetClassified\BalanceSheetClassified Flow.xml";
// Get the stream to logic
var stream = File.OpenRead(Path.Combine(baseFolder, logic));
// Create engine using stream
var engine = RuntimeEngine.FromXml(stream, baseFolder);

NuGet

You can automate the packages building process using NuGet.exe command line. Once the NuGet package for the FlexRule models is created, then the application can use PackageLoader to load the Module from the NuGet package.

In order to let FlexRule Runtime loads the package and creates a Module the structure of the NuGet package must follow below:

  • Your Package
    • Bin: folder for your custom assemblies
    • Decisions: folder that has the root to models
      • Package Identifier Folder: the root to models
        • All your Models: all files and folders for your models
    • Info: Folder that has the package and module information
      • Package.xml: The XML file that describes the module specification

Package.Xml

This file provides the module information. The PackageLoader will query this file to populate the module information.

<Package name='test' builderVersion='2'>
	<Decisions>
		<Add name='' entry='' title='' description='' version='' />
	</Decisions>
</Package>

The Package.Xml allows only one module at a time. And below are the description of the modules.

  • name: Name of the module, which must match the name of the folder under Decisions
  • entry: Entry point to the RuleSet of the module
  • title: Display name of the module
  • description: Description of the module
  • version: The version of the module. i.e. At FlexRule Runtime that will be the service version.

Here is an example:

<Package name='test' builderVersion='2'>
	<Decisions>
		<Add name='Car Flow' entry='Car Flow.xml' title='Car Flow' description='' version='1' />
	</Decisions>
</Package>

nuspec

nuspec allows NuGet.exe to create the NuGet package. Below is an example of a nuspec.

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
    <metadata>
        <id>Car-Insurance</id>
        <version>1.0</version>
        <authors>FlexRule</authors>
        <owners>FlexRule</owners>
        <projectUrl>https://resource.flexrule.com</projectUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <releaseNotes></releaseNotes>
        <description>Sample for FlexRule's car insurance models</description>
        <copyright>Copyright ©2019 by FlexRule</copyright>
        <tags>FlexRule</tags>
        <dependencies>
            <dependency id="FlexRule.Runtime" version="8.0" />
        </dependencies>
    </metadata>
 
    <files>
        <file src="bin\**" target="bin" />
        <file src="decisions\**" target="decisions" />
        <file src="info\**" target="info" />
    </files>
</package>

Loading NuGet Package

PackageLoader will allow you to create a module from a NuGet package.

var nugetFile="PATH_TO_YOUR_NUGET";
var loader = new PackageLoader(File.OpenRead(nugetFile));
var module = loader.Modules.First(); // Package contains only one module
var engine = RuntimeEngine.FromRuleSet(module.RuleSet, module.Entry);

Sample

The attached sample zip file shows the structure of the Car Insurance models for building a NuGet package.

Updated on April 12, 2022

Article Attachments

Was this article helpful?

Related Articles