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.

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>
    <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. It ships with SIDRA Intersection.

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();   // shuts down the SIDRA Intersection runtime
        }
    }
}

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 shuts down the SIDRA Intersection runtime the wrapper started; skipping it can leave the process running in the background.

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; the API surface and the per-member VB.NET tabs in the API reference are unchanged.