AlarmType? StateToAlarmType(DeviceDriverState state, Driver driver) { if (state.DriverState == null) { return null; } if (state.DriverState.IsAutomatic && (state.DriverState.Code.Contains("AutoOff") || state.DriverState.Code.Contains("Auto_Off") || state.DriverState.Code.Contains("Auto_off"))) return AlarmType.Auto; AlarmType? alarmType = null; switch (state.DriverState.StateType) { case StateType.Fire: return null; case StateType.Attention: if (state.DriverState.CanResetOnPanel == false) return null; alarmType = AlarmType.Attention; break; case StateType.Info: if (state.DriverState.CanResetOnPanel == false) return null; alarmType = AlarmType.Info; break; case StateType.Off: if (driver.CanDisable == false) return null; alarmType = AlarmType.Off; break; case StateType.Failure: alarmType = AlarmType.Failure; break; case StateType.Service: alarmType = AlarmType.Service; break; } return alarmType; }
void SetStates(Firesec.Models.CoreState.config coreState) { if (coreState == null) coreState = new Models.CoreState.config(); if (coreState.dev == null) coreState.dev = new Models.CoreState.devType[0]; foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { if (device.PlaceInTree == null) { Logger.Error("Watcher.SetStates deviceState.PlaceInTree = null"); continue; } bool hasOneChangedState = false; Firesec.Models.CoreState.devType innerDevice = FindDevice(coreState.dev, device.PlaceInTree); if (innerDevice != null) { if (device.Driver == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver = null"); continue; } if (device.Driver.States == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver.States = null"); continue; } if (innerDevice.state == null) { innerDevice.state = (new List<Firesec.Models.CoreState.stateType>()).ToArray(); } foreach (var driverState in device.Driver.States) { var innerState = innerDevice.state.FirstOrDefault(a => a.id == driverState.Id); var state = device.DeviceState.States.FirstOrDefault(x => x.DriverState.Code == driverState.Code); if ((state != null) != (innerState != null)) { hasOneChangedState = true; } if (innerState != null) { if (state == null) { var cloneddDiverState = driverState.Clone(); if (cloneddDiverState.Name == "Состояние 1") { var property = device.Properties.FirstOrDefault(x => x.Name == "Event1"); if (property != null && !string.IsNullOrEmpty(property.Value)) { cloneddDiverState.Name = property.Value; } } if (cloneddDiverState.Name == "Состояние 2") { var property = device.Properties.FirstOrDefault(x => x.Name == "Event2"); if (property != null && !string.IsNullOrEmpty(property.Value)) { cloneddDiverState.Name = property.Value; } } state = new DeviceDriverState() { DriverState = cloneddDiverState }; device.DeviceState.States.Add(state); } if (innerState.time != null) state.Time = JournalConverter.ConvertTime(innerState.time); else state.Time = null; } else { if (state != null) device.DeviceState.States.Remove(state); } } } else { hasOneChangedState = device.DeviceState.States.Count > 0; device.DeviceState.States.Clear(); } if (hasOneChangedState) { ChangedDevices.Add(device.DeviceState); } } }
void AddDeviceState(Device device, string stateName) { var state = device.Driver.States.FirstOrDefault(x => x.Name == stateName); if (state != null) { var deviceDriverState = new DeviceDriverState { DriverState = state, Time = DateTime.Now }; if (!device.DeviceState.States.Any(x => x.DriverState.Name == stateName)) device.DeviceState.States.Add(deviceDriverState); } }
void SetStates(Firesec.CoreState.config coreState) { if (ConfigurationCash.DeviceConfigurationStates == null) { Logger.Error("Watcher.SetStates FiresecManager.DeviceConfigurationStates = null"); return; } if (ConfigurationCash.DeviceConfigurationStates.DeviceStates == null) { Logger.Error("Watcher.SetStates FiresecManager.DeviceConfigurationStates.DeviceStates = null"); return; } foreach (var deviceState in ConfigurationCash.DeviceConfigurationStates.DeviceStates) { if (deviceState == null) { Logger.Error("Watcher.SetStates deviceState = null"); return; } if (coreState == null) { Logger.Error("Watcher.SetStates coreState = null"); return; } if (coreState.dev == null) { //Logger.Error("Watcher.SetStates coreState.dev = null"); return; } if (deviceState.PlaceInTree == null) { Logger.Error("Watcher.SetStates deviceState.PlaceInTree = null"); return; } bool hasOneChangedState = false; Firesec.CoreState.devType innerDevice = FindDevice(coreState.dev, deviceState.PlaceInTree); if (innerDevice != null) { if (deviceState.Device == null) { Logger.Error("Watcher.SetStates deviceState.Device = null"); return; } if (deviceState.Device.Driver == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver = null"); return; } if (deviceState.Device.Driver.States == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver.States = null"); return; } foreach (var driverState in deviceState.Device.Driver.States) { if (innerDevice.state == null) { Logger.Error("Watcher.SetStates innerDevice.state = null"); return; } var innerState = innerDevice.state.FirstOrDefault(a => a.id == driverState.Id); if (deviceState.States == null) { Logger.Error("Watcher.SetStates deviceState.States = null"); return; } var state = deviceState.States.FirstOrDefault(x => x.Code == driverState.Code); if ((state != null) != (innerState != null)) { hasOneChangedState = true; } if (innerState != null) { if (state == null) { state = new DeviceDriverState() { Code = driverState.Code, DriverState = driverState.Copy() }; deviceState.States.Add(state); } if (innerState.time != null) state.Time = JournalConverter.ConvertTime(innerState.time); else state.Time = null; } else { if (state != null) deviceState.States.Remove(state); } } } else { hasOneChangedState = deviceState.States.Count > 0; deviceState.States.Clear(); } if (hasOneChangedState) { ChangedDevices.Add(deviceState); } } }
void UpdateFireOrWarning(Device device) { var changedDevices = new List<Device>(); var zone = device.Zone; if (zone == null || zone.ZoneType == ZoneType.Guard) return; var hasHandDetectorInFire = false; var fireCount = 0; var warningCount = 0; foreach (var deviceInZone in zone.DevicesInZone) { var attentionState = deviceInZone.DeviceState.States.FirstOrDefault(x => x.DriverState.StateType == StateType.Attention); var fireState = deviceInZone.DeviceState.States.FirstOrDefault(x => x.DriverState.StateType == StateType.Fire); if (attentionState != null && fireState != null) { deviceInZone.DeviceState.States.Remove(attentionState); changedDevices.Add(deviceInZone); } } foreach (var deviceInZone in zone.DevicesInZone) { if (deviceInZone.Driver.DriverType == DriverType.HandDetector || deviceInZone.Driver.DriverType == DriverType.HandDetector) { if (deviceInZone.DeviceState.StateType == StateType.Fire) { hasHandDetectorInFire = true; break; } } else { if (deviceInZone.DeviceState.StateType == StateType.Fire) { fireCount++; } if (deviceInZone.DeviceState.StateType == StateType.Attention) { warningCount++; } } } if (!hasHandDetectorInFire) { if (fireCount == 0 && warningCount > 1) { foreach (var deviceInZone in zone.DevicesInZone) { if (deviceInZone.DeviceState.StateType == StateType.Attention) { deviceInZone.DeviceState.States.RemoveAll(x => x.DriverState.StateType == StateType.Attention); var driverState = deviceInZone.Driver.States.FirstOrDefault(x => x.StateType == StateType.Fire); var deviceDriverState = new DeviceDriverState() { DriverState = driverState, Time = DateTime.Now }; if (deviceDriverState != null) { deviceInZone.DeviceState.States.Add(deviceDriverState); changedDevices.Add(deviceInZone); } } } } } foreach (var changedDevice in changedDevices) { ForseUpdateDeviceStates(changedDevice); } }
public bool SetNewDeviceStates(Device device, List<DeviceDriverState> newStates) { var hasChanges = false; foreach (var state in newStates) { if (!device.DeviceState.States.Any(x => x.DriverState.Code == state.DriverState.Code)) { var driverState = device.Driver.States.FirstOrDefault(x => x.Code == state.DriverState.Code); if (driverState != null) { var deviceDriverState = new DeviceDriverState() { DriverState = driverState, Time = DateTime.Now }; device.DeviceState.States.Add(deviceDriverState); hasChanges = true; } } } var satesToRemove = new List<DeviceDriverState>(); foreach (var state in device.DeviceState.States) { if (!newStates.Any(x => x.DriverState.Id == state.DriverState.Id)) { satesToRemove.Add(state); } } var removedCount = device.DeviceState.States.RemoveAll(x => satesToRemove.Any(y => x.DriverState.Id == y.DriverState.Id)); if (removedCount > 0) hasChanges = true; return hasChanges; }
void ParceDeviceStateEnterLeave(FS2JournalItem journalItem, Device device, bool isDevice) { var metadataDeviceStates = MetadataHelper.GetMetadataDeviceStates(device, true); foreach (var metadataDeviceState in metadataDeviceStates) { if (metadataDeviceState.enter != null) { foreach (var deviceStateEnter in metadataDeviceState.enter) { string eventValue = null; if (isDevice) { eventValue = MetadataHelper.GetDeviceStateEventEnter(deviceStateEnter, journalItem.AdditionalEventCode); } else { eventValue = MetadataHelper.GetZoneStateEventEnter(deviceStateEnter, journalItem.AdditionalEventCode); } if (eventValue != null) { if (eventValue == "$" + journalItem.EventCode.ToString("X2")) { var driverState = device.Driver.States.FirstOrDefault(x => x.Code == metadataDeviceState.ID); if (driverState != null) { if (!device.DeviceState.States.Any(x => x.DriverState != null && x.DriverState.Code == driverState.Code)) { var deviceDriverState = new DeviceDriverState() { DriverState = driverState, Time = DateTime.Now }; device.DeviceState.States.Add(deviceDriverState); ForseUpdateDeviceStates(device); } } } } } } if (metadataDeviceState.leave != null) { foreach (var deviceStateLeave in metadataDeviceState.leave) { string eventValue = null; if (isDevice) { eventValue = MetadataHelper.GetDeviceStateEventLeave(deviceStateLeave, journalItem.AdditionalEventCode); } else { eventValue = MetadataHelper.GetZoneStateEventLeave(deviceStateLeave, journalItem.AdditionalEventCode); } if (eventValue != null) { if (eventValue == "$" + journalItem.EventCode.ToString("X2")) { var driverState = device.Driver.States.FirstOrDefault(x => x.Code == metadataDeviceState.ID); if (driverState != null) { var deviceDriverState = device.DeviceState.States.FirstOrDefault(x => x.DriverState.Code == driverState.Code); if (deviceDriverState != null) { device.DeviceState.States.Remove(deviceDriverState); ForseUpdateDeviceStates(device); } } } } } } } UpdateDeviceStateAndParameters(device); }
void SetStateFromMetadata(Device device, driverConfigDeviceStatesDeviceState metadataDeviceState, bool hasBit) { if (metadataDeviceState.inverse == "1") hasBit = !hasBit; if (hasBit) { if (!device.DeviceState.States.Any(x => x.DriverState.Code == metadataDeviceState.ID)) { var driverState = device.Driver.States.FirstOrDefault(x => x.Code == metadataDeviceState.ID); if (driverState != null) { var deviceDriverState = new DeviceDriverState() { DriverState = driverState, Time = DateTime.Now }; device.DeviceState.States.Add(deviceDriverState); ForseUpdateDeviceStates(device); } } } else { if (device.DeviceState.States.RemoveAll(x => x.DriverState.Code == metadataDeviceState.ID) > 0) ForseUpdateDeviceStates(device); } }
void AddStateByName(string stateName) { var driverState = ConfigurationManager.DriversConfiguration.Drivers.FirstOrDefault(x => x.DriverType == PanelDevice.Driver.DriverType).States.FirstOrDefault(x => x != null && x.Name == stateName); if (driverState == null) return; var deviceDriverState = new DeviceDriverState() { DriverState = driverState, Time = DateTime.Now }; PanelDevice.DeviceState.States.Add(deviceDriverState); DeviceStatesManager.ForseUpdateDeviceStates(PanelDevice); }