void PropogateStatesUp() { foreach (var deviceState in ConfigurationCash.DeviceConfigurationStates.DeviceStates) { if (deviceState.ChildStates == null) { Logger.Error("Watcher.PropogateStatesUp deviceState.ChildStates = null"); return; } deviceState.ChildStates.ForEach(x => x.IsDeleting = true); } foreach (var deviceState in ConfigurationCash.DeviceConfigurationStates.DeviceStates) { foreach (var state in deviceState.States) { if (deviceState.Device.Parent == null) continue; if (deviceState.Device.Parent.Driver.ChildAddressReserveRangeCount == 0 || state.DriverState.AffectParent == false) continue; var parentDevice = deviceState.Device.Parent; var parentDeviceState = ConfigurationCash.DeviceConfigurationStates.DeviceStates.FirstOrDefault(x => x.UID == parentDevice.UID); var childDeviceState = new ChildDeviceState() { ChildDeviceId = deviceState.UID, Code = state.Code, DriverState = state.DriverState, IsDeleting = false }; var existingParentDeviceState = parentDeviceState.ChildStates.FirstOrDefault(x => x.ChildDeviceId == childDeviceState.ChildDeviceId && x.Code == childDeviceState.Code && x.DriverState == childDeviceState.DriverState); if (existingParentDeviceState == null) { parentDeviceState.ChildStates.Add(childDeviceState); Trace.WriteLine(parentDeviceState.Device.PresentationAddressAndDriver + " " + childDeviceState.DriverState.Name); ChangedDevices.Add(parentDeviceState); } else { existingParentDeviceState.IsDeleting = false; } } } foreach (var deviceState in ConfigurationCash.DeviceConfigurationStates.DeviceStates) { for (int i = deviceState.ChildStates.Count(); i > 0; i--) { var childState = deviceState.ChildStates[i - 1]; if (childState.IsDeleting) { deviceState.ChildStates.RemoveAt(i - 1); ChangedDevices.Add(deviceState); } } } }
void PropogateStatesUp() { foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { if (device.DeviceState.ChildStates == null) { Logger.Error("Watcher.PropogateStatesUp deviceState.ChildStates = null"); return; } device.DeviceState.ChildStates.ForEach(x => x.IsDeleting = true); } foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { if (device.Driver.ChildAddressReserveRangeCount == 0) continue; ChildDeviceState childDeviceState = null; var minChildStateType = StateType.Norm; foreach (var child in device.Children) { if (child.DeviceState.StateType < minChildStateType) { minChildStateType = child.DeviceState.StateType; childDeviceState = new ChildDeviceState() { ChildDevice = device, StateType = minChildStateType, IsDeleting = false }; } } if (childDeviceState == null) continue; var existingDeviceState = device.DeviceState.ChildStates.FirstOrDefault(x => x.ChildDevice.UID == childDeviceState.ChildDevice.UID && x.StateType == childDeviceState.StateType); if (existingDeviceState == null) { device.DeviceState.ChildStates.Add(childDeviceState); ChangedDevices.Add(device.DeviceState); } else { existingDeviceState.IsDeleting = false; } } foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { for (int i = device.DeviceState.ChildStates.Count(); i > 0; i--) { var childState = device.DeviceState.ChildStates[i - 1]; if (childState.IsDeleting) { device.DeviceState.ChildStates.RemoveAt(i - 1); ChangedDevices.Add(device.DeviceState); } } } }
void PropogateStatesUp() { foreach (var device in ConfigurationManager.Devices) { device.DeviceState.ChildStates.ForEach(x => x.IsDeleting = true); } foreach (var device in ConfigurationManager.Devices) { if (device.Driver.ChildAddressReserveRangeCount == 0) continue; ChildDeviceState childDeviceState = null; var minChildStateType = StateType.Norm; foreach (var child in device.Children) { if (child.DeviceState.StateType < minChildStateType) { minChildStateType = child.DeviceState.StateType; childDeviceState = new ChildDeviceState() { ChildDeviceUID = device.UID, ChildDevice = device, StateType = minChildStateType, IsDeleting = false }; } } if (childDeviceState != null) { var existingDeviceState = device.DeviceState.ChildStates.FirstOrDefault(x => x.ChildDevice.UID == childDeviceState.ChildDevice.UID && x.StateType == childDeviceState.StateType); if (existingDeviceState == null) { device.DeviceState.ChildStates.Add(childDeviceState); ChangedDeviceStates.Add(device.DeviceState); } else { existingDeviceState.IsDeleting = false; } } } foreach (var device in ConfigurationManager.Devices) { var removedCount = device.DeviceState.ChildStates.RemoveAll(x => x.IsDeleting); if (removedCount > 0) { ChangedDeviceStates.Add(device.DeviceState); } } }