Custom Code & IDE

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:

  1. Custom Message Processing: Use a Custom Code Device to prototype message processing, or provide custom logic for a single channel. This image shows the simple interface used for message processing (Start Stop ProcessMessageAsync), 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).

image-20250821-172137.png
  1. 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 Actions tabs which let the user directly interact with the HTTP objects (if the default behavior isn’t desired).

image-20250821-173515.png
  1. 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.

image-20250821-181747.png

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.

image-20250821-195031.png
Multiple reference types

Connexion has different types of references with specific behaviors:

  1. .NET Framework assemblies: These are assemblies registered in the GAC. This is where you add all your typical .NET references, like System.Runtime.Serialization.

  2. Current Channel: If your custom code device should reference an assembly which is part of a custom compiled device, then use the Current Channel option. 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.

  3. 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).

image-20250821-200153.png
Current Channel references let you reference assemblies which are part of a compiled device. In this example, the reference to Cdph.ReportingDevice will be automatically updated as that device is upgraded or downgraded.
image-20250821-200836.png
Current Channel references don’t show a version number in the tree. Installed Assembly references are not automatically updated and do show a specific version number.

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.

image-20250821-202019.png
image-20250821-202440.png
After adding the service reference, the required .NET framework references are automatically added and the generated proxy class is shown in the tree.

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.

image-20250821-203753.png

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.

image-20250821-204956.png

After clicking the OK button, a tree of database objects will be displayed. Select the items you wish to be available to your code.

image-20250821-212102.png
image-20250821-222451.png
Standard Entity Framework Database Access

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.

image-20250821-223628.png

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:

image-20250821-224608.png

Event Publications

Events Hooks are covered here.

Breakpoints

Please see Custom Code Break Points.