public static DeviceViewModel AddDevice(GKDevice device, DeviceViewModel parentDeviceViewModel, bool isAddDevice = true, bool isStartList = false) { var deviceViewModel = new DeviceViewModel(device); if (isAddDevice) { if (isStartList) parentDeviceViewModel.AddChildFirst(deviceViewModel); else parentDeviceViewModel.AddChild(deviceViewModel); foreach (var childDevice in device.Children) { AddDevice(childDevice, deviceViewModel); } } else { parentDeviceViewModel.InsertChild(deviceViewModel); foreach (var childDevice in device.Children) { AddDevice(childDevice, deviceViewModel, !isAddDevice); } } return deviceViewModel; }
public static DeviceViewModel InsertDevice(XDevice device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device); parentDeviceViewModel.InsertChild(deviceViewModel); foreach (var childDevice in device.Children) { InsertDevice(childDevice, deviceViewModel); } if (device.Driver.IsGroupDevice) { var driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == device.Driver.GroupDeviceChildType); for (byte i = 0; i < device.Driver.GroupDeviceChildrenCount; i++) { var autoDevice = XManager.AddChild(device, driver, (byte)(device.IntAddress + i)); AddDevice(autoDevice, deviceViewModel); } } return deviceViewModel; }