Exemplo n.º 1
0
		public void Update()
		{
			var coreStates = new Firesec.Models.CoreState.config();
			var innerDevices = new List<devType>();
			foreach (var device in Devices)
			{
				var innerDevice = new devType()
				{
					name = device.DeviceState.Device.PlaceInTree
				};
				var innerStates = new List<stateType>();
				foreach (var state in device.DriverStates)
				{
					if (state.IsActive)
					{
						var innerState = new stateType()
						{
							id = state.DriverState.Id
						};
						innerStates.Add(innerState);
					}
				}
				innerDevice.state = innerStates.ToArray();
				innerDevices.Add(innerDevice);
			}
			coreStates.dev = innerDevices.ToArray();
			Watcher.ImitatorStateChanged(coreStates);
		}
Exemplo n.º 2
0
		void SetStates(Firesec.Models.CoreState.config coreState)
		{
			if (coreState == null)
				coreState = new Models.CoreState.config();
			if (coreState.dev == null)
				coreState.dev = new Models.CoreState.devType[0];

			foreach (var device in ConfigurationCash.DeviceConfiguration.Devices)
			{
				if (device.PlaceInTree == null)
				{
					Logger.Error("Watcher.SetStates deviceState.PlaceInTree = null");
					continue;
				}

				bool hasOneChangedState = false;

				Firesec.Models.CoreState.devType innerDevice = FindDevice(coreState.dev, device.PlaceInTree);
				if (innerDevice != null)
				{
					if (device.Driver == null)
					{
						Logger.Error("Watcher.SetStates deviceState.Device.Driver = null");
                        continue;
					}
					if (device.Driver.States == null)
					{
						Logger.Error("Watcher.SetStates deviceState.Device.Driver.States = null");
                        continue;
					}
                    if (innerDevice.state == null)
                    {
						innerDevice.state = (new List<Firesec.Models.CoreState.stateType>()).ToArray();
                    }

					foreach (var driverState in device.Driver.States)
					{
						var innerState = innerDevice.state.FirstOrDefault(a => a.id == driverState.Id);
						var state = device.DeviceState.States.FirstOrDefault(x => x.DriverState.Code == driverState.Code);
						if ((state != null) != (innerState != null))
						{
							hasOneChangedState = true;
						}

						if (innerState != null)
						{
							if (state == null)
							{
								var cloneddDiverState = driverState.Clone();
								if (cloneddDiverState.Name == "Состояние 1")
								{
									var property = device.Properties.FirstOrDefault(x => x.Name == "Event1");
									if (property != null && !string.IsNullOrEmpty(property.Value))
									{
										cloneddDiverState.Name = property.Value;
									}
								}
								if (cloneddDiverState.Name == "Состояние 2")
								{
									var property = device.Properties.FirstOrDefault(x => x.Name == "Event2");
									if (property != null && !string.IsNullOrEmpty(property.Value))
									{
										cloneddDiverState.Name = property.Value;
									}
								}
								state = new DeviceDriverState()
								{
									DriverState = cloneddDiverState
								};
								device.DeviceState.States.Add(state);
							}

							if (innerState.time != null)
								state.Time = JournalConverter.ConvertTime(innerState.time);
							else
								state.Time = null;
						}
						else
						{
							if (state != null)
								device.DeviceState.States.Remove(state);
						}
					}
				}
				else
				{
					hasOneChangedState = device.DeviceState.States.Count > 0;
					device.DeviceState.States.Clear();
				}

				if (hasOneChangedState)
				{
					ChangedDevices.Add(device.DeviceState);
				}
			}
		}