Developing Custom Routes
Overview
In some cases you would want to write a custom route to do some specific manipulation with message data that might be easier that processing through Crossfire.
These are extensions to Crossfire and is written typically using C# code, and building a separate DLL.
First you can create a project with Visual Studio, and make sure you are at least using .NET 4.0 for the project. Our current convention is to use .net Standard 2.0 for development.
There are a few pre-requsite installations required before you can begin development
Microsoft visual studio https://visualstudio.microsoft.com/downloads/
The latest .net SDK https://dotnet.microsoft.com/en-us/download/dotnet
The Sandfield.Messaging.dll project reference. This will be provided to you upon request
Project setup
Open Visual Studio and click "Create a new project".
Search for the project type "C# class library". Select the option shown to the left
Configure your new project
Project Name: {Your company}.Messaging.CustomRoutes.{Your project here}
Location: Pick a location on disk to do your development
Solution Name: {Your company}.Messaging.CustomRoutes.{Your project here}
EG Sandfield.Messaging.CustomRoutes.ConvertXmlToJson
After clicking next, you will be asked what Framework to use. We recommend .NET Standard 2.0
Click Create
Pre development
You should now have an empty project with a single Class1.cs file. Rename your file to Route.cs, and rename your class to Route
Right click on the Dependencies item in the solution explorer, and select "Add Project Reference". Use the "Browse" button at the bottom, and find the Sandfield.Messaging.dll file provided above. Click Add once you have selected the file, then click OK to close the menu.
In the code window, you can now make your class implemnet the IRouteMessage interface required for custom routes. Add " : IRouteMessage" after your "public class Route" declaration
You will then need to implement two methods. Paste these lines into your file and complete the method body
public bool CustomMatch(Message message) {}
This is used for the Custom Match functionality to determine if a message should be routed. You can access all fields against the message, and its linked attachments. Return true if the message should be routed, otherwise false.
public bool CustomRoute(DeliveryTypeDetail FromDeliveryTypeDetail, Message message){}
This is used to modify the message, its attachments, or perform other logic before the message is passed on to the destination transport.
Development
Write the code for your custom route. Make sure to right click on your solution in the "Solution Explorer", and select "Build Solution" often. This will make sure there are no errors.
You can create new files, classes, methods, add nuget package references, and more. The final value of message.Attachments will be sent to your destination transport when your route has finished running.
Deployment
Create a new folder in your Crossfire engine directory to store the route. It is best to name the folder the same as your route eg "Sandfield.Messaging.CustomRoutes.ConvertXmlToJson"
Copy the route files from the bin folder into the new engine directory. The bin folder will be located in a subfolder of your project eg \\Sandfield.Messaging.CustomRoutes.ConvertXmlToJson\Sandfield.Messaging.CustomRoutes.ConvertXmlToJson\bin\Debug\netstandard2.0
You will need to copy the main dll, and pdb for your application eg Sandfield.Messaging.CustomRoutes.ConvertXmlToJson.dll and Sandfield.Messaging.CustomRoutes.ConvertXmlToJson.pdb
Set up the route in crossfire. If you wish to use the CustomMatch method, check that option on the route.
Custom Assembly: This is the full path to your dll inside the engine folder
Custom Class: This is the namespace and class name of your IRouteMessage implementation.