void PropogateStatesDown() { foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { device.DeviceState.ParentStates.ForEach(x => x.IsDeleting = true); } foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { foreach (var state in device.DeviceState.States.Where(x => x.DriverState.AffectChildren)) { foreach (var childDevice in ConfigurationCash.DeviceConfiguration.Devices) { if (childDevice.PlaceInTree == null) { Logger.Error("Watcher.PropogateStatesDown chilDevice.PlaceInTree = null"); continue; } if ((childDevice.PlaceInTree + "/").StartsWith(device.PlaceInTree) && childDevice.PlaceInTree != device.PlaceInTree) { var parentDeviceState = new ParentDeviceState() { ParentDevice = device, DriverState = state.DriverState, IsDeleting = false }; var existingParentDeviceState = childDevice.DeviceState.ParentStates.FirstOrDefault(x => x.ParentDevice.UID == parentDeviceState.ParentDevice.UID && x.DriverState.Code == parentDeviceState.DriverState.Code && x.DriverState == parentDeviceState.DriverState); if (existingParentDeviceState == null) { childDevice.DeviceState.ParentStates.Add(parentDeviceState); ChangedDevices.Add(childDevice.DeviceState); } else { existingParentDeviceState.IsDeleting = false; } } } } } foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { for (int i = device.DeviceState.ParentStates.Count(); i > 0; i--) { var parentState = device.DeviceState.ParentStates[i - 1]; if (parentState.IsDeleting) { device.DeviceState.ParentStates.RemoveAt(i - 1); ChangedDevices.Add(device.DeviceState); } } } }
void PropogateStatesDown() { foreach (var device in ConfigurationManager.Devices) { device.DeviceState.ParentStates.ForEach(x => x.IsDeleting = true); } foreach (var device in ConfigurationManager.Devices) { foreach (var state in device.DeviceState.States.Where(x => x.DriverState.AffectChildren)) { var allChildren = device.GetAllChildren(); foreach (var childDevice in allChildren) { var parentDeviceState = new ParentDeviceState() { ParentDeviceUID = device.UID, ParentDevice = device, DriverState = state.DriverState, IsDeleting = false }; var existingParentDeviceState = childDevice.DeviceState.ParentStates.FirstOrDefault(x => x.ParentDevice.UID == parentDeviceState.ParentDevice.UID && x.DriverState.Code == parentDeviceState.DriverState.Code && x.DriverState == parentDeviceState.DriverState); if (existingParentDeviceState == null) { childDevice.DeviceState.ParentStates.Add(parentDeviceState); ChangedDeviceStates.Add(childDevice.DeviceState); } else { existingParentDeviceState.IsDeleting = false; } } } } foreach (var device in ConfigurationManager.Devices) { var removedCount = device.DeviceState.ParentStates.RemoveAll(x => x.IsDeleting); if (removedCount > 0) { ChangedDeviceStates.Add(device.DeviceState); } } }