public XDevice() { UID = BaseUID;// Guid.NewGuid(); Children = new List<XDevice>(); Properties = new List<XProperty>(); DeviceProperties = new List<XProperty>(); ZoneUIDs = new List<Guid>(); DeviceLogic = new XDeviceLogic(); NSLogic = new XDeviceLogic(); PlanElementUIDs = new List<Guid>(); IsNotUsed = false; AllowMultipleVizualization = false; Zones = new List<XZone>(); Directions = new List<XDirection>(); DevicesInLogic = new List<XDevice>(); }
public XPumpStation() { UID = BaseUID; Delay = 10; Hold = 60; DelayRegime = DelayRegime.Off; NSPumpsCount = 1; NSDeltaTime = 15; StartLogic = new XDeviceLogic(); StopLogic = new XDeviceLogic(); AutomaticOffLogic = new XDeviceLogic(); InputDevices = new List<XDevice>(); InputZones = new List<XZone>(); InputDirections = new List<XDirection>(); NSDevices = new List<XDevice>(); NSDeviceUIDs = new List<Guid>(); }
public DeviceLogicViewModel(XDevice device, XDeviceLogic deviceLogic) { if (device.DriverType == XDriverType.System) Title = "Настройка логики"; else Title = "Настройка логики устройства " + device.PresentationName; Device = device; if (deviceLogic.Clauses.Count == 0) { deviceLogic.Clauses.Add(new XClause()); } OnLogicViewModel = new LogicViewModel(device, deviceLogic.Clauses); OffLogicViewModel = new LogicViewModel(device, deviceLogic.OffClauses); SelectedMROMessageNo = deviceLogic.ZoneLogicMROMessageNo; SelectedMROMessageType = deviceLogic.ZoneLogicMROMessageType; }
protected override bool Save() { var deviceLogic = new XDeviceLogic(); foreach (var stateLogicViewModel in StateLogics) { var stateLogic = new StateLogic(); stateLogic.StateType = stateLogicViewModel.SelectedStateType; foreach (var clauseViewModel in stateLogicViewModel.Clauses) { var clause = new XClause() { StateType = clauseViewModel.SelectedStateType, Devices = clauseViewModel.Devices.ToList(), Zones = clauseViewModel.Zones.ToList(), ClauseJounOperationType = clauseViewModel.SelectedClauseJounOperationType, ClauseOperationType = clauseViewModel.SelectedClauseOperationType }; foreach (var deviceUID in clause.Devices) { var decvice = XManager.DeviceConfiguration.Devices.FirstOrDefault(x=>x.UID == deviceUID); clause.XDevices.Add(decvice); } foreach (var zoneUID in clause.Zones) { var zone = XManager.DeviceConfiguration.Zones.FirstOrDefault(x => x.UID == zoneUID); clause.XZones.Add(zone); } if ((clause.Devices.Count > 0) || (clause.Zones.Count > 0)) stateLogic.Clauses.Add(clause); } if (deviceLogic.StateLogics.Any(x => x.StateType == stateLogic.StateType)) { MessageBoxService.ShowWarning("Логика для состояние " + stateLogic.StateType.ToDescription() + " дублируется"); return false; } if (stateLogic.Clauses.Count > 0) deviceLogic.StateLogics.Add(stateLogic); Device.DeviceLogic = deviceLogic; } return base.Save(); }
public static string GetPresentationZone(XDeviceLogic DeviceLogic) { var stringBuilder = new StringBuilder(); var index = 0; foreach (var clause in DeviceLogic.Clauses) { if (index > 0) stringBuilder.Append(" " + clause.ClauseJounOperationType.ToDescription() + " "); if (clause.ClauseConditionType == ClauseConditionType.IfNot) stringBuilder.Append("Если НЕ "); stringBuilder.Append(clause.StateType.ToDescription() + " "); stringBuilder.Append(clause.ClauseOperationType.ToDescription() + " "); stringBuilder.Append(GetCommaSeparatedDevices(clause.Devices)); stringBuilder.Append(GetCommaSeparatedZones(clause.Zones)); stringBuilder.Append(GetCommaSeparatedDirections(clause.Directions)); index++; } return stringBuilder.ToString(); }
void ReplaceDeviceLogic(XDeviceLogic deviceLogic) { foreach (var clause in deviceLogic.Clauses) { for (int i = 0; i < clause.ZoneUIDs.Count; i++) { var zoneUID = clause.ZoneUIDs[i]; clause.ZoneUIDs[i] = ZoneUIDs[zoneUID]; } for (int i = 0; i < clause.DeviceUIDs.Count; i++) { var deviceUID = clause.DeviceUIDs[i]; clause.DeviceUIDs[i] = DeviceUIDs[deviceUID]; } for (int i = 0; i < clause.DirectionUIDs.Count; i++) { var directionUID = clause.DirectionUIDs[i]; clause.DirectionUIDs[i] = DirectionUIDs[directionUID]; } } }
public static void ChangeDeviceLogic(XDevice device, XDeviceLogic deviceLogic) { foreach (var clause in device.DeviceLogic.Clauses) { foreach (var direction in clause.Directions) { direction.OutputDevices.Remove(device); direction.OnChanged(); device.Directions.Remove(direction); } } device.DeviceLogic = deviceLogic; UpdateConfigurationHelper.InvalidateOneLogic(DeviceConfiguration, device, device.DeviceLogic); device.OnChanged(); }
void ConvertLogic() { foreach (var xDevice in XManager.DeviceConfiguration.Devices) { var device = FiresecManager.Devices.FirstOrDefault(x => x.UID == xDevice.UID); if (device != null) { if ((device.Driver.IsZoneLogicDevice) && (device.ZoneLogic != null)) { var xDeviceLogic = new XDeviceLogic(); var stateLogic = new StateLogic() { StateType = XStateType.TurnOn }; xDeviceLogic.StateLogics.Add(stateLogic); foreach (var clause in device.ZoneLogic.Clauses) { var xClause = new XClause() { ClauseOperationType = ClauseOperationType.AllZones }; if(clause.Operation.HasValue) switch(clause.Operation.Value) { case ZoneLogicOperation.All: xClause.ClauseOperationType = ClauseOperationType.AllZones; break; case ZoneLogicOperation.Any: xClause.ClauseOperationType = ClauseOperationType.AnyZone; break; } if (clause.Device != null) { ; } if (clause.DeviceUID != Guid.Empty) { ; } switch (clause.State) { case FiresecAPI.Models.ZoneLogicState.Attention: xClause.StateType = XStateType.Attention; break; case FiresecAPI.Models.ZoneLogicState.Fire: xClause.StateType = XStateType.Fire1; break; case FiresecAPI.Models.ZoneLogicState.Failure: xClause.StateType = XStateType.Failure; break; default: continue; } if ((clause.Zones == null) || (clause.Zones.Count == 0)) continue; foreach (var zoneNo in clause.Zones) { var xZone = XManager.DeviceConfiguration.Zones.FirstOrDefault(x=>x.No == zoneNo); xClause.Zones.Add(xZone.UID); } stateLogic.Clauses.Add(xClause); } if (stateLogic.Clauses.Count > 0) xDevice.DeviceLogic = xDeviceLogic; } } } }
public XDeviceLogic GetModel() { var deviceLogic = new XDeviceLogic(); deviceLogic.Clauses = OnLogicViewModel.GetClauses(); deviceLogic.OffClauses = OffLogicViewModel.GetClauses(); deviceLogic.ZoneLogicMROMessageNo = SelectedMROMessageNo; deviceLogic.ZoneLogicMROMessageType = SelectedMROMessageType; return deviceLogic; }
public static void InvalidatePumpStationLogic(XPumpStation pumpStation, XDeviceLogic deviceLogic) { var clauses = new List<XClause>(); foreach (var clause in deviceLogic.Clauses) { clause.Devices = new List<XDevice>(); clause.Zones = new List<XZone>(); clause.Directions = new List<XDirection>(); var deviceUIDs = new List<Guid>(); foreach (var deviceUID in clause.DeviceUIDs) { var clauseDevice = DeviceConfiguration.Devices.FirstOrDefault(x => x.UID == deviceUID); if (clauseDevice != null && !clauseDevice.IsNotUsed) { deviceUIDs.Add(deviceUID); clause.Devices.Add(clauseDevice); if (!pumpStation.InputDevices.Contains(clauseDevice)) pumpStation.InputDevices.Add(clauseDevice); //clauseDevice.DevicesInLogic.Add(device); } } clause.DeviceUIDs = deviceUIDs; var zoneUIDs = new List<Guid>(); foreach (var zoneUID in clause.ZoneUIDs) { var zone = DeviceConfiguration.Zones.FirstOrDefault(x => x.UID == zoneUID); if (zone != null) { zoneUIDs.Add(zoneUID); clause.Zones.Add(zone); if (!pumpStation.InputZones.Contains(zone)) pumpStation.InputZones.Add(zone); //zone.DevicesInLogic.Add(device); } } clause.ZoneUIDs = zoneUIDs; var directionUIDs = new List<Guid>(); foreach (var directionUID in clause.DirectionUIDs) { var direction = DeviceConfiguration.Directions.FirstOrDefault(x => x.UID == directionUID); if (direction != null) { directionUIDs.Add(directionUID); clause.Directions.Add(direction); if (!pumpStation.InputDirections.Contains(direction)) pumpStation.InputDirections.Add(direction); //direction.OutputDevices.Add(device); //device.Directions.Add(direction); } } clause.DirectionUIDs = directionUIDs; if (clause.Zones.Count > 0 || clause.Devices.Count > 0 || clause.Directions.Count > 0) clauses.Add(clause); } deviceLogic.Clauses = clauses; }
public static void InvalidateOneLogic(XDeviceConfiguration deviceConfiguration, XDevice device, XDeviceLogic deviceLogic) { var clauses = new List<XClause>(); foreach (var clause in deviceLogic.Clauses) { InvalidateOneClause(deviceConfiguration, device, clause); if (clause.Zones.Count > 0 || clause.Devices.Count > 0 || clause.Directions.Count > 0) clauses.Add(clause); } deviceLogic.Clauses = clauses; var offClauses = new List<XClause>(); if (deviceLogic.OffClauses != null) { foreach (var clause in deviceLogic.OffClauses) { InvalidateOneClause(deviceConfiguration, device, clause); if (clause.Zones.Count > 0 || clause.Devices.Count > 0 || clause.Directions.Count > 0) offClauses.Add(clause); } deviceLogic.OffClauses = offClauses; } }
public static string GetPresentationZone(XDeviceLogic DeviceLogic) { var stringBuilder = new StringBuilder(); foreach (var stateLogic in DeviceLogic.StateLogics) { stringBuilder.Append(stateLogic.StateType.ToDescription() + " если "); foreach (var clause in stateLogic.Clauses) { stringBuilder.Append(clause.StateType.ToDescription() + " в "); stringBuilder.Append(clause.ClauseOperationType.ToDescription() + " "); stringBuilder.Append(GetCommaSeparatedDevices(clause.Devices)); stringBuilder.Append(GetCommaSeparatedZones(clause.Zones)); } } return stringBuilder.ToString(); }
void ConvertLogic() { foreach (var xDevice in XManager.Devices) { var device = FiresecManager.Devices.FirstOrDefault(x => x.UID == xDevice.UID); if (device != null) { if ((device.Driver.IsZoneLogicDevice) && (device.ZoneLogic != null)) { var xDeviceLogic = new XDeviceLogic(); foreach (var clause in device.ZoneLogic.Clauses) { var xClause = new XClause() { ClauseOperationType = ClauseOperationType.AllZones }; if (clause.Operation.HasValue) switch (clause.Operation.Value) { case ZoneLogicOperation.All: xClause.ClauseOperationType = ClauseOperationType.AllZones; break; case ZoneLogicOperation.Any: xClause.ClauseOperationType = ClauseOperationType.AnyZone; break; } switch (clause.State) { case FiresecAPI.Models.ZoneLogicState.Attention: xClause.StateType = XStateBit.Attention; break; case FiresecAPI.Models.ZoneLogicState.Fire: xClause.StateType = XStateBit.Fire1; break; case FiresecAPI.Models.ZoneLogicState.Failure: xClause.StateType = XStateBit.Failure; break; default: continue; } if ((clause.ZoneUIDs == null) || (clause.ZoneUIDs.Count == 0)) continue; foreach (var zoneUID in clause.ZoneUIDs) { var xZone = XManager.Zones.FirstOrDefault(x => x.UID == zoneUID); xClause.ZoneUIDs.Add(xZone.UID); } xDeviceLogic.Clauses.Add(xClause); } if (xDeviceLogic.Clauses.Count > 0) xDevice.DeviceLogic = xDeviceLogic; } if (device.Driver.DriverType == DriverType.MPT) { if (device.Zone != null) { var xClause = new XClause(); xClause.ClauseOperationType = ClauseOperationType.AnyZone; xClause.ZoneUIDs.Add(device.Zone.UID); xDevice.DeviceLogic.Clauses.Add(xClause); } } } } }