public EffectorDeviceTable(FlashDatabase panelDatabase, BinaryDevice binaryDevice, bool isRemote)
			: base(panelDatabase, isRemote ? "Внешнее устройство " : "" + binaryDevice.Device.DottedPresentationAddressAndName)
		{
			binaryDevice.TableBase = this;
			BinaryDevice = binaryDevice;
			Device = binaryDevice.Device;
			IsRemote = isRemote;
		}
Beispiel #2
0
		public void CreatreDevices()
		{
			foreach (var device in ParentPanel.GetRealChildren())
			{
				var binaryDevice = new BinaryDevice()
				{
					ParentPanel = ParentPanel,
					Device = device,
					BinaryPanel = this
				};
				device.BinaryDevice = binaryDevice;
				BinaryLocalDevices.Add(binaryDevice);
			}
		}
Beispiel #3
0
		public void Initialize()
		{
			foreach (var device in ParentPanel.GetRealChildren())
			{
				var binaryDevice = new BinaryDevice()
				{
					ParentPanel = ParentPanel,
					Device = device
				};
				device.BinaryDevice = binaryDevice;
				BinaryLocalDevices.Add(binaryDevice);

				foreach (var zone in device.ZonesInLogic)
				{
					var binaryLocalZone = BinaryLocalZones.FirstOrDefault(x => x.Zone == zone);
					if (binaryLocalZone != null)
					{
						//if (!binaryDevice.BinaryZones.Contains(binaryLocalZone))
						//    binaryDevice.BinaryZones.Add(binaryLocalZone);
					}

					if (binaryLocalZone == null)
					{
						foreach (var binaryRemoteZone in BinaryRemoteZones)
						{
							//if (!binaryDevice.BinaryZones.Contains(binaryRemoteZone))
							//    binaryDevice.BinaryZones.Add(binaryRemoteZone);

							foreach (var binaryPanel in binaryRemoteZone.BinaryPanels)
							{
								if (binaryPanel.ParentPanel != ParentPanel)
								{
									if (!remoteDevices.Contains(device))
									{
										remoteDevices.Add(device);
										binaryPanel.BinaryRemoteDevices.Add(binaryDevice);
									}
								}
							}
						}
					}
				}
			}
		}
		void CreateZones()
		{
			foreach (var device in ConfigurationManager.Devices)
			{
				var localBinaryPanel = BinaryPanels.FirstOrDefault(x => x.ParentPanel == device.ParentPanel);
				if (device.Zone != null)
				{
					localBinaryPanel.TempLocalZones.Add(device.Zone);
				}
			}

			foreach (var device in ConfigurationManager.Devices)
			{
				var localBinaryPanel = BinaryPanels.FirstOrDefault(x => x.ParentPanel == device.ParentPanel);

				var hasLocalZonesInAllClauses = false;
				foreach (var clause in device.ZoneLogic.Clauses)
				{
					foreach (var zone in clause.Zones)
					{
						foreach (var deviceInZone in zone.DevicesInZone)
						{
							if (deviceInZone.ParentPanel.UID == localBinaryPanel.ParentPanel.UID)
							{
								hasLocalZonesInAllClauses = true;
								break;
							}
						}
					}
				}
				foreach (var clause in device.ZoneLogic.Clauses)
				{
					var hasLocalZones = false;
					foreach (var zone in clause.Zones)
					{
						foreach (var deviceInZone in zone.DevicesInZone)
						{
							if (deviceInZone.ParentPanel.UID == localBinaryPanel.ParentPanel.UID)
							{
								hasLocalZones = true;
								break;
							}
						}
					}

					foreach (var zone in clause.Zones)
					{
						if (zone.ZoneType == ZoneType.Fire)
						{
							if (zone.DevicesInZone.Any(x => x.ParentPanel.UID == localBinaryPanel.ParentPanel.UID))
							{
								localBinaryPanel.TempLocalZones.Add(zone);
							}
							if (clause.Operation.Value == ZoneLogicOperation.All)
							{
								localBinaryPanel.TempLocalZones.Add(zone);
								if (hasLocalZones)
								{
									localBinaryPanel.TempRemoteZones.Add(zone);
								}
							}
							if (hasLocalZonesInAllClauses && device.ZoneLogic.JoinOperator == ZoneLogicJoinOperator.And)
							{
								localBinaryPanel.TempRemoteZones.Add(zone);
							}
						}
					}
				}
			}

			foreach (var binaryPanel in BinaryPanels)
			{
				foreach (var zone in binaryPanel.TempRemoteZones.OrderBy(x => x.No))
				{
					AddRemoteZoneToPanel(binaryPanel, zone);
				}
				foreach (var zone in binaryPanel.TempLocalZones.OrderBy(x => x.No))
				{
					AddLocalZoneToPanel(binaryPanel, zone);
				}
			}

			foreach (var device in ConfigurationManager.Devices)
			{
				var localBinaryPanel = BinaryPanels.FirstOrDefault(x => x.ParentPanel == device.ParentPanel);

				foreach (var clause in device.ZoneLogic.Clauses)
				{
					var binaryPanels = new HashSet<Device>();
					foreach (var clauseZone in clause.Zones)
					{
						foreach (var zoneDevice in clauseZone.DevicesInZone)
						{
							var clauseBinaryPanel = BinaryPanels.FirstOrDefault(x => x.ParentPanel == zoneDevice.ParentPanel);
							binaryPanels.Add(clauseBinaryPanel.ParentPanel);
						}
					}
					foreach (var zone in clause.Zones)
					{
						if (!device.BinaryDevice.BinaryZones.Any(x => x.Zone.UID == zone.UID))
						{
							var existingRemoteBinaryZone = localBinaryPanel.BinaryRemoteZones.FirstOrDefault(x => x.Zone.UID == zone.UID);
							if (existingRemoteBinaryZone != null)
							{
								existingRemoteBinaryZone.IsRemote = true;
								device.BinaryDevice.BinaryZones.Add(existingRemoteBinaryZone);
							}
							else
							{
								var existingLocalBinaryZone = localBinaryPanel.BinaryLocalZones.FirstOrDefault(x => x.Zone.UID == zone.UID);
								if (existingLocalBinaryZone != null)
								{
									device.BinaryDevice.BinaryZones.Add(existingLocalBinaryZone);
								}
							}
						}
					}
				}
			}

			foreach (var zone in ConfigurationManager.Zones)
			{
				var binaryPanels = new HashSet<Device>();
				foreach (var device in zone.DevicesInZone)
				{
					binaryPanels.Add(device.ParentPanel);
				}

				foreach (var binaryPanel in binaryPanels)
				{
					var parentPanel = binaryPanel;
					var localBinaryPanel = BinaryPanels.FirstOrDefault(x => x.ParentPanel == parentPanel);

					foreach (var device in zone.DevicesInZoneLogic)
					{
						foreach (var clause in device.ZoneLogic.Clauses)
						{
							foreach (var clauseZone in clause.Zones)
							{
								if (clauseZone.UID == zone.UID)
								{
									if (device.ParentPanel.UID != parentPanel.UID)
									{
										var binaryDevice = new BinaryDevice()
										{
											Device = device,
											ParentPanel = parentPanel,
										};
										localBinaryPanel.BinaryRemoteDevices.Add(binaryDevice);
									}
								}
							}
						}
					}
				}
			}

			foreach (var binaryPanel in BinaryPanels)
			{
				binaryPanel.BinaryRemoteDevices = binaryPanel.BinaryRemoteDevices.OrderBy(x => x.Device.ParentPanel.IntAddress * 256 * 256 + x.Device.IntAddress).ToList();
			}

			foreach (var binaryPanel in BinaryPanels)
			{
				var guardZones = binaryPanel.BinaryLocalZones.Where(x => x.Zone.ZoneType == ZoneType.Guard).OrderBy(x => x.Zone.No);
				var fireZones = binaryPanel.BinaryLocalZones.Where(x => x.Zone.ZoneType == ZoneType.Fire).OrderBy(x => x.Zone.No);
				var sortedZones = guardZones.ToList();
				sortedZones.AddRange(fireZones);

				binaryPanel.BinaryLocalZones = sortedZones;
				for (int i = 0; i < binaryPanel.BinaryLocalZones.Count; i++)
				{
					binaryPanel.BinaryLocalZones[i].LocalNo = i + 1;
				}
			}
		}