Beispiel #1
0
        public static ZoneLogic Convert(expr innerZoneLogic)
        {
            var zoneLogic = new ZoneLogic();

            if (innerZoneLogic != null && innerZoneLogic.clause.IsNotNullOrEmpty())
            {
                foreach (var innerClause in innerZoneLogic.clause)
                {
                    var clause = new Clause();
                    if (innerClause.zone != null)
                    {
                        foreach (var item in innerClause.zone)
                        {
                            if (string.IsNullOrWhiteSpace(item) == false)
                                clause.Zones.Add(int.Parse(item));
                        }
                    }

                    clause.State = (ZoneLogicState)int.Parse(innerClause.state);

                    switch (innerClause.operation)
                    {
                        case "and":
                            clause.Operation = ZoneLogicOperation.All;
                            break;

                        case "or":
                            clause.Operation = ZoneLogicOperation.Any;
                            break;

                        default:
                            clause.Operation = null;
                            break;
                    }

                    switch (innerClause.joinOperator)
                    {
                        case "and":
                            zoneLogic.JoinOperator = ZoneLogicJoinOperator.And;
                            break;

                        case "or":
                            zoneLogic.JoinOperator = ZoneLogicJoinOperator.Or;
                            break;
                    }

                    if (innerClause.device != null)
                        clause.DeviceUID = GuidHelper.ToGuid(innerClause.device[0].UID);

                    zoneLogic.Clauses.Add(clause);
                }
            }

            return zoneLogic;
        }
Beispiel #2
0
        public static expr ConvertBack(ZoneLogic zoneLogic)
        {
            var innerZoneLogic = new expr();

            var innerClauses = new List<clauseType>();
            foreach (var clause in zoneLogic.Clauses)
            {
                var innerClause = new clauseType();

                innerClause.state = ((int)clause.State).ToString();

                switch (clause.Operation)
                {
                    case ZoneLogicOperation.All:
                        innerClause.operation = "and";
                        break;

                    case ZoneLogicOperation.Any:
                        innerClause.operation = "or";
                        break;

                    default:
                        innerClause.operation = null;
                        break;
                }

                switch (zoneLogic.JoinOperator)
                {
                    case ZoneLogicJoinOperator.And:
                        innerClause.joinOperator = "and";
                        break;

                    case ZoneLogicJoinOperator.Or:
                        innerClause.joinOperator = "or";
                        break;

                    default:
                        innerClause.joinOperator = null;
                        break;
                }

                if (clause.DeviceUID != Guid.Empty)
                {
                    innerClause.device = new deviceType[0];
                    innerClause.device[0] = new deviceType() { UID = clause.DeviceUID.ToString() };
                }

                innerClause.zone = clause.Zones.Select(x => x.ToString()).ToArray();
                innerClauses.Add(innerClause);
            }

            innerZoneLogic.clause = innerClauses.ToArray();

            return innerZoneLogic;
        }
		void ClearExternalZones(Device device)
		{
			var zoneLogic = new ZoneLogic();
			if (device.ZoneLogic != null)
			{
				foreach (var clause in device.ZoneLogic.Clauses)
				{
					var newClause = new Clause();
					foreach (var zone in clause.Zones)
					{
						if (!HasExternalZone(zone, device))
						{
							newClause.ZoneUIDs.Add(zone.UID);
							newClause.Zones.Add(zone);
						}
					}
					zoneLogic.Clauses.Add(newClause);
				}
			}
			device.ZoneLogic = zoneLogic;
		}
Beispiel #4
0
		public Device()
		{
			UID = Guid.NewGuid();
			Children = new List<Device>();
			Properties = new List<Property>();
			SystemAUProperties = new List<Property>();
			DeviceAUProperties = new List<Property>();
			IndicatorLogic = new IndicatorLogic();
			PDUGroupLogic = new PDUGroupLogic();
			PlanElementUIDs = new List<Guid>();
			ZoneLogic = new ZoneLogic();
			IsRmAlarmDevice = false;
			IsNotUsed = false;
			AllowMultipleVizualization = false;

			ShapeIds = new List<string>();
			ZonesInLogic = new List<Zone>();
			DependentDevices = new List<Device>();
			DeviceConfiguration = new DeviceConfiguration();
			StateWordBytes = new List<byte>();
			RawParametersBytes = new List<byte>();
		}
		public static expr ConvertBack(ZoneLogic zoneLogic)
		{
			var innerZoneLogic = new expr();

			var innerClauses = new List<clauseType>();
			foreach (var clause in zoneLogic.Clauses)
			{
				var innerClause = new clauseType();
				innerClause.state = ((int)clause.State).ToString();

				switch (clause.Operation)
				{
					case ZoneLogicOperation.All:
						innerClause.operation = "and";
						break;

					case ZoneLogicOperation.Any:
						innerClause.operation = "or";
						break;

					default:
						innerClause.operation = null;
						break;
				}

				switch (zoneLogic.JoinOperator)
				{
					case ZoneLogicJoinOperator.And:
						innerClause.joinOperator = "and";
						break;

					case ZoneLogicJoinOperator.Or:
						innerClause.joinOperator = "or";
						break;

					default:
						innerClause.joinOperator = null;
						break;
				}

				if (clause.ZoneLogicMROMessageNo != ZoneLogicMROMessageNo.Message1)
				{
					switch (clause.ZoneLogicMROMessageNo)
					{
						case ZoneLogicMROMessageNo.Message1:
							innerClause.MRO_MessageNo = "0";
							break;

						case ZoneLogicMROMessageNo.Message2:
							innerClause.MRO_MessageNo = "1";
							break;

						case ZoneLogicMROMessageNo.Message3:
							innerClause.MRO_MessageNo = "2";
							break;

						case ZoneLogicMROMessageNo.Message4:
							innerClause.MRO_MessageNo = "3";
							break;

						case ZoneLogicMROMessageNo.Message5:
							innerClause.MRO_MessageNo = "4";
							break;

						case ZoneLogicMROMessageNo.Message6:
							innerClause.MRO_MessageNo = "5";
							break;

                        case ZoneLogicMROMessageNo.Message7:
                            innerClause.MRO_MessageNo = "6";
                            break;

                        case ZoneLogicMROMessageNo.Message8:
                            innerClause.MRO_MessageNo = "7";
                            break;

						default:
							innerClause.MRO_MessageNo = null;
							break;
					}
				}

				if (clause.ZoneLogicMROMessageType != ZoneLogicMROMessageType.Add)
				{
					switch (clause.ZoneLogicMROMessageType)
					{
						case ZoneLogicMROMessageType.Add:
							innerClause.MRO_MessageNo = "0";
							break;

						case ZoneLogicMROMessageType.Remove:
							innerClause.MRO_MessageNo = "1";
							break;

						default:
							innerClause.MRO_MessageNo = null;
							break;
					}
				}

				if (clause.DeviceUIDs != null && clause.DeviceUIDs.Count > 0)
				{
					var deviceTypes = new List<deviceType>();
					foreach (var deviceUID in clause.DeviceUIDs)
					{
						var deviceType = new deviceType() { UID = deviceUID.ToString() };
						deviceTypes.Add(deviceType);
					}
					innerClause.device = deviceTypes.ToArray();
				}

                innerClause.zone = clause.Zones.Select(x => x.No.ToString()).ToArray();
				innerClauses.Add(innerClause);
			}

			innerZoneLogic.clause = innerClauses.ToArray();
			return innerZoneLogic;
		}
		public static ZoneLogic Convert(DeviceConfiguration deviceConfiguration, expr innerZoneLogic)
		{
			var zoneLogic = new ZoneLogic();

			if (innerZoneLogic != null && innerZoneLogic.clause.IsNotNullOrEmpty())
			{
				foreach (var innerClause in innerZoneLogic.clause)
				{
					var clause = new Clause();
					if (innerClause.zone != null)
					{
						foreach (var item in innerClause.zone)
						{
                            if (string.IsNullOrWhiteSpace(item) == false)
                            {
                                var zoneNo = int.Parse(item);
                                var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.No == zoneNo);
                                if (zone != null)
                                {
                                    clause.ZoneUIDs.Add(zone.UID);
                                }
                            }
						}
					}
					if (innerClause.device != null)
					{
						foreach (var innerDevice in innerClause.device)
						{
							if (innerDevice != null)
							{
								if (!string.IsNullOrEmpty(innerDevice.UID))
								{
									clause.DeviceUIDs.Add(GuidHelper.ToGuid(innerDevice.UID));
								}
							}
						}
					}

					clause.State = (ZoneLogicState)int.Parse(innerClause.state);

					switch (innerClause.operation)
					{
						case "and":
							clause.Operation = ZoneLogicOperation.All;
							break;

						case "or":
							clause.Operation = ZoneLogicOperation.Any;
							break;

						default:
							clause.Operation = null;
							break;
					}

					switch (innerClause.joinOperator)
					{
						case "and":
							zoneLogic.JoinOperator = ZoneLogicJoinOperator.And;
							break;

						case "or":
							zoneLogic.JoinOperator = ZoneLogicJoinOperator.Or;
							break;
					}

					if (!string.IsNullOrEmpty(innerClause.MRO_MessageNo))
					{
						switch (innerClause.MRO_MessageNo)
						{
							case "0":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message1;
								break;

							case "1":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message2;
								break;

							case "2":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message3;
								break;

							case "3":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message4;
								break;

							case "4":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message5;
								break;

							case "5":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message6;
								break;

                            case "6":
                                clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message7;
                                break;

                            case "7":
                                clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message8;
                                break;
						}
					}

					if (!string.IsNullOrEmpty(innerClause.MRO_MessageType))
					{
						switch (innerClause.MRO_MessageType)
						{
							case "0":
								clause.ZoneLogicMROMessageType = ZoneLogicMROMessageType.Add;
								break;

							case "1":
								clause.ZoneLogicMROMessageType = ZoneLogicMROMessageType.Remove;
								break;
						}
					}

					zoneLogic.Clauses.Add(clause);
				}
			}

			return zoneLogic;
		}
		public void SetDeviceZoneLogic(Device parentDevice, ZoneLogic zoneLogic)
		{
			foreach (var device in GetMRO2Group(parentDevice))
			{
				foreach (var zone in device.ZonesInLogic)
				{
					zone.DevicesInZoneLogic.Remove(device);
					zone.OnChanged();
				}
				device.ZonesInLogic.Clear();

				var dependentDevices = new List<Device>(device.DependentDevices);
				foreach (var dependentDevice in dependentDevices)
				{
					DeviceConfiguration.InvalidateOneDevice(dependentDevice);
					DeviceConfiguration.UpdateOneDeviceCrossReferences(dependentDevice);
					device.OnChanged();
				}
				device.DependentDevices.Clear();

				device.ZoneLogic = zoneLogic;
				DeviceConfiguration.InvalidateOneDevice(device);
				DeviceConfiguration.UpdateOneDeviceCrossReferences(device);
				device.UpdateHasExternalDevices();
				device.OnChanged();
			}
		}
        public string GetPresentationZone(ZoneLogic zoneLogic)
        {
            string result = "";

            for (int i = 0; i < zoneLogic.Clauses.Count; i++)
            {
                var clause = zoneLogic.Clauses[i];

                if (i > 0)
                {
                    switch (zoneLogic.JoinOperator)
                    {
                        case ZoneLogicJoinOperator.And:
                            result += " и ";
                            break;
                        case ZoneLogicJoinOperator.Or:
                            result += " или ";
                            break;
                        default:
                            break;
                    }
                }

				if (clause.DeviceUIDs != null && clause.DeviceUIDs.Count > 0)
                {
					result += "Количество устройств для сработки " + clause.DeviceUIDs.Count;
                    continue;
                }

                if (clause.State == ZoneLogicState.Failure)
                {
                    result += "состояние неисправность прибора";
                    continue;
                }

				if (clause.State == ZoneLogicState.DoubleFire)
				{
					result += "состояние Включение без задержки по пожару в двух зонах";
					continue;
				}

                result += "состояние " + clause.State.ToDescription();
                result += " " + clause.Operation.ToDescription() + " " + GetCommaSeparatedZones(clause.Zones);
            }

            return result;
        }
		public string GetPresentationZone(ZoneLogic zoneLogic)
		{
			string result = "";

			for (int i = 0; i < zoneLogic.Clauses.Count; i++)
			{
				var clause = zoneLogic.Clauses[i];

				if (i > 0)
				{
					switch (zoneLogic.JoinOperator)
					{
						case ZoneLogicJoinOperator.And:
							result += " и ";
							break;
						case ZoneLogicJoinOperator.Or:
							result += " или ";
							break;
						default:
							break;
					}
				}

				if (clause.DeviceUIDs != null && clause.DeviceUIDs.Count > 0)
				{
					result += "Сработка устройств ";
					foreach (var device in clause.Devices)
					{
						result += device.PresentationAddressAndName + ", ";
					}
					if (result.EndsWith(", "))
						result = result.Remove(result.Length - 2, 2);
					continue;
				}

				if (clause.State == ZoneLogicState.Failure)
				{
					result += "состояние неисправность прибора";
					continue;
				}

				result += "состояние " + clause.State.ToDescription();
                result += " " + clause.Operation.ToDescription() + " " + GetCommaSeparatedZones(clause.Zones);
			}

			return result;
		}
        public string GetPresentationZone(ZoneLogic zoneLogic)
        {
            string result = "";

            for (int i = 0; i < zoneLogic.Clauses.Count; i++)
            {
                var clause = zoneLogic.Clauses[i];

                if (i > 0)
                {
                    switch (zoneLogic.JoinOperator)
                    {
                        case ZoneLogicJoinOperator.And:
                            result += " и ";
                            break;
                        case ZoneLogicJoinOperator.Or:
                            result += " или ";
                            break;
                        default:
                            break;
                    }
                }

                if (clause.DeviceUID != Guid.Empty)
                {
                    result += "Сработка устройства " + clause.Device.PresentationAddress + " - " + clause.Device.Driver.Name;
                    continue;
                }

                if (clause.State == ZoneLogicState.Failure)
                {
                    result += "состояние неисправность прибора";
                    continue;
                }

                result += "состояние " + clause.State.ToDescription();

                string stringOperation = null;
                switch (clause.Operation)
                {
                    case ZoneLogicOperation.All:
                        stringOperation = "во всех зонах из";
                        break;

                    case ZoneLogicOperation.Any:
                        stringOperation = "в любой зоне из";
                        break;

                    default:
                        break;
                }

                result += " " + stringOperation + " " + GetCommaSeparatedZones(clause.Zones);
            }

            return result;
        }
		protected override bool Save()
		{
			var zoneLogic = new ZoneLogic();
			zoneLogic.JoinOperator = JoinOperator;

			foreach (var clauseViewModel in Clauses)
			{
				switch (clauseViewModel.SelectedState)
				{
					case ZoneLogicState.AM1TOn:
					case ZoneLogicState.ShuzOn:
						if (clauseViewModel.SelectedDevices.Count > 0)
						{
							var clause = new Clause()
							{
								State = clauseViewModel.SelectedState,
								Operation = clauseViewModel.SelectedOperation,
							};
							foreach (var device in clauseViewModel.SelectedDevices)
							{
								clause.DeviceUIDs.Add(device.UID);
								clause.Devices.Add(device);
							}

							zoneLogic.Clauses.Add(clause);
						}
						break;

					case ZoneLogicState.Failure:
					case ZoneLogicState.DoubleFire:
						{
							var clause = new Clause()
							{
								State = clauseViewModel.SelectedState,
							};
							zoneLogic.Clauses.Add(clause);
						}
						break;

					default:
						if (clauseViewModel.Zones.Count > 0)
						{
							var clause = new Clause()
							{
								State = clauseViewModel.SelectedState,
								Operation = clauseViewModel.SelectedOperation,
								ZoneUIDs = clauseViewModel.Zones,
								ZoneLogicMROMessageNo = clauseViewModel.SelectedMROMessageNo,
								ZoneLogicMROMessageType = clauseViewModel.SelectedMROMessageType
							};
							zoneLogic.Clauses.Add(clause);
						}
						break;
				}
			}
			FiresecManager.FiresecConfiguration.SetDeviceZoneLogic(_device, zoneLogic);
			return base.Save();
		}
Beispiel #12
0
        protected override bool Save()
        {
            var zoneLogic = new ZoneLogic();
            zoneLogic.JoinOperator = JoinOperator;

            foreach (var clauseViewModel in Clauses)
            {
                switch (clauseViewModel.SelectedState)
                {
                    case ZoneLogicState.AM1TOn:
                        if (clauseViewModel.SelectedDevice != null)
                        {
                            var clause = new Clause()
                            {
                                State = clauseViewModel.SelectedState,
                                Operation = clauseViewModel.SelectedOperation,
                                DeviceUID = clauseViewModel.SelectedDevice.UID,
                                Device = clauseViewModel.SelectedDevice
                            };
                            zoneLogic.Clauses.Add(clause);
                        }
                        break;

                    case ZoneLogicState.Failure:
                        {
                            var clause = new Clause()
                            {
                                State = clauseViewModel.SelectedState,
                            };
                            zoneLogic.Clauses.Add(clause);
                        }
                        break;

                    default:
                        if (clauseViewModel.Zones.Count > 0)
                        {
                            var clause = new Clause()
                            {
                                State = clauseViewModel.SelectedState,
                                Operation = clauseViewModel.SelectedOperation,
                                Zones = clauseViewModel.Zones
                            };
                            zoneLogic.Clauses.Add(clause);
                        }
                        break;
                }
            }
            _device.ZoneLogic = zoneLogic;
            return base.Save();
        }