The following sample code shows how to create a device group and add a device to the device group.
DeviceManagerProxy dmp = new DeviceManagerProxy("localhost");
//create a device group with name TestDeviceGroup
DeviceGroupDefinition dgd = new DeviceGroupDefinition("TestDeviceGroup", "This is a device group creating for testing device group related APIs");
dmp.CreateDeviceGroup(dgd, DeviceGroupDefinition.RootDeviceGroupName);
// add a device TestDevice, and add the device to the TestDeviceGroup in one call
TcpTransportSettings tts = new TcpTransportSettings("127.0.0.1", 7777);
ConnectionInformation ci = new ConnectionInformation("Contoso", tts);
UserDeviceInformation udi = new UserDeviceInformation(ci, null);
DeviceDefinition dd = new DeviceDefinition(udi, "TestDevice", null);
//add the device TestDevice with definition dd to the group named dbg.name, and keep it offline.
dmp.AddDevice(dd, dgd.Name, true);
//add a device TestDevice2 to the RootDeviceGroup, and then move the device to the TestDeviceGroup
TcpTransportSettings tts2 = new TcpTransportSettings("127.0.0.1", 8888);
ConnectionInformation ci2 = new ConnectionInformation("Contoso", tts2);
UserDeviceInformation udi2 = new UserDeviceInformation(ci2, null);
DeviceDefinition dd2 = new DeviceDefinition(udi2, "TestDevice2", null);
//add the device TestDevice2 with definition dd to the root device group, and keep it offline.
dmp.AddDevice(dd2, DeviceGroupDefinition.RootDeviceGroupName, true);
//move the device to the TestDeviceGroup
dmp.MoveEntityToDeviceGroup(dd2.Name, dgd.Name);