Main concepts
Introduction
The same high-level concepts that define programming languages also apply to Linx. Concepts like Functions, Types, Services and Events are all there, just packaged differently to make them easier to define and use. If you ever get stuck in Linx just think of what the programmatic answer will be and you’re likely to find something similar or be able to construct it from functionality in Plugins.
Linx | Programming equivalents |
Solution Container for one or more projects. |
Solution e.g. Visual Studio solution. |
Project Container for related functionality. |
Project e.g. Java project. |
Function Container for instructions to perform a specific task. |
Function, Procedure, Subroutine. |
Type Define structure of data. |
Data type e.g. string, integer, structure. |
Service Code that runs in the background. |
Daemon, Windows Service. |
Event Function triggered by a Service. |
Event Handler. |
Plugin Container for pre-built functions, types and services. |
Package e.g. Nuget or npm package. |
Server Host for Linx Solutions. |
Server, Host e.g. Apache and IIS hosts web apps. |
Each of these concepts are covered in this guide. Once you master them you’ll be able to create complex apps from the reusable components that come with Plugins or the pieces you build yourself.
Every chapter builds on the knowledge gained from the previous chapters. We recommend that you read these chapters in order.
Plugins
Functionality is added via Plugins. They contain pre-built Functions, Types and Services. Think of them as Nuget or npm packages that can be installed and used in your Linx Solution.
The Linx and Utilities plugins are installed by default and contain all the basic types and functions. Click on the ADD PLUGINS button to see all available plugins.
Plugins contain simple types like string or integer, generic functions like CallRESTService, complex services like RESTHost and specialized functionality like the AWS APIs.
Functions
Defining a Function
Here is a C# function compared to the Linx version:
- The Function definition lives in the Solution Explorer.
- Its Parameters property defines the input parameters.
- Its Result property defines the output results.
- The central working area contains the body of the function.
- Linx does not have an explicit ‘return’. When the Function finishes the Result set is returned.
Setting the result of a Function
- The SetValue function comes from the Linx Plugin.
- The Target property is set to $.Result.result. Select it from the dropdown. The Source property is set to an expression that adds the two numbers from $.Parameters. Use the Expression Editor in the dropdown to build the expression. The ‘=’ in front of the values in Target and Source indicates that these values are expressions and not literal values.
Click DEBUG to run the Function and see the result.
Calling a Function
Calling a Function is the same as one function calling another in programming.
- Functions are dragged onto the body of another Function to call them.
- Parameters of the called Function are visible as Properties.
Click DEBUG to run the Function and see the result.
Using the result of a Function
The body of a Function works exactly like the body of a programming function. Statements and expressions are added in a top down fashion and can refer to items in its scope. When we add another AddNumbers Function to the body of UseAddNumbers we can set its parameters to the result of the first AddNumbers:
Click DEBUG to run the Function and see the result.
Types
Simple Types
Linx plugin contains simple types Boolean, Byte, DateTime, Decimal, Double, Integer and String. Use a Type to create a variable in a Function by
- Dragging it onto the body of the Function and
- Setting the Value property.
Complex Types
Complex types have properties that can in turn be simple or complex. Plugins may provide their own complex types for use as variables in Functions. To create your own complex type
- Click Type on the menu bar
- Add properties
To use the Type as a variable
- Drag it onto the Function body and
- Set property values by using the Fields Editor in the dropdown or clicking the editor icon.
Lists
A list can contain any type. To use one
- Drag List from the Linx plugin onto the Function body.
- Set the Type property. It defaults to String.
- Add items in the editor by selecting the List Editor from the dropdown or clicking the editor icon.
- Other functions to manipulate the list are available in the Linx plugin.
Properties
Functions, Types and Services have properties that are visible in the Properties tab. Properties can be static or dynamic. Static properties are set at design time and cannot be changed at runtime. Dynamic properties can be changed at runtime by using an Expression.
Property values are usually represented in a text format that fits the type of property. Some examples are
- Complex types are saved as JSON e.g. a Property of type Person might have a value of ‘{"Name":"John", "Surname":"Smith"}’.
- Lists are saved as JSON e.g. ‘[“abc”,”def”]’.
- Database functions have a ‘Connection string’ property that are saved as is e.g. ‘Data Source=.\dbServer;Initial Catalog=mydb…’.
- Expressions are saved as ‘=expression’.
Expressions
Expressions are recognizable by the ‘=’ in front of the value in the Property tab e.g. a property value of ‘1+1’ will result in ‘1+1’ at runtime while ‘=1+1’ will result in ‘2’. It works like Excel except that expressions are only resolved at runtime.
Selecting a value in scope will automatically insert an expression referencing that value. There is also an Expression Editor available in the dropdown of dynamic property values where more complex expressions can be constructed.
Control Flow
The contents of a Linx function is executed from top to bottom.
In Linx control flow statements are implemented as functions. The Linx plugin contains DoWhile, ForEach, IfElse and TryCatch. They work exactly like their programming counterparts.
ForEach loops through any list and exposes each item in an execution path. To try it:
- Create a list and call it Names.
- Drag a ForEach from the Linx plugin.
- Set the List property to Names (using the dropdown).
The ForEach shows an execution path called Loop. This path will be executed once for each item in the List. To see it working:
- Add a couple of items to Names.
- Add the File plugin.
- Drag the TextFileWrite function into the box below Loop.
- Set the File path property.
- Set the Contents property to ForEach.Loop by selecting it from the dropdown.
Click DEBUG to run the Function and see the result.
DoWhile and IfElse use expressions to control the program flow. To try DoWhile:
- Add an Integer to the Function and name it Counter.
- Add a DoWhile and set its Condition property to Counter < 5. Use the Expression Editor in the dropdown to make this easier. DoWhile will keep on executing while the Condition is true.
- Add a SetValue to the Loop and set its properties to add 1 to Counter each time it executes.
Click DEBUG to run the Function and see the result.
Scope
Scope in Linx Functions works the same as in programming. Data is in scope if it is an ancestor in the execution tree.
Services
Linx Services are similar in concept to Windows Services or Daemons. It is code that is loaded and kept running by the Linx Server and communicates with Linx through Events. The steps to implement a Service are:
- Use Linx Designer to develop a solution which contains a Linx Service and reacts to its Events. At this point you have a design but nothing is running.
- Deploy the solution to a Linx Server and start the Linx Service. Now the Service is loaded by the Linx Server and triggering events which in turn does whatever you told it to do.
Examples of Linx Services are:
- Timer: Fires a TimerEvent at specified times.
- RESTHost: Fires events when its endpoints are called by clients.
Using a Linx Service
This example explains how to write to a file every 10 seconds to illustrate how the Timer Service can be used.
- Drag the Timer Service from the Utilities plugin onto your project.
- Set the “Run every” property to 10 seconds.
- Install the File plugin and add the TextFileWrite function to the TimerEvent.
- Set the File path property.
- Set the Contents property to $.Parameters.Data. It is the data that the Event passes to Linx. In this case the date and time that the event fires.
- Select Timer in the Solution Explorer and click DEBUG to start the Timer Service.
You will see the events firing in the Debug Output panel. You can also select the TimerEvent and click DEBUG to run the event once. Debugging an event works just like debugging a Function.
Server
Linx Server hosts Linx Solutions and runs all the services within the solution. Solutions are deployed to Linx Server from within Linx Designer or uploaded from the Linx Server management console. Linx Server manages:
- Linx Applications and their Services
- Users
- Configuration
- Logging
- Metrics
- Updates
- Resources
The Linx Server management console is a web application and looks like this: