public ClauseGroupViewModel(GKBase gkBase, GKClauseGroup clauseGroup) { AddCommand = new RelayCommand(OnAdd); AddGroupCommand = new RelayCommand(OnAddGroup); RemoveCommand = new RelayCommand<ClauseViewModel>(OnRemove); RemoveGroupCommand2 = new RelayCommand(OnRemoveGroup2, CanRemoveGroup2); RemoveGroupCommand = new RelayCommand<ClauseGroupViewModel>(OnRemoveGroup); ChangeJoinOperatorCommand = new RelayCommand(OnChangeJoinOperator); GKBase = gkBase; Clauses = new ObservableCollection<ClauseViewModel>(); foreach (var clause in clauseGroup.Clauses) { var clauseViewModel = new ClauseViewModel(gkBase, clause); Clauses.Add(clauseViewModel); } ClauseGroups = new ObservableCollection<ClauseGroupViewModel>(); foreach (var clause in clauseGroup.ClauseGroups) { var clauseGroupViewModel = new ClauseGroupViewModel(gkBase, clause); clauseGroupViewModel.Parent = this; ClauseGroups.Add(clauseGroupViewModel); } JoinOperator = clauseGroup.ClauseJounOperationType; }
public ICIndicatorLogic() { Blink1ClausesGroup = new GKClauseGroup(); Blink3ClausesGroup = new GKClauseGroup(); OffClausesGroup = new GKClauseGroup(); UseOffCounterLogic = false; }
public GKLogic() { OnClausesGroup = new GKClauseGroup(); On2ClausesGroup = new GKClauseGroup(); OffClausesGroup = new GKClauseGroup(); OnNowClausesGroup = new GKClauseGroup(); OffNowClausesGroup = new GKClauseGroup(); StopClausesGroup = new GKClauseGroup(); UseOffCounterLogic = true; RedIndicatorLogic = new ICIndicatorLogic(); GreenIndicatorLogic = new ICIndicatorLogic(); YellowIndicatorLogic = new ICIndicatorLogic(); }
public GKClauseGroup Clone() { var result = new GKClauseGroup(); result.ClauseJounOperationType = ClauseJounOperationType; foreach (var clause in Clauses) { var clonedClause = new GKClause() { ClauseConditionType = clause.ClauseConditionType, ClauseOperationType = clause.ClauseOperationType, StateType = clause.StateType, DeviceUIDs = clause.DeviceUIDs, ZoneUIDs = clause.ZoneUIDs, GuardZoneUIDs = clause.GuardZoneUIDs, DirectionUIDs = clause.DirectionUIDs, DelayUIDs = clause.DelayUIDs, DoorUIDs = clause.DoorUIDs, MPTUIDs = clause.MPTUIDs, PumpStationsUIDs = clause.PumpStationsUIDs, Devices = clause.Devices, Zones = clause.Zones, GuardZones = clause.GuardZones, Directions = clause.Directions, Delays = clause.Delays, Doors = clause.Doors, MPTs = clause.MPTs, PumpStations = clause.PumpStations, }; result.Clauses.Add(clonedClause); } foreach (var clauseGroup in ClauseGroups) { result.ClauseGroups.Add(clauseGroup.Clone()); } return result; }
public GKClauseGroup InvalidateOneClauseGroup(GKBase gkBase, GKClauseGroup clauseGroup) { var result = new GKClauseGroup(); result.ClauseJounOperationType = clauseGroup.ClauseJounOperationType; var groups = new List<GKClauseGroup>(); foreach (var group in clauseGroup.ClauseGroups) { var _clauseGroup = InvalidateOneClauseGroup(gkBase, group); if (_clauseGroup.Clauses.Count + _clauseGroup.ClauseGroups.Count > 0) groups.Add(_clauseGroup); } result.ClauseGroups = groups; foreach (var clause in clauseGroup.Clauses) { clause.Devices = new List<GKDevice>(); clause.Zones = new List<GKZone>(); clause.GuardZones = new List<GKGuardZone>(); clause.Directions = new List<GKDirection>(); clause.MPTs = new List<GKMPT>(); clause.Delays = new List<GKDelay>(); clause.Doors = new List<GKDoor>(); clause.PumpStations = new List<GKPumpStation>(); var deviceUIDs = new List<Guid>(); foreach (var deviceUID in clause.DeviceUIDs) { var device = Devices.FirstOrDefault(x => x.UID == deviceUID); if (device != null) { deviceUIDs.Add(deviceUID); clause.Devices.Add(device); } } clause.DeviceUIDs = deviceUIDs; var zoneUIDs = new List<Guid>(); foreach (var zoneUID in clause.ZoneUIDs) { var zone = Zones.FirstOrDefault(x => x.UID == zoneUID); if (zone != null) { zoneUIDs.Add(zoneUID); clause.Zones.Add(zone); } } clause.ZoneUIDs = zoneUIDs; var guardZoneUIDs = new List<Guid>(); foreach (var guardZoneUID in clause.GuardZoneUIDs) { var guardZone = GuardZones.FirstOrDefault(x => x.UID == guardZoneUID); if (guardZone != null) { guardZoneUIDs.Add(guardZoneUID); clause.GuardZones.Add(guardZone); } } clause.GuardZoneUIDs = guardZoneUIDs; var directionUIDs = new List<Guid>(); foreach (var directionUID in clause.DirectionUIDs) { var direction = Directions.FirstOrDefault(x => x.UID == directionUID); if (direction != null) { directionUIDs.Add(directionUID); clause.Directions.Add(direction); } } clause.DirectionUIDs = directionUIDs; var mptUIDs = new List<Guid>(); foreach (var mptUID in clause.MPTUIDs) { var mpt = MPTs.FirstOrDefault(x => x.UID == mptUID); if (mpt != null) { mptUIDs.Add(mptUID); clause.MPTs.Add(mpt); } } clause.MPTUIDs = mptUIDs; var delayUIDs = new List<Guid>(); foreach (var delayUID in clause.DelayUIDs) { var delay = Delays.FirstOrDefault(x => x.UID == delayUID); if (delay != null) { delayUIDs.Add(delayUID); clause.Delays.Add(delay); } } clause.DelayUIDs = delayUIDs; var doorUIDs = new List<Guid>(); foreach (var doorUID in clause.DoorUIDs) { var door = Doors.FirstOrDefault(x => x.UID == doorUID); if (door != null) { doorUIDs.Add(doorUID); clause.Doors.Add(door); } } clause.DoorUIDs = doorUIDs; var pumpStationsUIDs = new List<Guid>(); foreach (var pumpStationUID in clause.PumpStationsUIDs) { var pumpStation = PumpStations.FirstOrDefault(x => x.UID == pumpStationUID); if (pumpStation != null) { pumpStationsUIDs.Add(pumpStationUID); clause.PumpStations.Add(pumpStation); } } clause.PumpStationsUIDs = pumpStationsUIDs; if (clause.HasObjects()) result.Clauses.Add(clause); } return result; }
GKLogic CreateLogic(GKDevice device) { var clause = new GKClause() { ClauseOperationType = ClauseOperationType.AnyDevice, StateType = GKStateBit.Fire1 }; clause.Devices.Add(device); clause.DeviceUIDs.Add(device.UID); var clauseGroup = new GKClauseGroup(); clauseGroup.Clauses.Add(clause); var logic = new GKLogic(); logic.OnClausesGroup = clauseGroup; return logic; }
void LinkLogic(GKBase gkBase, GKClauseGroup clauseGroup) { if (clauseGroup.Clauses != null) { foreach (var clause in clauseGroup.Clauses) { foreach (var clauseDevice in clause.Devices) gkBase.LinkToDescriptor(clauseDevice); foreach (var zone in clause.Zones) gkBase.LinkToDescriptor(zone); foreach (var guardZone in clause.GuardZones) gkBase.LinkToDescriptor(guardZone); foreach (var direction in clause.Directions) gkBase.LinkToDescriptor(direction); foreach (var mpt in clause.MPTs) gkBase.LinkToDescriptor(mpt); foreach (var delay in clause.Delays) gkBase.LinkToDescriptor(delay); foreach (var door in clause.Doors) gkBase.LinkToDescriptor(door); foreach (var pumpStation in clause.PumpStations) gkBase.LinkToDescriptor(pumpStation); } } if (clauseGroup.ClauseGroups != null) { foreach (var group in clauseGroup.ClauseGroups) { LinkLogic(gkBase, group); } } }
public static string GetPresentationLogic(GKClauseGroup clauseGroup) { var stringBuilder = new StringBuilder(); var index = 0; foreach (var clause in clauseGroup.Clauses) { if (index > 0) stringBuilder.Append(" " + clauseGroup.ClauseJounOperationType.ToDescription() + " "); if (clause.ClauseConditionType == ClauseConditionType.IfNot) stringBuilder.Append("Если НЕ "); stringBuilder.Append(GKClause.ClauseToString(clause.ClauseOperationType, clause.StateType) + " "); stringBuilder.Append(clause.ClauseOperationType.ToDescription() + " "); stringBuilder.Append(GetCommaSeparatedDevices(clause.Devices)); stringBuilder.Append(GetCommaSeparatedObjects(new List<ModelBase>(clause.Zones), new List<ModelBase>(Zones))); stringBuilder.Append(GetCommaSeparatedObjects(new List<ModelBase>(clause.GuardZones), new List<ModelBase>(GuardZones))); stringBuilder.Append(GetCommaSeparatedObjects(new List<ModelBase>(clause.Directions), new List<ModelBase>(Directions))); stringBuilder.Append(GetCommaSeparatedObjects(new List<ModelBase>(clause.MPTs), new List<ModelBase>(MPTs))); stringBuilder.Append(GetCommaSeparatedObjects(new List<ModelBase>(clause.Delays), new List<ModelBase>(Delays))); stringBuilder.Append(GetCommaSeparatedObjects(new List<ModelBase>(clause.Doors), new List<ModelBase>(Doors))); stringBuilder.Append(GetCommaSeparatedObjects(new List<ModelBase>(clause.PumpStations), new List<ModelBase>(PumpStations))); index++; } foreach (var group in clauseGroup.ClauseGroups) { if (index > 0) stringBuilder.Append(" " + clauseGroup.ClauseJounOperationType.ToDescription() + " "); var groupString = GetPresentationLogic(group); stringBuilder.Append("(" + groupString + ")"); index++; } return stringBuilder.ToString(); }
static bool AppendClauseGroupString(GKClauseGroup gkClauseGroup, string name, List<StringBuilder> list) { if (gkClauseGroup.IsNotEmpty()) { var stringBuilder = new StringBuilder(); stringBuilder.Append(name); stringBuilder.Append(": "); stringBuilder.Append(GetPresentationLogic(gkClauseGroup)); list.Add(stringBuilder); return true; } return false; }
public GKClauseGroup GetClauseGroup() { var clauseGroup = new GKClauseGroup(); clauseGroup.ClauseJounOperationType = JoinOperator; foreach (var clauseGroupViewModel in ClauseGroups) { clauseGroup.ClauseGroups.Add(clauseGroupViewModel.GetClauseGroup()); } foreach (var clauseViewModel in Clauses) { var clause = new GKClause() { ClauseConditionType = clauseViewModel.SelectedClauseConditionType, StateType = clauseViewModel.SelectedStateType.StateBit, ClauseOperationType = clauseViewModel.SelectedClauseOperationType }; switch (clause.ClauseOperationType) { case ClauseOperationType.AllDevices: case ClauseOperationType.AnyDevice: clause.Devices = clauseViewModel.Devices.ToList(); clause.DeviceUIDs = clauseViewModel.Devices.Select(x => x.UID).ToList(); break; case ClauseOperationType.AllZones: case ClauseOperationType.AnyZone: clause.Zones = clauseViewModel.Zones.ToList(); clause.ZoneUIDs = clauseViewModel.Zones.Select(x => x.UID).ToList(); break; case ClauseOperationType.AllGuardZones: case ClauseOperationType.AnyGuardZone: clause.GuardZones = clauseViewModel.GuardZones.ToList(); clause.GuardZoneUIDs = clauseViewModel.GuardZones.Select(x => x.UID).ToList(); break; case ClauseOperationType.AllDirections: case ClauseOperationType.AnyDirection: clause.Directions = clauseViewModel.Directions.ToList(); clause.DirectionUIDs = clauseViewModel.Directions.Select(x => x.UID).ToList(); break; case ClauseOperationType.AllMPTs: case ClauseOperationType.AnyMPT: clause.MPTs = clauseViewModel.MPTs.ToList(); clause.MPTUIDs = clauseViewModel.MPTs.Select(x => x.UID).ToList(); break; case ClauseOperationType.AllDelays: case ClauseOperationType.AnyDelay: clause.Delays = clauseViewModel.Delays.ToList(); clause.DelayUIDs = clauseViewModel.Delays.Select(x => x.UID).ToList(); break; case ClauseOperationType.AllDoors: case ClauseOperationType.AnyDoor: clause.Doors = clauseViewModel.Doors.ToList(); clause.DoorUIDs = clauseViewModel.Doors.Select(x => x.UID).ToList(); break; case ClauseOperationType.AnyPumpStation: case ClauseOperationType.AllPumpStations: clause.PumpStations = clauseViewModel.PumpStations.ToList(); clause.PumpStationsUIDs = clauseViewModel.PumpStations.Select(x => x.UID).ToList(); break; } if (clause.HasObjects()) clauseGroup.Clauses.Add(clause); } return clauseGroup; }