DeviceRepository.Restore Method

Restore existing devices by restore mode.

Namespace: Gamanet.C4.SDK
Assembly: Gamanet.C4.SimpleClient (in Gamanet.C4.SimpleClient.dll) Version: 2026.0.0.733
Syntax
C#
public void Restore(
	SimpleDeviceV1 device,
	RestoreMode restoreMode
)

Parameters

device  SimpleDeviceV1
The device.
restoreMode  RestoreMode
The restore mode

Implements

ISimpleClientDeviceRepositoryV1.Restore(SimpleDeviceV1, RestoreMode)
Example
The following example illustrates how the SimpleClient restores device with parents.
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

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

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

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

        // You need to have installed the Demo Access Device package from https://my.c4portal.com/plugins/
        var exampleBusCategory = client.EntityDefinitions.Get(Guid.Parse("4810e0c6-9391-490c-a646-ca9643dd1ca5")).Id;
        var examplePanelCategory = client.EntityDefinitions.Get(Guid.Parse("822caeea-b66b-4f60-ab43-bc14240cb6ec")).Id;
        var exampleDoorCategory = client.EntityDefinitions.Get(Guid.Parse("dcd0cea7-8de9-4458-afa7-cd1e94b56028")).Id;

        // Create the Example Device (Bus Controller)
        var exampleBusController = new SimpleDeviceV1(
            Guid.NewGuid(),
            "BUS",
            EntityRoot.Device,
            exampleBusCategory
        );

        // Create the Example Device (Panel)
        var examplePanel = new SimpleDeviceV1(
            Guid.NewGuid(),
            "PANEL",
            exampleBusController.Id,
            examplePanelCategory
        );

        // Create the Example Device (Door)
        var exampleDoor = new SimpleDeviceV1(
            Guid.NewGuid(),
            "DOOR",
            examplePanel.Id,
            exampleDoorCategory
        );
        // Create devices in db
        client.Devices.Create(exampleBusController);
        client.Devices.Create(examplePanel);
        client.Devices.Create(exampleDoor);

        // Archive device tree
        client.Devices.Archive(exampleBusController);

        // Check if all devices are archived
        var allDevices = client.Devices.GetAll(exampleBusController.Id, Properties.All, true);
        foreach ( var device in allDevices)
        {
            Console.WriteLine($"Device name {device.Name}. Archived: {device.Archived}");
        }

        // Get the device to restore
        var deviceExampleToRestore = SimpleClientV1.Devices.Get(examplePanel.Id, Properties.None);

        client.Devices.Restore(deviceExampleToRestore, RestoreMode.WithParents);

        var result = client.Devices.GetAll(EntityRoot.DeviceSuperRoot, Properties.All, true);

        foreach ( var device in result)
        {
            Console.WriteLine($"{device.Name} => Archived: {device.Archived}");
        }

        // Disconnect from server
        client.Disconnect();
    }
}
The following example illustrates how the SimpleClient restores device with children.
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

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

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

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

        // You need to have installed the Demo Access Device package from https://my.c4portal.com/plugins/
        var exampleBusCategory = client.EntityDefinitions.Get(Guid.Parse("4810e0c6-9391-490c-a646-ca9643dd1ca5")).Id;
        var examplePanelCategory = client.EntityDefinitions.Get(Guid.Parse("822caeea-b66b-4f60-ab43-bc14240cb6ec")).Id;
        var exampleDoorCategory = client.EntityDefinitions.Get(Guid.Parse("dcd0cea7-8de9-4458-afa7-cd1e94b56028")).Id;

        // Create the Example Device (Bus Controller)
        var exampleBusController = new SimpleDeviceV1(
            Guid.NewGuid(),
            "BUS",
            EntityRoot.Device,
            exampleBusCategory
        );

        // Create the Example Device (Panel)
        var examplePanel = new SimpleDeviceV1(
            Guid.NewGuid(),
            "PANEL",
            exampleBusController.Id,
            examplePanelCategory
        );

        // Create the Example Device (Door)
        var exampleDoor = new SimpleDeviceV1(
            Guid.NewGuid(),
            "DOOR",
            examplePanel.Id,
            exampleDoorCategory
        );
        // Create devices in db
        client.Devices.Create(exampleBusController);
        client.Devices.Create(examplePanel);
        client.Devices.Create(exampleDoor);

        // Archive device tree
        client.Devices.Archive(exampleBusController);

        // Check if all devices are archived
        var allDevices = client.Devices.GetAll(exampleBusController.Id, Properties.All, true);
        foreach (var device in allDevices)
        {
            Console.WriteLine($"Device name {device.Name}. Archived: {device.Archived}");
        }

        // Get the device to restore
        var deviceExampleToRestore = SimpleClientV1.Devices.Get(exampleBusController.Id, Properties.None);

        client.Devices.Restore(deviceExampleToRestore, RestoreMode.WithChildren);

        var result = client.Devices.GetAll(EntityRoot.DeviceSuperRoot, Properties.All, true);
        foreach ( var device in result )
        {
            Console.WriteLine($"{device.Name} => Archived: {device.Archived}");
        }

        // Disconnect from server
        client.Disconnect();
    }
}
The following example illustrates how the SimpleClient restores a single device.
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

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

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

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

        // You need to have installed the Demo Access Device package from https://my.c4portal.com/plugins/
        var exampleBusCategory = client.EntityDefinitions.Get(Guid.Parse("4810e0c6-9391-490c-a646-ca9643dd1ca5")).Id;
        var examplePanelCategory = client.EntityDefinitions.Get(Guid.Parse("822caeea-b66b-4f60-ab43-bc14240cb6ec")).Id;
        var exampleDoorCategory = client.EntityDefinitions.Get(Guid.Parse("dcd0cea7-8de9-4458-afa7-cd1e94b56028")).Id;

        // Create the Example Device (Bus Controller)
        var exampleBusController = new SimpleDeviceV1(
            Guid.NewGuid(),
            "BUS",
            EntityRoot.Device,
            exampleBusCategory
        );

        // Create the Example Device (Panel)
        var examplePanel = new SimpleDeviceV1(
            Guid.NewGuid(),
            "PANEL",
            exampleBusController.Id,
            examplePanelCategory
        );

        // Create the Example Device (Door)
        var exampleDoor = new SimpleDeviceV1(
            Guid.NewGuid(),
            "DOOR",
            examplePanel.Id,
            exampleDoorCategory
        );
        // Create devices in db
        client.Devices.Create(exampleBusController);
        client.Devices.Create(examplePanel);
        client.Devices.Create(exampleDoor);

        // Archive device tree
        client.Devices.Archive(exampleBusController);

        // Check if all devices are archived
        var allDevices = client.Devices.GetAll(exampleBusController.Id, Properties.All, true);
        foreach (var device in allDevices)
        {
            Console.WriteLine($"Device name {device.Name}. Archived: {device.Archived}");
        }

        // Get the device to restore
        var deviceExampleToRestore = client.Devices.Get(exampleBusController.Id, Properties.None);

        // restore single device
        client.Devices.Restore(deviceExampleToRestore, RestoreMode.Single);

        var result = client.Devices.GetAll(EntityRoot.DeviceSuperRoot,Properties.All, true);
        foreach ( var device in result)
        {
            Console.WriteLine($"{device.Name} => Archived: {device.Archived}");
        }

        // Disconnect from server
        client.Disconnect();
    }
}
See Also

Reference

DeviceRepository Class
Gamanet.C4.SDK Namespace
SimpleDeviceV1
RestoreMode