public PumpStationDetailsViewModel(XPumpStation pumpStation = null)
		{
			if (pumpStation == null)
			{
				Title = "Создание новой насосоной станции";

				PumpStation = new XPumpStation()
				{
					Name = "Насосная станция",
					No = 1
				};
				if (XManager.PumpStations.Count != 0)
					PumpStation.No = (ushort)(XManager.PumpStations.Select(x => x.No).Max() + 1);
			}
			else
			{
				Title = string.Format("Свойства Насосной станции: {0}", pumpStation.PresentationName);
				PumpStation = pumpStation;
			}
			CopyProperties();

			var availableNames = new HashSet<string>();
			var availableDescription = new HashSet<string>();
			foreach (var existingPumpStation in XManager.PumpStations)
			{
				availableNames.Add(existingPumpStation.Name);
			}
			AvailableNames = new ObservableCollection<string>(availableNames);
		}
Ejemplo n.º 2
0
		public PumpStationViewModel(XPumpStation pumpStation)
		{
			PumpStation = pumpStation;
			ChangeStartLogicCommand = new RelayCommand(OnChangeStartLogic);
			ChangeStopLogicCommand = new RelayCommand(OnChangeStopLogic);
			ChangeAutomaticOffLogicCommand = new RelayCommand(OnChangeAutomaticOffLogic);
			Update();
		}
Ejemplo n.º 3
0
		public ObjectViewModel(XPumpStation pumpStation)
		{
			PumpStation = pumpStation;
			Name = pumpStation.PresentationName;
			ImageSource = "/Controls;component/Images/BPumpStation.png";
			Address = "";
			PresentationZone = "";
			ObjectType = ObjectType.PumpStation;
		}
Ejemplo n.º 4
0
		static bool ValidateEmptyPumpStation(XPumpStation pumpStation)
		{
			var count = pumpStation.InputZones.Count + pumpStation.InputDevices.Count + pumpStation.InputDirections.Count + pumpStation.NSDevices.Count;
			if (count == 0)
			{
				Errors.Add(new PumpStationValidationError(pumpStation, "В НС отсутствуют входные или выходные объекты", ValidationErrorLevel.CannotWrite));
				return false;
			}
			return true;
		}
Ejemplo n.º 5
0
		public PumpStationDescriptor(GkDatabase gkDatabase, XPumpStation pumpStation)
		{
			DatabaseType = DatabaseType.Gk;
			DescriptorType = DescriptorType.PumpStation;
			PumpStation = pumpStation;

			MainDelay = new XDelay();
			MainDelay.UID = GuidHelper.CreateOn(PumpStation.UID);
			gkDatabase.AddDelay(MainDelay);

			Build();
		}
Ejemplo n.º 6
0
		public PumpStationViewModel(XPumpStation pumpStation)
		{
			ShowJournalCommand = new RelayCommand(OnShowJournal);
			ShowPropertiesCommand = new RelayCommand(OnShowProperties);
			PumpStation = pumpStation;
			State.StateChanged += new System.Action(OnStateChanged);
			OnStateChanged();

			Pumps = new ObservableCollection<DeviceViewModel>();
			foreach (var device in PumpStation.NSDevices)
			{
				var deviceViewModel = DevicesViewModel.Current.AllDevices.FirstOrDefault(x => x.Device == device);
				Pumps.Add(deviceViewModel);
			}
		}
Ejemplo n.º 7
0
		static void ValidateDifferentGK(XPumpStation pumpStation)
		{
			var devices = new List<XDevice>();
			devices.AddRange(pumpStation.InputDevices);
			devices.AddRange(pumpStation.NSDevices);
			foreach (var zone in pumpStation.InputZones)
			{
				devices.AddRange(zone.Devices);
			}
			foreach (var direction in pumpStation.InputDirections)
			{
				devices.AddRange(direction.InputDevices);
			}

			if (AreDevicesInSameGK(devices))
				Errors.Add(new PumpStationValidationError(pumpStation, "НС содержит объекты устройства разных ГК", ValidationErrorLevel.CannotWrite));
		}
		public PumpStationDetailsViewModel(XPumpStation pumpStation)
		{
			PumpStation = pumpStation;
			State.StateChanged += new Action(OnStateChanged);
			InitializePlans();

			ShowCommand = new RelayCommand(OnShow);
			ShowJournalCommand = new RelayCommand(OnShowJournal);
			SetAutomaticStateCommand = new RelayCommand(OnSetAutomaticState, CanSetAutomaticState);
			SetManualStateCommand = new RelayCommand(OnSetManualState, CanSetManualState);
			SetIgnoreStateCommand = new RelayCommand(OnSetIgnoreState, CanSetIgnoreState);
			TurnOnCommand = new RelayCommand(OnTurnOn);
			TurnOnNowCommand = new RelayCommand(OnTurnOnNow);
			TurnOffCommand = new RelayCommand(OnTurnOff);
			ForbidStartCommand = new RelayCommand(OnForbidStart);

			Title = PumpStation.PresentationName;
			TopMost = true;
		}
Ejemplo n.º 9
0
		public PumpStationCreator(GkDatabase gkDatabase, XPumpStation pumpStation, XDelay mainDelay)
		{
			GkDatabase = gkDatabase;
			PumpStation = pumpStation;
			MainDelay = mainDelay;

			PumpDelays = new List<PumpDelay>();

			FirePumpDevices = new List<XDevice>();
			foreach (var nsDevice in pumpStation.NSDevices)
			{
				if (nsDevice.Driver.IsPump)
				{
					var pumpTypeProperty = nsDevice.Properties.FirstOrDefault(x => x.Name == "PumpType");
					if (pumpTypeProperty != null)
					{
						if (pumpTypeProperty.Value == 0)
							FirePumpDevices.Add(nsDevice);
						if (pumpTypeProperty.Value == 1)
							JNPumpDevice = nsDevice;
					}
				}
			}
		}
		public ArchivePumpStationViewModel(XPumpStation pumpStation)
		{
			PumpStation = pumpStation;
			Name = pumpStation.PresentationName;
		}
Ejemplo n.º 11
0
		static void ValidatePumpStationOutput(XPumpStation pumpStation)
		{
			var pumpsCount = pumpStation.NSDevices.Count(x => x.Driver.DriverType == XDriverType.FirePump);
			if (pumpsCount == 0)
			{
				Errors.Add(new PumpStationValidationError(pumpStation, "В НС отсутствуют насосы", ValidationErrorLevel.CannotWrite));
			}
			else
			{
				if (pumpStation.NSPumpsCount > pumpsCount)
					Errors.Add(new PumpStationValidationError(pumpStation, "В НС основных насосов меньше реально располагаемых", ValidationErrorLevel.CannotWrite));
			}

			var jnPumpsCount = pumpStation.NSDevices.Count(x => x.DriverType == XDriverType.JockeyPump);
			if (jnPumpsCount > 1)
				Errors.Add(new PumpStationValidationError(pumpStation, "В НС количество подключенных ЖН больше 1", ValidationErrorLevel.CannotWrite));

			if (jnPumpsCount == 1)
			{
				if (pumpStation.InputZones.Count > 0)
					Errors.Add(new PumpStationValidationError(pumpStation, "В условии пуска НС c ЖН не могут участвовать зоны", ValidationErrorLevel.CannotWrite));

				if (pumpStation.InputDirections.Count > 0)
					Errors.Add(new PumpStationValidationError(pumpStation, "В условии пуска НС c ЖН не могут участвовать направления", ValidationErrorLevel.CannotWrite));

				if (!pumpStation.InputDevices.All(x => x.DriverType == XDriverType.AM_1))
					Errors.Add(new PumpStationValidationError(pumpStation, "В НС c ЖН во входных устройствах могут участвовать только АМ1", ValidationErrorLevel.CannotWrite));
			}
		}
Ejemplo n.º 12
0
		static void ValidatePumpStationInput(XPumpStation pumpStation)
		{
			if (pumpStation.StartLogic.Clauses.Count == 0)
				Errors.Add(new PumpStationValidationError(pumpStation, "В НС отсутствует условие для запуска", ValidationErrorLevel.CannotWrite));
		}
Ejemplo n.º 13
0
		static void ValidatePumpInNSInputLogic(XPumpStation pumpStation)
		{
			foreach (var clause in pumpStation.StartLogic.Clauses)
			{
				foreach (var device in clause.Devices)
				{
					if (device.Driver.IsPump)
					{
						Errors.Add(new PumpStationValidationError(pumpStation, "В условии для запуска не может участвовать ШУН", ValidationErrorLevel.CannotWrite));
						return;
					}
				}
			}
		}
Ejemplo n.º 14
0
		static void ValidateEmptyObjectsInPumpStation(XPumpStation pumpStation)
		{
			foreach (var zone in pumpStation.InputZones)
			{
				if (zone.Devices.Count == 0)
				{
					Errors.Add(new PumpStationValidationError(pumpStation, "В НС входит пустая зона " + zone.PresentationName, ValidationErrorLevel.CannotWrite));
				}
			}

			foreach (var direction in pumpStation.InputDirections)
			{
				if (direction.InputDevices.Count + direction.InputZones.Where(x => x.Devices.Count > 0).Count() == 0)
				{
					Errors.Add(new PumpStationValidationError(pumpStation, "В НС входит пустое направление " + direction.PresentationName, ValidationErrorLevel.CannotWrite));
				}
			}
		}
Ejemplo n.º 15
0
		public XPumpStationState(XPumpStation pumpStation)
		{
			PumpStation = pumpStation;
		}
Ejemplo n.º 16
0
		bool Parse(List<byte> bytes, int descriptorNo)
		 {
			var internalType = BytesHelper.SubstructShort(bytes, 0);
			var controllerAdress = BytesHelper.SubstructShort(bytes, 2);
			var adressOnController = BytesHelper.SubstructShort(bytes, 4);
			var physicalAdress = BytesHelper.SubstructShort(bytes, 6);
			if(internalType == 0)
				return true;
			var description = BytesHelper.BytesToStringDescription(bytes);
			var driver = XManager.Drivers.FirstOrDefault(x => x.DriverTypeNo == internalType);
			if (internalType == 0x70)
			{
				if (description[0] == 'П')
					driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.FirePump);
				if (description[0] == 'Ж')
					driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.JockeyPump);
				if (description[0] == 'Д')
					driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.DrainagePump);
			}
			if (driver != null)
			{
				if (driver.DriverType == XDriverType.GK && descriptorNo > 1)
				{
					driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.KAU);
					if (bytes[0x3a] == 1)
					{
						driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.RSR2_KAU);
					}
				}
				if (driver.DriverType == XDriverType.GKIndicator && descriptorNo > 14)
					driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.KAUIndicator);

				var shleifNo = (byte)(physicalAdress / 256) + 1;
				var device = new XDevice
				{
					Driver = driver,
					DriverUID = driver.UID,
					IntAddress = (byte)(physicalAdress % 256),
				};
				if (driver.DriverType == XDriverType.GK)
				{
					device.Properties.Add(new XProperty{Name = "IPAddress",StringValue = IpAddress});
					ControllerDevices.Add(controllerAdress, device);
					DeviceConfiguration.RootDevice.Children.Add(device);
					GkDevice = device;
				}
				if (driver.IsKauOrRSR2Kau)
				{
					device.IntAddress = (byte)(controllerAdress % 256);
					var modeProperty = new XProperty
					{
						Name = "Mode",
						Value = (byte)(controllerAdress / 256)
					};
					device.DeviceProperties.Add(modeProperty);
					ControllerDevices.Add(controllerAdress, device);
					GkDevice.Children.Add(device);
					for (int i = 0; i < 8; i++)
					{
						var shleif = new XDevice();
						shleif.Driver = driver.DriverType == XDriverType.KAU ? XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.KAU_Shleif) : XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.RSR2_KAU_Shleif);
						shleif.DriverUID = shleif.Driver.UID;
						shleif.IntAddress = (byte)(i + 1);
						device.Children.Add(shleif);
					}
				}
				if (driver.DriverType != XDriverType.GK && !driver.IsKauOrRSR2Kau && driver.DriverType != XDriverType.System)
				{
					var controllerDevice = ControllerDevices.FirstOrDefault(x => x.Key == controllerAdress);
					if (controllerDevice.Value != null)
					{
						if(1 <= shleifNo && shleifNo <= 8 && physicalAdress != 0)
						{
							var shleif = controllerDevice.Value.Children.FirstOrDefault(x => (x.DriverType == XDriverType.KAU_Shleif || x.DriverType == XDriverType.RSR2_KAU_Shleif) && x.IntAddress == shleifNo);
							shleif.Children.Add(device);
						}
						else
						{
							if (controllerDevice.Value.Driver.DriverType == XDriverType.GK)
								device.IntAddress = (byte) (controllerDevice.Value.Children.Where(x => !x.Driver.HasAddress).Count() + 2);
							else
								device.IntAddress = (byte)(controllerDevice.Value.Children.Where(x => !x.Driver.HasAddress).Count() + 1);
							controllerDevice.Value.Children.Add(device);
						}
					}
				}
				return true;
			}

			if(internalType == 0x100 || internalType == 0x106)
			{
				var isPumpStation = false;
				ushort no;
				try
				{
					if (description[0] == '0')
						isPumpStation = true;
					no = (ushort)Int32.Parse(description.Substring(0, description.IndexOf(".")));
					description = description.Substring(description.IndexOf(".") + 1);
				}
				catch
				{
					Error = "Невозможно получить номер объекта с дескриптором " + descriptorNo;
					return false;
				}

				if (internalType == 0x100)
				{
					var zone = new XZone
					{
						Name = description,
						No = no,
						GkDatabaseParent = GkDevice
					};
					DeviceConfiguration.Zones.Add(zone);
					return true;
				}
				if (internalType == 0x106)
				{
					if (isPumpStation)
					{
						var pumpStation = new XPumpStation()
						{
							Name = description,
							No = no,
							GkDatabaseParent = GkDevice
						};
						DeviceConfiguration.PumpStations.Add(pumpStation);
					}
					else
					{
						var direction = new XDirection
						{
							Name = description,
							No = no,
							GkDatabaseParent = GkDevice
						};
						DeviceConfiguration.Directions.Add(direction);
					}
					return true;
				}
			}
			return true;
		}
Ejemplo n.º 17
0
		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;
		}