public XDeviceViewModel AddDevice(XDevice xDevice, XDeviceViewModel parentDeviceViewModel) { var xDeviceViewModel = new XDeviceViewModel(xDevice, Devices); xDeviceViewModel.Parent = parentDeviceViewModel; var indexOf = Devices.IndexOf(parentDeviceViewModel); Devices.Insert(indexOf + 1, xDeviceViewModel); if (xDevice != null) foreach (var childDevice in xDevice.Children) { var childDeviceViewModel = AddDevice(childDevice, xDeviceViewModel); xDeviceViewModel.Children.Add(childDeviceViewModel); } return xDeviceViewModel; }
public XDeviceViewModel AddDevice(XDevice device, XDeviceViewModel parentDeviceViewModel) { var deviceViewModel = new XDeviceViewModel(device, Devices); deviceViewModel.Parent = parentDeviceViewModel; var indexOf = Devices.IndexOf(parentDeviceViewModel); Devices.Insert(indexOf + 1, deviceViewModel); if (device != null) foreach (var childDevice in device.Children) { if (childDevice.Driver.IsDeviceOnShleif || childDevice.Children.Count > 0) { var childDeviceViewModel = AddDevice(childDevice, deviceViewModel); deviceViewModel.Children.Add(childDeviceViewModel); } } return deviceViewModel; }
public DeviceDetailsViewModel() { Title = "Добавить устройство"; Devices = new ObservableCollection<XDeviceViewModel>(); var drivers = (from XDriver driver in XManager.Drivers select driver).ToList(); foreach (var driver in drivers) { if (!XManager.DeviceLibraryConfiguration.XDevices.Any(x => x.XDriverId == driver.UID) && (driver.IsPlaceable)) { var libraryXDevice = new LibraryXDevice() { Driver = driver, XDriverId = driver.UID }; var xdeviceViewModel = new XDeviceViewModel(libraryXDevice); Devices.Add(xdeviceViewModel); } } SelectedDevice = Devices.FirstOrDefault(); }
public LibraryViewModel() { AddDeviceCommand = new RelayCommand(OnAddDevice); RemoveDeviceCommand = new RelayCommand(OnRemoveDevice, CanRemoveDevice); AddStateCommand = new RelayCommand(OnAddState, CanAddState); RemoveStateCommand = new RelayCommand(OnRemoveState, CanRemoveState); Current = this; var devicesToRemove = new List<LibraryXDevice>(); foreach (var libraryXDevice in XManager.DeviceLibraryConfiguration.XDevices) { var driver = XManager.Drivers.FirstOrDefault(x => x.UID == libraryXDevice.XDriverId); if (driver != null) { libraryXDevice.Driver = driver; } else { //if (libraryXDevice.XDriverId.ToString() != "a7bb2fd0-0088-49ae-8c04-7d6fa22c79d6" && // libraryXDevice.XDriverId.ToString() != "64cb0ab4-d9be-4c71-94a1-cf24406daf92") { devicesToRemove.Add(libraryXDevice); Logger.Error("XLibraryViewModel.Initialize driver = null " + libraryXDevice.XDriverId.ToString()); } } } foreach (var libraryXDevice in devicesToRemove) { XManager.DeviceLibraryConfiguration.XDevices.RemoveAll(x => x == libraryXDevice); } if(devicesToRemove.Count > 0) ServiceFactory.SaveService.XLibraryChanged = true; var devices = from LibraryXDevice libraryXDevice in XManager.DeviceLibraryConfiguration.XDevices.Where(x => x.Driver != null) orderby libraryXDevice.Driver.DeviceClassName select libraryXDevice; Devices = new ObservableCollection<XDeviceViewModel>(); foreach (var device in devices) { var deviceViewModel = new XDeviceViewModel(device); Devices.Add(deviceViewModel); } SelectedDevice = Devices.FirstOrDefault(); }
public void Select(Guid deviceUID) { FillAllDevices(); var deviceViewModel = AllDevices.FirstOrDefault(x => x.Device.UID == deviceUID); if (deviceViewModel != null) deviceViewModel.ExpantToThis(); SelectedDevice = deviceViewModel; }
private void ExpandChild(XDeviceViewModel parentDeviceViewModel) { parentDeviceViewModel.IsExpanded = true; foreach (var deviceViewModel in parentDeviceViewModel.Children) ExpandChild(deviceViewModel); }
private void CollapseChild(XDeviceViewModel parentDeviceViewModel) { parentDeviceViewModel.IsExpanded = false; foreach (var deviceViewModel in parentDeviceViewModel.Children) CollapseChild(deviceViewModel); }
private void AddChildPlainDevices(XDeviceViewModel parentViewModel) { AllDevices.Add(parentViewModel); foreach (var childViewModel in parentViewModel.Children) AddChildPlainDevices(childViewModel); }
public void Update() { AllDevices.Clear(); Devices.Clear(); BuildTree(); if (Devices.Count > 0) { AddChildPlainDevices(Devices[0]); CollapseChild(Devices[0]); ExpandChild(Devices[0]); SelectedDevice = Devices[0]; } }