Custom Code & IDE
Connexion (and Gateway) have a built-in C# development control which is used throughout the management applications. This control provides a way for users to easily inject their own logic - for tweaking the behavior of existing devices, adding custom message processing, or utilizing enterprise functionality.
Although we recommend using a dedicated IDE like Visual Studio or Rider for complex development tasks, the built-in IDE is quite powerful. It supports intellisense, code formatting and spacing, syntax error highlighting and compiler errors, references (both assembly and web), embedded resources, multiple code files, database connections, break points and debugging, and much more.
Here are a few examples of the Custom Code control:
Custom Message Processing: Use a
Custom Code Deviceto prototype message processing, or provide custom logic for a single channel. This image shows the simple interface used for message processing (StartStopProcessMessageAsync), but a real-world example might be creating an Entity Framework model and connection to a database and adding records based on message content. If your logic will be used by multiple channels, Connexion can automatically convert your work into a Visual Studio solution so it can be packaged into a fully-compiled device (with it’s own user interface).
Adding or altering existing device behaviors: Many devices use this control to allow users to change default behaviors, or, add their own new behavior. For example, the HTTP devices both have
Custom Actionstabs which let the user directly interact with the HTTP objects (if the default behavior isn’t desired).
Enterprise features & integration: Connexion uses this control for a number of enterprise features. For example, the Alerting feature supports most common protocols (email, SMS, SNMP, etc.) natively. However, if you want to push alerts to your own monitoring stack, for example, you can utilize this control. Many other enterprise features like Auditing, Monitoring, Globals, and Scripting also use this control.
Let’s take a closer look at the various features of the Custom Code Control.
References
The Custom Code control supports both .NET assembly references and service/web references. Right-click the References tree item and choose the Manage References menu. This will display the References dialog.
There is also a Global References menu item which includes or excludes a reference to the Global code. The Global Code is a special type of global which lets you share code with any Custom Code control. Typically, globally shared code is defined within a shared and properly versioned .NET assembly, however, the Global Code can be handy in many scenarios.
Connexion has different types of references with specific behaviors:
.NET Framework assemblies: These are assemblies registered in the
GAC. This is where you add all your typical .NET references, likeSystem.Runtime.Serialization.Current Channel: If your custom code device should reference an assembly which is part of a custom compiled device, then use the
Current Channeloption. When a compiled device version is changed (upgraded or downgraded), the Current Channel references are also automatically updated. This ensures your custom code device and compiled device are always referencing the same assemblies.Installed Assemblies: These are assemblies which are already used by either Connexion or compiled devices within your system (and not necessarily in use within your channel).
Cdph.ReportingDevice will be automatically updated as that device is upgraded or downgraded.Connexion versions prior to 18 only support .NET framework assemblies (up to 4.8.1).
Service References
The Custom Code control supports simple service references. Right-click the Service References tree item and choose the Add Service Reference option. Input the URI to a wsdl and click the Go button. If the wsdl is valid, the definition will be displayed. Click the Add Reference button to confirm.
Modern async/await service signatures are not available in version 16. You can use the older-style OnOperationCompleted event callback for async service calls.
Resources
The Custom Code control supports embedded resources. These are files which can be included and then referenced from within code. For example, you might have a public key or text file which needs to be loaded into memory when your code starts. Resources can be accessed via helper methods GetResourceX.
Connexion application servers can be members of a cluster. If resources are not embedded here, you must ensure your resources are available (at the same location) on all members of a Connexion cluster.
Resources are serialized and stored with the custom code configuration. We do not recommend embedding large payloads - try and keep resources under 1MB.
Data Connections
Data Connections are Entity Framework based models of databases. Entity Framework is an ORM which hides much of the complexity of database interaction, and includes support for many different types of database (Sql Server, Postgres, MySql, Oracle, etc.).
The Custom Code control supports all the standard .NET data access classes, if you prefer to use those.
After clicking the OK button, a tree of database objects will be displayed. Select the items you wish to be available to your code.
Code Classes
The custom code control supports multiple code classes. Right-click on the Code node and choose the Add Code File option. Individual code files have actions and options available on the associated context menu.
One interesting feature is the Lock File command. This option will obscure and password protect a code file - making it accessible only to those with the password.
Templates
Templates are a feature used by the Templating Device. This device uses a Razor template engine to create textual content. This engine (the same one used in ASP.NET), makes it easy to generate structured text, like Cda and Fhir without resorting to complex object models. Read about the Templating Device for more information.
Values
The values node represents a collection of key-value string pairs which can be accessed by code. The concept is to hide sensitive values that need to be accessed by your code, without have this text appear within your code.
You can access these key-value pairs using the following code:
Event Publications
Events Hooks are covered here.
Breakpoints
Please see Custom Code Break Points.