Skip to content

C# sample

A minimal console app that opens a SIDRA project, processes every site, and prints its level of service and degree of saturation.

This is a short website walkthrough using an existing project. To create Sites, Networks or volume scenarios, see the Sample project guide. The C# project's SIAPITest.cs contains several larger examples and is separate from the program below.

Note

Complete the Getting started prerequisites first (SIDRA INTERSECTION installed, 64-bit, .NET 8). You also need a SIDRA project (.sipx) file to open. Save one from SIDRA INTERSECTION, or point the sample at any existing project. Replace C:\Samples\Demo.sipx below with its path. If anything fails, see Troubleshooting.

1. Create the project

dotnet new console -n SidraSample
cd SidraSample

Copy the late-binding wrapper assembly LB_SI11API.dll (and its LB_SI11API.deps.json) into the project folder, then replace the generated SidraSample.csproj with this. It targets x64 and references the wrapper:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <Platforms>x64</Platforms>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="LB_SI11API">
      <HintPath>LB_SI11API.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

LB_SI11API.dll exposes the SIDRASolutions.SI.API types and loads the installed SIDRA INTERSECTION runtime for you at run time, so you instantiate the API directly rather than activating it through COM. Download the wrapper from LB_SI11API.zip.

2. Write the program

Program.cs:

using System;
using SIDRASolutions.SI.API;

class Program
{
    [STAThread]   // the SIDRA INTERSECTION runtime requires an STA thread
    static void Main()
    {
        // The wrapper loads the installed API; just instantiate SIAPI.
        var api = new SIAPI();

        try
        {
            if (!api.OpenProject(@"C:\Samples\Demo.sipx"))
                throw new InvalidOperationException($"Could not open project: {api.LastErrorMessage}");

            var project = api.Project;
            Console.WriteLine($"Project: {project.Name}");

            // Project -> SiteFolders -> Sites. In SIDRA a "site" is an intersection.
            var folders = project.SiteFolders;
            for (int f = 0; f < folders.Count; f++)
            {
                var sites = folders[f].Sites;
                for (int s = 0; s < sites.Count; s++)
                {
                    var site = sites[s];

                    site.Process();   // run the analysis for this site

                    // Site-level vehicle results live under Outputset.OutputSiteVehicle.
                    var result = site.Outputset.OutputSiteVehicle;
                    Console.WriteLine($"  {site.Name}: LOS {result.Level_of_service}, " +
                                      $"degree of saturation {result.Deg_satn:F3}");
                }
            }
        }
        finally
        {
            api.Close();   // saves and closes the project if it is still open, releases the licence and frees resources.
        }
    }
}

3. Run it

dotnet run

Expected output (values depend on your project):

Project: Demo
  North Rd / Main St: LOS B, degree of saturation 0.742
  East Ave / Main St: LOS C, degree of saturation 0.871

Important

Always call api.Close() when you are finished (a try/finally is the safest place). It saves and closes the project if it is still open, releases the licence and frees resources.

Reading detailed outputs

Each site's results hang off ISIAPISite.Outputset:

  • Outputset.OutputSiteVehicle: site totals (LOS, degree of saturation, delay, queues) used above.
  • Outputset.OutputLegs: per-leg results.
  • Outputset.OutputMovementVehicleODs: per-movement results.

See the API reference for the full surface.

Note

VB.NET consumes the API identically: same net8.0-windows x64 project, same LB_SI11API.dll reference, same New SIAPI() instantiation. Translate the snippet above to VB.NET syntax and use the same members shown in the API reference.