MessagePump.Send Method

For sending commands

Namespace: Gamanet.C4.SDK
Assembly: Gamanet.C4.SimpleClient (in Gamanet.C4.SimpleClient.dll) Version: 2026.0.0.733
Syntax
C#
public bool Send(
	MessageV1 message
)

Parameters

message  MessageV1
The message.

Return Value

Boolean
True if successful; otherwise false.

Implements

ISimpleClientMessagePumpV1.Send(MessageV1)
Example
The following example illustrates how to send the command to concrete device.
C#
using Gamanet.C4.SDK;
using Gamanet.C4.SDK.Enums.Devices;
using Gamanet.C4.SimpleInterfaces;
using SCExampleCore;
using System;

public class SendCommandToAllPossibleDevicesInSubtree 
{
    static void Main()
    {
        // create instance of simple clients
        var client1 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        var client2 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        ConnectionInfo token;

        // connect to local server
        var connectionResult = client1.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        var connectionResult1 = client2.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        if (connectionResult != ConnectionResult.Successful &&  connectionResult1 != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unSuccessful, result: {0}", connectionResult);
            return;
        }

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

        // new device tree
        var busControllerDevice = new SimpleDevice(Guid.NewGuid(), "Bus Controller", EntityRoot.Device,
            Guid.Parse("EF10235E-5FB3-4B47-ABEA-FCB5498A162F"));
        var panel1 = new SimpleDevice(Guid.NewGuid(), "EDGE EVE E440 Sector 1", busControllerDevice.Id,
            Guid.Parse("B71C7322-D43F-47BF-BE6A-1BD0A0D79254"));
        var door1 = new SimpleDevice(Guid.NewGuid(), "Door 1", panel1.Id,
            Guid.Parse("F1AC242B-1FDA-43BB-AF37-5F7EBC38A7A0"));

        var door2 = new SimpleDevice(Guid.NewGuid(), "Door 2", panel1.Id,
            Guid.Parse("F1AC242B-1FDA-43BB-AF37-5F7EBC38A7A0"));

        // create devices
        client1.Devices.Create(busControllerDevice);
        client1.Devices.Create(panel1);
        client1.Devices.Create(door1);
        client1.Devices.Create(door2);

        // start handling message pump states
        client1.MessagePump.OnStateChanged += OnMessagePumpStateChanged;

        // start handling message pump incoming messages
        client2.MessagePump.OnMessage += OnMessage;

        // start message pump
        client1.MessagePump.Start();
        client2.MessagePump.Start();

        // create command
        var command = new SimpleCommand(
            Guid.NewGuid(), // new Id for command
            "Open Door",
            Guid.Empty,
            CommandCategory.Open); // category Id to specify command

        // id of device for which the command is intended
        command.Data["DeviceId"] = Guid.Parse("3D0BE21A-201E-49E9-ACBF-6A1840E51276");

        // create message for command
        var message = new Message(
            Guid.Empty,
            door1.Id,  // id of device for which the command is intended
            command);

        // send message
        client1.MessagePump.Send(message);

        Console.WriteLine("Command sent");

        // stop handling messages
        client2.MessagePump.OnMessage -= OnMessage;

        // stop message pump
        client1.MessagePump.Stop();
        client2.MessagePump.Stop();

        // stop handling message pump statuses
        client1.MessagePump.OnStateChanged -= OnMessagePumpStateChanged;

        // disconnect from server
        client1.Disconnect();
        client2.Disconnect();

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

        // Command sent
        // Message Pump state: Started
        // COMMAND Open Door | CommandCategory c73239f1-ee2a-458d-96b0-d253c85fd164
        // Message Pump state: Stopped
    }

    private static void OnMessage(object sender, MessageEventArgs e)
    {
        if (e.Message.CategoryId == MessageCategory.Status)
        {
            var status = (SimpleStatus)e.Message.SimpleEntity;
            Console.WriteLine("STATUS: {0}", status.Name);
        }
        else if (e.Message.CategoryId == MessageCategory.Command)
        {
            var sc = (SimpleCommand)e.Message.SimpleEntity;
            Console.WriteLine($"COMMAND  {sc.Name}  CommandCategory {sc.CategoryId}");
        }
    }

    private static void OnMessagePumpStateChanged(object sender, MessagePumpStateChangedEventArgs e)
    {
        Console.WriteLine("Message Pump state: {0}", e.MessagePumpState);
    }
}
The following example illustrates how to send the status to concrete device.
C#
using Gamanet.C4.SDK;
using Gamanet.C4.SDK.Enums.Devices;
using Gamanet.C4.SimpleInterfaces;
using SCExampleCore;
using System;

public class SendStatus{

    static void Main()
    {
        // create instance of simple client
        var client1 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        var client2 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        ConnectionInfo token;

        // connect to local server
        var connectionResult = client1.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        var connectionResult1 = client2.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        if (connectionResult != ConnectionResult.Successful && connectionResult1 != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unSuccessful, result: {0}", connectionResult);
            return;
        }

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

        // new device tree
        var busConrtollerDevice = new SimpleDevice(Guid.NewGuid(), "Bus Controller", EntityRoot.Device,
            Guid.Parse("D81A3534-CA3F-4998-A8AC-473143DA521E"));
        var panel = new SimpleDevice(Guid.NewGuid(), "EDGE EVE E440 Sector 1", busConrtollerDevice.Id,
            Guid.Parse("3C684E0C-AF67-4129-89AA-833C0F466032"));
        var door = new SimpleDevice(Guid.NewGuid(), "Door", panel.Id,
            Guid.Parse("0940228b-69c9-4d0a-a804-1e96c82568e3"));

        // create devices
        client1.Devices.Create(busConrtollerDevice);
        client1.Devices.Create(panel);
        client1.Devices.Create(door);

        // start handling message pump statuses
        client1.MessagePump.OnStateChanged += OnMessagePumpStateChanged;

        // start message pump
        client1.MessagePump.Start();
        client2.MessagePump.Start();

        // start handling message pump incoming messages
        client2.MessagePump.OnMessage += OnMessage;

        // create status
        var status = new SimpleStatus(Guid.NewGuid(), "Opened", Guid.Empty, DeviceStatusCategory.Opened);
        status.Data["DeviceId"] = door.Id;

        // create message for status
        var message = new Message(
            Guid.Empty,
            Guid.Empty,
            status); // status for transfer

        // send message
        client1.MessagePump.Send(message);

        Console.WriteLine("Status sent");

        // stop handling messages
        client1.MessagePump.OnMessage -= OnMessage;

        // stop message pump
        client1.MessagePump.Stop();
        client2.MessagePump.Stop();

        // stop handling message pump statuses
        client1.MessagePump.OnStateChanged -= OnMessagePumpStateChanged;

        // disconnect from server
        client1.Disconnect();
        client2.Disconnect();

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

        // Status sent
        // Message Pump state: Started
        // STATUS  Opened | StatusCategory 6eda6590-3606-48dc-a2f1-58724d7b1b4f
        // Message Pump state: Stopped
        Console.ReadLine();
    }

    private static void OnMessage(object sender, MessageEventArgs e)
    {
        if (e.Message.CategoryId == MessageCategory.Status)
        {
            var status = (SimpleStatus)e.Message.SimpleEntity;
            Console.WriteLine($"STATUS  {status.Name} | StatusCategory {status.CategoryId}");
        }
        else if (e.Message.CategoryId == MessageCategory.Command)
        {
            var sc = (SimpleCommand)e.Message.SimpleEntity;
            Console.WriteLine($"COMMAND  {sc.Name} | CommandCategory {sc.CategoryId}");
        }
        else if (e.Message.CategoryId == MessageCategory.Log)
        {
            var sc = (SimpleLog)e.Message.SimpleEntity;
            Console.WriteLine($"LOG  {sc.Name} | LogCategory {sc.CategoryId}");
        }
    }

    private static void OnMessagePumpStateChanged(object sender, MessagePumpStateChangedEventArgs e)
    {
        Console.WriteLine("Message Pump state: {0}", e.MessagePumpState);
    }
}
The following example illustrates how to send the log.
C#
using SCExampleCore;
using System;
using System.Collections.Generic;
using Gamanet.C4.SDK;
using Gamanet.C4.SDK.Enums.Logs;
using Gamanet.C4.SDK.Enums.Persons
using Gamanet.C4.SimpleInterfaces;

public class SendLog : ExampleBase 
{ 
    public static void Main()
    {
        // create instance of simple client
        var client1 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        var client2 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        ConnectionInfo token;

        // connect to local server
        var connectionResult = client1.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        var connectionResult1 = client2.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        if (connectionResult != ConnectionResult.Successful && connectionResult1 != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unSuccessful, result: {0}", connectionResult);
            return;
        }

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

        // new device tree
        var busConrtollerDevice = new SimpleDevice(Guid.NewGuid(), "Bus Controller", EntityRoot.Device,
            Guid.Parse("D81A3534-CA3F-4998-A8AC-473143DA521E"));
        var panel = new SimpleDevice(Guid.NewGuid(), "EDGE EVE E440 Sector 1", busConrtollerDevice.Id,
            Guid.Parse("3C684E0C-AF67-4129-89AA-833C0F466032"));
        var door = new SimpleDevice(Guid.NewGuid(), "Door", panel.Id,
            Guid.Parse("0940228b-69c9-4d0a-a804-1e96c82568e3"));

        // create devices
        client1.Devices.Create(busConrtollerDevice);
        client1.Devices.Create(panel);
        client1.Devices.Create(door);

        // create new person under person root
        var person = new SimplePerson(
            Guid.NewGuid(),
            "Johnson",
            EntityRoot.Person,
            PersonCategory.Person);

        person.Data["Surname"] = "Luck";

        // create person in db
        client1.Persons.Create(person);

        // start handling message pump statuses
        client1.MessagePump.OnStateChanged += OnMessagePumpStateChanged;

        // start message pump
        client1.MessagePump.Start();
        client2.MessagePump.Start();

        // start handling message pump incoming messages
        client2.MessagePump.OnMessage += OnMessage;

        // create log
        var log = new SimpleLog(Guid.NewGuid(), "", Guid.Empty, LogCategory.DoorOpened)
        {
            Data = new Dictionary<string, object>()
            {
                ["CategoryId"] = door.CategoryId,
                ["ParentId"] = door.ParentId,
                ["DeviceIdName"] = door.Name,
                ["DeviceId"] = door.Id,
                ["PersonIdName"] = person.Name
            }
        };

        // create message for log
        var message = new Message(
            Guid.Empty,
            Guid.Empty,
            log); // log for transfer

        // send message
        client1.MessagePump.Send(message);

        Console.WriteLine("Log sent");

        // stop handling messages
        client1.MessagePump.OnMessage -= OnMessage;

        // stop message pump
        client1.MessagePump.Stop();
        client2.MessagePump.Stop();

        // stop handling message pump statuses
        client1.MessagePump.OnStateChanged -= OnMessagePumpStateChanged;

        // disconnect from server
        client1.Disconnect();
        client2.Disconnect();

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

        // Log sent
        // Message Pump state: Started
        // LOG  'Door' opened by 'Johnson'. | LogCategory 8cbda41e - 753f - 46f3 - aa4c - f3468109b9e7
        // Message Pump state: Stopped
        Console.ReadLine();
    }

    private static void OnMessage(object sender, MessageEventArgs e)
    {
        if (e.Message.CategoryId == MessageCategory.Status)
        {
            var status = (SimpleStatus)e.Message.SimpleEntity;
            Console.WriteLine($"STATUS  {status.Name} | StatusCategory {status.CategoryId}");
        }
        else if (e.Message.CategoryId == MessageCategory.Command)
        {
            var sc = (SimpleCommand)e.Message.SimpleEntity;
            Console.WriteLine($"COMMAND  {sc.Name} | CommandCategory {sc.CategoryId}");
        }
        else if (e.Message.CategoryId == MessageCategory.Log)
        {
            var sc = (SimpleLog)e.Message.SimpleEntity;
            Console.WriteLine($"LOG  {sc.Name} | LogCategory {sc.CategoryId}");
        }
    }

    private static void OnMessagePumpStateChanged(object sender, MessagePumpStateChangedEventArgs e)
    {
        Console.WriteLine("Message Pump state: {0}", e.MessagePumpState);
    }
 }
The following example illustrates how to send the command to all possible devices.
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SDK.Enums.Devices;
using Gamanet.C4.SDK.Enums.Core;
using Gamanet.C4.SimpleInterfaces;

public class SendCommandToAllPossibleDevices
{
    static void Main()
    {
        // create instance of simple clients
        var client1 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        var client2 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        ConnectionInfo token;

        // connect to local server
        var connectionResult = client1.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        var connectionResult1 = client2.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        if (connectionResult != ConnectionResult.Successful && connectionResult1 != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unSuccessful, result: {0}", connectionResult);
            return;
        }

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

        // new device tree
        var busControllerDevice = new SimpleDevice(Guid.NewGuid(), "Bus Controller", EntityRoot.Device,
            Guid.Parse("EF10235E-5FB3-4B47-ABEA-FCB5498A162F"));
        var panel1 = new SimpleDevice(Guid.NewGuid(), "EDGE EVE E440 Sector 1", busControllerDevice.Id,
            Guid.Parse("B71C7322-D43F-47BF-BE6A-1BD0A0D79254"));
        var door1 = new SimpleDevice(Guid.NewGuid(), "Door", panel1.Id,
            Guid.Parse("F1AC242B-1FDA-43BB-AF37-5F7EBC38A7A0"));

        var panel2 = new SimpleDevice(Guid.NewGuid(), "EDGE EVE E440 Sector 2", busControllerDevice.Id,
            Guid.Parse("B71C7322-D43F-47BF-BE6A-1BD0A0D79254"));

        // create devices
        client1.Devices.Create(busControllerDevice);
        client1.Devices.Create(panel1);
        client1.Devices.Create(door1);
        client1.Devices.Create(panel2);

        // start handling message pump states
        client1.MessagePump.OnStateChanged += OnMessagePumpStateChanged;

        // start handling message pump incoming messages
        client2.MessagePump.OnMessage += OnMessage;

        // start message pump
        client1.MessagePump.Start();
        client2.MessagePump.Start();

        // use this destination Id, if you want to send command to all devices that supports this command
        var serverDestinationId = MessageDestinations.Server;

        // create command
        var command = new SimpleCommand(
            Guid.NewGuid(), // new Id for command
            "Reset panel",
            Guid.Empty,
            CommandCategory.Reset); // category Id to specify command

        // is required data option to use destination Id
        command.Data["IsBulkCommand"] = true;

        // create message for command
        var message = new Message(
            Guid.Empty,
            serverDestinationId,
            command);

        // send message
        client1.MessagePump.Send(message);

        Console.WriteLine("Command sent");

        // stop handling messages
        client2.MessagePump.OnMessage -= OnMessage;

        // stop message pump
        client1.MessagePump.Stop();
        client2.MessagePump.Stop();

        // stop handling message pump statuses
        client1.MessagePump.OnStateChanged -= OnMessagePumpStateChanged;

        // disconnect from server
        client1.Disconnect();
        client2.Disconnect();

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

        // Command sent
        // Message Pump state: Started
        // COMMAND  Reset panel | CommandCategory f43c79d9-8dd5-46e8-aaad-6e4bc3b4d8a3
        // COMMAND  Reset panel | CommandCategory f43c79d9-8dd5-46e8-aaad-6e4bc3b4d8a3
        // Message Pump state: Stopped
    }

    private static void OnMessage(object sender, MessageEventArgs e)
    {
        if (e.Message.CategoryId == MessageCategory.Status)
        {
            var status = (SimpleStatus)e.Message.SimpleEntity;
            Console.WriteLine("STATUS: {0}", status.Name);
        }
        else if (e.Message.CategoryId == MessageCategory.Command)
        {
            var sc = (SimpleCommand)e.Message.SimpleEntity;
            Console.WriteLine($"COMMAND  {sc.Name}  CommandCategory {sc.CategoryId}");
        }
    }

    private static void OnMessagePumpStateChanged(object sender, MessagePumpStateChangedEventArgs e)
    {
        Console.WriteLine("Message Pump state: {0}", e.MessagePumpState);
    }
}
The following example illustrates how to send the command to all possible devices in subtree.
C#
using Gamanet.C4.SDK;
using Gamanet.C4.SDK.Enums.Devices;
using Gamanet.C4.SimpleInterfaces;
using SCExampleCore;
using System;

public class SendCommandToAllPossibleDevicesInSubtree 
{
    static void Main()
    {
        // create instance of simple clients
        var client1 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        var client2 = new SimpleClient(ConnectorConfiguration.HttpClient, null);
        ConnectionInfo token;

        // connect to local server
        var connectionResult = client1.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        var connectionResult1 = client2.Connect(new Uri("https://localhost/"), "Support", "support", out token);
        if (connectionResult != ConnectionResult.Successful &&  connectionResult1 != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unSuccessful, result: {0}", connectionResult);
            return;
        }

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

        // new device tree
        var busControllerDevice = new SimpleDevice(Guid.NewGuid(), "Bus Controller", EntityRoot.Device,
            Guid.Parse("EF10235E-5FB3-4B47-ABEA-FCB5498A162F"));
        var panel1 = new SimpleDevice(Guid.NewGuid(), "EDGE EVE E440 Sector 1", busControllerDevice.Id,
            Guid.Parse("B71C7322-D43F-47BF-BE6A-1BD0A0D79254"));
        var door1 = new SimpleDevice(Guid.NewGuid(), "Door 1", panel1.Id,
            Guid.Parse("F1AC242B-1FDA-43BB-AF37-5F7EBC38A7A0"));

        var door2 = new SimpleDevice(Guid.NewGuid(), "Door 2", panel1.Id,
            Guid.Parse("F1AC242B-1FDA-43BB-AF37-5F7EBC38A7A0"));

        // create devices
        client1.Devices.Create(busControllerDevice);
        client1.Devices.Create(panel1);
        client1.Devices.Create(door1);
        client1.Devices.Create(door2);

        // start handling message pump states
        client1.MessagePump.OnStateChanged += OnMessagePumpStateChanged;

        // start handling message pump incoming messages
        client2.MessagePump.OnMessage += OnMessage;

        // start message pump
        client1.MessagePump.Start();
        client2.MessagePump.Start();

        // create command
        var command = new SimpleCommand(
            Guid.NewGuid(), // new Id for command
            "Open Door",
            Guid.Empty,
            CommandCategory.Open); // category Id to specify command

        // is required data option to use destination Id
        command.Data["IsBulkCommand"] = true;

        // create message for command
        var message = new Message(
            Guid.Empty,
            busControllerDevice.Id,  // DestinationId is rootId of subtree
            command);

        // send message
        client1.MessagePump.Send(message);

        Console.WriteLine("Command sent");

        // stop handling messages
        client2.MessagePump.OnMessage -= OnMessage;

        // stop message pump
        client1.MessagePump.Stop();
        client2.MessagePump.Stop();

        // stop handling message pump statuses
        client1.MessagePump.OnStateChanged -= OnMessagePumpStateChanged;

        // disconnect from server
        client1.Disconnect();
        client2.Disconnect();

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

        // Command sent
        // Message Pump state: Started
        // COMMAND Open Door | CommandCategory c73239f1-ee2a-458d-96b0-d253c85fd164
        // COMMAND Open Door | CommandCategory c73239f1-ee2a-458d-96b0-d253c85fd164
        // Message Pump state: Stopped
    }

    private static void OnMessage(object sender, MessageEventArgs e)
    {
        if (e.Message.CategoryId == MessageCategory.Status)
        {
            var status = (SimpleStatus)e.Message.SimpleEntity;
            Console.WriteLine("STATUS: {0}", status.Name);
        }
        else if (e.Message.CategoryId == MessageCategory.Command)
        {
            var sc = (SimpleCommand)e.Message.SimpleEntity;
            Console.WriteLine($"COMMAND  {sc.Name}  CommandCategory {sc.CategoryId}");
        }
    }

    private static void OnMessagePumpStateChanged(object sender, MessagePumpStateChangedEventArgs e)
    {
        Console.WriteLine("Message Pump state: {0}", e.MessagePumpState);
    }
}
See Also

Reference

MessagePump Class
Gamanet.C4.SDK Namespace
MessageV1
MessageCategory
SimpleLogV1
SimpleStatusV1
SimpleCommandV1