Exemplo n.º 1
0
		void OnAdd()
		{
			var clause = new XClause();
			var clauseViewModel = new ClauseViewModel(clause, Device);
			Clauses.Add(clauseViewModel);
			UpdateJoinOperatorVisibility();
		}
Exemplo n.º 2
0
		public static XDevice CopyDevice(XDevice deviceFrom, XDevice deviceTo)
		{
			deviceTo.DriverUID = deviceFrom.DriverUID;
			deviceTo.Driver = deviceFrom.Driver;
			deviceTo.IntAddress = deviceFrom.IntAddress;
			deviceTo.Description = deviceFrom.Description;

			deviceTo.Properties = new List<XProperty>();
			foreach (var property in deviceFrom.Properties)
			{
				deviceTo.Properties.Add(new XProperty()
				{
					Name = property.Name,
					Value = property.Value,
					DriverProperty = property.DriverProperty
				});
			}

			deviceTo.ZoneUIDs = deviceFrom.ZoneUIDs.ToList();
			deviceTo.Zones = deviceFrom.Zones.ToList();
			foreach (var clause in deviceFrom.DeviceLogic.Clauses)
			{
				var clonedClause = new XClause()
				{
					ClauseConditionType = clause.ClauseConditionType,
					ClauseJounOperationType = clause.ClauseJounOperationType,
					ClauseOperationType = clause.ClauseOperationType,
					StateType = clause.StateType,
					DeviceUIDs = clause.DeviceUIDs,
					ZoneUIDs = clause.ZoneUIDs,
					DirectionUIDs = clause.DirectionUIDs,
					Devices = clause.Devices,
					Zones = clause.Zones,
					Directions = clause.Directions,
				};
				deviceTo.DeviceLogic.Clauses.Add(clonedClause);
			}

			deviceTo.Children = new List<XDevice>();
			foreach (var childDevice in deviceFrom.Children)
			{
				var newChildDevice = CopyDevice(childDevice, false);
				newChildDevice.Parent = deviceTo;
				deviceTo.Children.Add(newChildDevice);
			}

			return deviceTo;
		}
Exemplo n.º 3
0
		public ClauseViewModel(XClause clause, XDevice device)
		{
			Device = device;
			SelectZonesCommand = new RelayCommand(OnSelectZones);
			SelectDevicesCommand = new RelayCommand(OnSelectDevices);
			SelectDirectionCommand = new RelayCommand(OnSelectDirections);

			ClauseConditionTypes = Enum.GetValues(typeof(ClauseConditionType)).Cast<ClauseConditionType>().ToList();
			ClauseOperationTypes = Enum.GetValues(typeof(ClauseOperationType)).Cast<ClauseOperationType>().ToList();

			SelectedClauseOperationType = clause.ClauseOperationType;
			Zones = clause.Zones.ToList();
			Devices = clause.Devices.ToList();
			Directions = clause.Directions.ToList();

			SelectedClauseConditionType = clause.ClauseConditionType;
			SelectedStateType = clause.StateType;
		}
Exemplo n.º 4
0
        public DeviceLogicViewModel(XDevice device)
        {
            Title = "Настройка логики устройства";
            AddCommand = new RelayCommand(OnAdd);
            RemoveCommand = new RelayCommand<StateLogicViewModel>(OnRemove);

            Device = device;
            if (device.DeviceLogic.StateLogics.Count == 0)
            {
                var stateLogic = new StateLogic();
                var clause = new XClause();
                stateLogic.Clauses.Add(clause);
                device.DeviceLogic.StateLogics.Add(stateLogic);
            }

            StateLogics = new ObservableCollection<StateLogicViewModel>();
            foreach (var stateLogic in device.DeviceLogic.StateLogics)
            {
                var stateLogicViewModel = new StateLogicViewModel(this, stateLogic);
                StateLogics.Add(stateLogicViewModel);
            }
        }
Exemplo n.º 5
0
		public List<XClause> GetClauses()
		{
			var clauses = new List<XClause>();
			foreach (var clauseViewModel in Clauses)
			{
				var clause = new XClause()
				{
					ClauseConditionType = clauseViewModel.SelectedClauseConditionType,
					StateType = clauseViewModel.SelectedStateType,
					ClauseJounOperationType = JoinOperator,
					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.AllDirections:
					case ClauseOperationType.AnyDirection:
						clause.Directions = clauseViewModel.Directions.ToList();
						clause.DirectionUIDs = clauseViewModel.Directions.Select(x => x.UID).ToList();
						break;
				}
				if (clause.ZoneUIDs.Count > 0 || clause.DeviceUIDs.Count > 0 || clause.DirectionUIDs.Count > 0)
					clauses.Add(clause);
			}
			return clauses;
		}
Exemplo n.º 6
0
        public ClauseViewModel(StateLogicViewModel stateLogicViewModel, XClause clause)
        {
            SelectZonesCommand = new RelayCommand(OnSelectZones);
            SelectDevicesCommand = new RelayCommand(OnSelectDevices);

            _stateLogicViewModel = stateLogicViewModel;
            SelectedStateType = clause.StateType;
            SelectedClauseJounOperationType = clause.ClauseJounOperationType;
            SelectedClauseOperationType = clause.ClauseOperationType;
            Zones = clause.Zones.ToList();
            Devices = clause.Devices.ToList();

            ClauseJounOperationTypes = Enum.GetValues(typeof(ClauseJounOperationType)).Cast<ClauseJounOperationType>().ToList();
            ClauseOperationTypes = Enum.GetValues(typeof(ClauseOperationType)).Cast<ClauseOperationType>().ToList();

            StateTypes = new List<XStateType>();
            StateTypes.Add(XStateType.Attention);
            StateTypes.Add(XStateType.Fire1);
            StateTypes.Add(XStateType.Fire2);
            StateTypes.Add(XStateType.Test);
            StateTypes.Add(XStateType.Failure);

            SelectedStateType = clause.StateType;
        }
Exemplo n.º 7
0
        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;
                    }
                }
            }
        }
		static void InvalidateOneClause(XDeviceConfiguration deviceConfiguration, XDevice device, XClause clause)
		{
			clause.Devices = new List<XDevice>();
			clause.Zones = new List<XZone>();
			clause.Directions = new List<XDirection>();

			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);
					zone.DevicesInLogic.Add(device);
				}
			}
			clause.ZoneUIDs = zoneUIDs;

			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);
					clauseDevice.DevicesInLogic.Add(device);
				}
			}
			clause.DeviceUIDs = deviceUIDs;

			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);
					direction.OutputDevices.Add(device);
					device.Directions.Add(direction);
				}
			}
			clause.DirectionUIDs = directionUIDs;
		}
Exemplo n.º 9
0
		public void DeleteOutputDevice(XDevice deviceToRemove)
		{
			var devices = new List<XDevice>(Direction.OutputDevices);
			devices.Remove(deviceToRemove);
			foreach (var device in Direction.OutputDevices)
			{
				foreach (var clause in device.DeviceLogic.Clauses)
				{
					clause.Directions.RemoveAll(x => x == Direction);
					clause.DirectionUIDs.RemoveAll(x => x == Direction.UID);
				}
				device.DeviceLogic.Clauses.RemoveAll(x => x.Zones.Count + x.Devices.Count + x.Directions.Count == 0);
				device.OnChanged();
			}
			Direction.OutputDevices.Clear();
			foreach (var device in devices)
			{
				var alreadyHasDirectionClause = false;
				foreach (var clause in device.DeviceLogic.Clauses)
				{
					if ((clause.ClauseOperationType == ClauseOperationType.AllDirections) || (clause.ClauseOperationType == ClauseOperationType.AnyDirection))
					{
						alreadyHasDirectionClause = true;
						if (!clause.Directions.Contains(Direction))
						{
							clause.Directions.Add(Direction);
							clause.DirectionUIDs.Add(Direction.UID);
							device.Directions.Add(Direction);
							device.OnChanged();
						}
					}
				}
				if (!alreadyHasDirectionClause)
				{
					var clause = new XClause()
					{
						ClauseOperationType = ClauseOperationType.AnyDirection,
						StateType = XStateBit.On,
						Directions = new List<XDirection>() { Direction },
						DirectionUIDs = new List<Guid>() { Direction.UID }
					};

					device.DeviceLogic.Clauses.Add(clause);
					device.Directions.Add(Direction);
					device.OnChanged();
				}
			}
			Direction.OutputDevices = devices;

			InitializeDependences();
			ServiceFactory.SaveService.GKChanged = true;
		}
Exemplo n.º 10
0
		public void SetNewOutputDevices(List<XDevice> devices)
		{
			foreach (var device in Direction.OutputDevices)
			{
				foreach (var clause in device.DeviceLogic.Clauses)
				{
					clause.Directions.RemoveAll(x => x == Direction);
					clause.DirectionUIDs.RemoveAll(x => x == Direction.UID);
				}
				device.DeviceLogic.Clauses.RemoveAll(x => x.Zones.Count + x.Devices.Count + x.Directions.Count == 0);
				device.OnChanged();
			}
			Direction.OutputDevices.Clear();

			Direction.OutputDevices = devices;
			foreach (var device in Direction.OutputDevices)
			{
				var alreadyHasDirectionClause = false;
				foreach (var clause in device.DeviceLogic.Clauses)
				{
					if ((clause.ClauseOperationType == ClauseOperationType.AllDirections) || (clause.ClauseOperationType == ClauseOperationType.AnyDirection))
					{
						alreadyHasDirectionClause = true;
						if (!clause.Directions.Contains(Direction))
						{
							clause.Directions.Add(Direction);
							clause.DirectionUIDs.Add(Direction.UID);
							device.Directions.Add(Direction);
							device.OnChanged();
						}
					}
				}
				if (!alreadyHasDirectionClause)
				{
					var clause = new XClause()
					{
						ClauseOperationType = ClauseOperationType.AnyDirection,
						StateType = XStateBit.On,
						Directions = new List<XDirection>() { Direction },
						DirectionUIDs = new List<Guid>() { Direction.UID }
					};

					device.DeviceLogic.Clauses.Add(clause);
					device.Directions.Add(Direction);
					device.OnChanged();
				}
			}
		}
Exemplo n.º 11
0
		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);
						}
					}
				}
			}
		}
Exemplo n.º 12
0
        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();
        }