Skip to content

Tutorial 04 10 Configure Traditional Bridge Environment

Matt Linder edited this page Jun 30, 2023 · 14 revisions

Harmony Core Logo

Tutorial 4: Configuring the Traditional Bridge Environment

All the individual pieces are now in place, and all that remains is to plug some custom code into the service startup pipeline to tell Harmony Core about the Traditional Bridge service and controller that are now available.

We'll provide the necessary custom startup code via a partial implementation of the Services.Startup class. And if you look in the Services project, you should already have a file named StartupCustom.dbl from when you plugged in code related to your Primary Key Generator class in the previous tutorial. You will simply add a little more code to that class.

Add Custom Startup Code

  1. Open the StartupCustom.dbl file in the Visual Studio editor. (This file is in the Services project.)

Determine the Traditional Bridge Directory

  1. Scroll to the bottom of the ConfigureServicesCustom method and add the following code immediately before the endmethod statement.

    ;;----------------------------------------------
    ;; Configure the Traditional Bridge environment.
    
    data traditionalBridgeDirectory, string
    data logLevel, string
    
    if (_env.IsDevelopment()) then
    begin
        traditionalBridgeDirectory=Environment.GetEnvironmentVariable("EXEDIR")
        if (String.IsNullOrWhiteSpace(traditionalBridgeDirectory))
        begin
            throw new ApplicationException("Logical name EXEDIR is not set. It must point to the TraditionalBridge host application.")
        end
        logLevel = "6"
    end
    else
    begin
        traditionalBridgeDirectory = Path.GetFullPath(Path.GetDirectoryName(^typeof(Startup).Assembly.Location))
        logLevel = "2"
    end
    

    This code specifies the directory where the Traditional Bridge Host application will be executed from, as well as the level of logging that will be performed. Notice that the code uses _env.IsDevelopment(), which you won't see defined in the code here. That is because _env is a class variable that is present in the main Startup class. We have access to it because this is a PARTIAL part of that same class.

  2. Now add this code immediately below the code you just added:

    data launchCommand, string, Path.Combine(traditionalBridgeDirectory,"launch.bat")
    data environmentVariables, @Dictionary<string,string>,new Dictionary<string,string>(){{"HARMONY_LOG_LEVEL",logLevel}}
    

    This code determines the command that will be used to launch the Traditional Bridge host application on the target system, and it also creates a list of environment variables that will be set within the process used to run the Traditional Bridge host application. It is important to note that there are two ways that the host process can be started. In some cases, Harmony Core will establish an SSH tunnel to a remote target system and send the launchCommand to the shell processor on that remote system. In the scenario we are using here, however, Harmony Core will launch a new process on the same machine, and it will instruct that process to execute the launchCommand.

  3. And add this code immediately below the code you just added:

    data contextPool, @ExternalContextPool<BridgeMethodsService>, new ExternalContextPool<BridgeMethodsService>
    &    (
    &    launchCommand,
    &    "optional_command_parameters",
    &    traditionalBridgeDirectory,
    &    environmentVariables,
    &    4
    &    ) 
    

    This code establishes a context pool (contextPool) capable of starting, hosting, allocating, and re-using Traditional Bridge client instances associated with your Traditional Bridge service and environment.

  4. Finally, add this code immediately below the code you just added:

    ;; Make 'BridgeMethodsService' available as a DI service
    services.AddSingleton<IContextFactory<BridgeMethodsService>>(contextPool)
    services.AddContextPool<BridgeMethodsService>()        
    

    This code completes the puzzle. It registers the contextPool and TraditionalBridgeService as services in the dependency injection (DI) container, making them available for use by controllers as needed.

  5. Save the file.

Build the Code

Before moving on, make sure the project builds:

  1. Right-click on the Services project and select Build.

  2. Check the Output window and verify that the build was successful.


Next topic: Testing Traditional Bridge


Clone this wiki locally