StatusMap.OnStatusChanged Event

Occurs when on status changed.

Namespace: Gamanet.C4.SDK
Assembly: Gamanet.C4.SimpleClient (in Gamanet.C4.SimpleClient.dll) Version: 2026.0.0.733
Syntax
C#
public event EventHandler<StatusArgsV1> OnStatusChanged

Value

EventHandler<StatusArgsV1>

Implements

ISimpleClientStatusMapV1.OnStatusChanged
Example
The following example illustrates how StatusMap notifies about device unknown statuses when connection broken.
C#
using System;
using Gamanet.C4.SimpleInterfaces;
using Gamanet.C4.SDK;

public class RestClientConfiguration
{
    static void Main()
    {
        // Create instance of simple client with configuration for RestClient (connection to C4 server)
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

        ConnectionInfo token;
        var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        Console.WriteLine("Connection result: {0}", connectionResult);

        client.StatusMap.OnStatusChanged += StatusMapOnOnStatusChanged;
        client.MessagePump.Start();
        client.StatusMap.Start();


        // The example displays the following output:
        // Connection result: Successful 

        // Process of connection broking...

        // Unknown statuses of all devices
        // Status of entity 20000000-0000-0000-0000-000000000000 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity e6ea9173-c8c8-4e73-a38e-167d9d7c3811 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity 6b50ca76-458a-466d-a58e-d3acf5c0b9fe changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity ffb1dc4b-4cab-4ec5-80dc-0b65b6008d51 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
    }

    private static void StatusMapOnOnStatusChanged(object sender, StatusArgs e)
    {
        foreach (var change in e.Changes)
        {
            foreach (var statusInfo in change.Value)
            {
                Console.WriteLine($"Status of entity {change.Key} changed to {statusInfo.Status}");
            }
        }
    }
}
The following example illustrates how new device can be created by other client application. Local client catches changes in device structure tree. Even if local client managed to get change about new device until connection broking, client will receive unknown statuses for each device including new one.
C#
using System;
using Gamanet.C4.SimpleInterfaces;
using Gamanet.C4.SDK;

public class RestClientConfiguration
{
    static void Main()
    {
        // Create instance of simple client with configuration for RestClient (connection to C4 server)
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);
        var client2 = new SimpleClient(ConnectorConfiguration.HttpClient);

        ConnectionInfo token;
        var connectionResult1 = client.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        Console.WriteLine("Connection result: {0}", connectionResult1);

        var connectionResult2 = client2.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        Console.WriteLine("Connection result: {0}", connectionResult2);

        client.StatusMap.OnStatusChanged += StatusMapOnOnStatusChanged;
        client.MessagePump.Start();
        client.StatusMap.Start();
        client2.MessagePump.Start();

        client2.MessagePump.OnStateChanged += (sender, eventArgs) =>
        {
            if (eventArgs.MessagePumpState == MessagePumpState.Recovered)
            {
                var device = new SimpleDevice(Guid.NewGuid(), "OtherBus",
                    EntityRoot.Device, Guid.Parse("D81A3534-CA3F-4998-A8AC-473143DA521E"));
                Console.WriteLine("Connection was restored");
                Console.WriteLine($"Other client created new device {device.Id}");
                client2.Devices.Create(device);
            }
        };

        // The example displays the following output:
        // Connection result: Successful 

        // Process of connection broking...

        // Unknown statuses of all devices
        // Status of entity 20000000-0000-0000-0000-000000000000 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity e6ea9173-c8c8-4e73-a38e-167d9d7c3811 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity 6b50ca76-458a-466d-a58e-d3acf5c0b9fe changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity ffb1dc4b-4cab-4ec5-80dc-0b65b6008d51 changed to 58390eda-38bf-43a0-ba33-48cc1750b831

        // Connection was restored
        // Other client created new device 264fe2e6-b879-47a4-9f22-d706fb94b5aa

        // Status of entity 20000000-0000-0000-0000-000000000000 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity e6ea9173-c8c8-4e73-a38e-167d9d7c3811 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity 6b50ca76-458a-466d-a58e-d3acf5c0b9fe changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity ffb1dc4b-4cab-4ec5-80dc-0b65b6008d51 changed to 58390eda-38bf-43a0-ba33-48cc1750b831
        // Status of entity 264fe2e6-b879-47a4-9f22-d706fb94b5aa changed to 58390eda-38bf-43a0-ba33-48cc1750b831
    }

    private static void StatusMapOnOnStatusChanged(object sender, StatusArgs e)
    {
        foreach (var change in e.Changes)
        {
            foreach (var statusInfo in change.Value)
            {
                Console.WriteLine($"Status of entity {change.Key} changed to {statusInfo.Status}");
            }
        }
    }
}
See Also

Reference

StatusMap Class
Gamanet.C4.SDK Namespace