Пример #1
0
		public Watcher(GkDatabase gkDatabase)
		{
			GkDatabase = gkDatabase;
			GKCallbackResult = new GKCallbackResult();
			IsStopping = false;
			IsSuspending = false;
		}
Пример #2
0
		void OnGKCallbackResult(GKCallbackResult gkCallbackResult)
		{
			ApplicationService.Invoke(() =>
			{
				CopyGKStates(gkCallbackResult.GKStates);
			});
		}
Пример #3
0
		void OnGKCallbackResult(GKCallbackResult gkCallbackResult)
		{
			ApplicationService.Invoke(() =>
			{
				CopyGKStates(gkCallbackResult.GKStates);
				ServiceFactoryBase.Events.GetEvent<GKObjectsStateChangedEvent>().Publish(null);
			});
		}
Пример #4
0
		public static void NotifyGKObjectStateChanged(GKCallbackResult gkCallbackResult)
		{
			var callbackResult = new CallbackResult()
			{
				CallbackResultType = CallbackResultType.GKObjectStateChanged,
				GKCallbackResult = gkCallbackResult
			};
			CallbackManager.Add(callbackResult, ClientType.Monitor | ClientType.OPC | ClientType.WebService | ClientType.Other);
		}
Пример #5
0
		public static void OnGKCallbackResult(GKCallbackResult gkCallbackResult)
		{
			if (gkCallbackResult.JournalItems.Count +
				gkCallbackResult.GKStates.DeviceStates.Count +
				gkCallbackResult.GKStates.ZoneStates.Count +
				gkCallbackResult.GKStates.DirectionStates.Count +
				gkCallbackResult.GKStates.PumpStationStates.Count +
				gkCallbackResult.GKStates.MPTStates.Count +
				gkCallbackResult.GKStates.DelayStates.Count +
				gkCallbackResult.GKStates.PimStates.Count +
				gkCallbackResult.GKStates.GuardZoneStates.Count +
				gkCallbackResult.GKStates.DoorStates.Count +
				gkCallbackResult.GKStates.SKDZoneStates.Count +
				gkCallbackResult.GKStates.DeviceMeasureParameters.Count > 0)
			{
				if (GKCallbackResultEvent != null)
					GKCallbackResultEvent(gkCallbackResult);
			}
		}
Пример #6
0
		static void OnGKCallbackResultEvent(GKCallbackResult gkCallbackResult)
		{
			CheckPendingCards(gkCallbackResult);

			foreach (var journalItem in gkCallbackResult.JournalItems)
			{
				ProcessPassJournal(journalItem);
			}

			foreach (var doorState in gkCallbackResult.GKStates.DoorStates)
			{
				if (doorState.Door != null)
				{
					var enterZone = GKManager.SKDZones.FirstOrDefault(x => x.UID == doorState.Door.EnterZoneUID);
					if (enterZone != null)
					{
						GKProcessorManager.CalculateSKDZone(enterZone);
						if (!gkCallbackResult.GKStates.SKDZoneStates.Any(x => x.UID == enterZone.UID))
						{
							gkCallbackResult.GKStates.SKDZoneStates.Add(enterZone.State);
						}
					}
					var exitZone = GKManager.SKDZones.FirstOrDefault(x => x.UID == doorState.Door.ExitZoneUID);
					if (exitZone != null)
					{
						GKProcessorManager.CalculateSKDZone(exitZone);
						if (!gkCallbackResult.GKStates.SKDZoneStates.Any(x => x.UID == exitZone.UID))
						{
							gkCallbackResult.GKStates.SKDZoneStates.Add(exitZone.State);
						}
					}
				}
			}
			RubezhService.Service.RubezhService.NotifyGKObjectStateChanged(gkCallbackResult);
			if (gkCallbackResult.JournalItems.Count > 0)
				RubezhService.Service.RubezhService.AddCommonJournalItems(gkCallbackResult.JournalItems, null);
		}
Пример #7
0
		/// <summary>
		/// Обработка событий изменения состояния элементов.
		/// </summary>
		/// <param name="obj">Информация об изменении состояния.</param>
		private void OnServiceCallback(GKCallbackResult obj)
		{
			var states = obj.GKStates;
			Parallel.ForEach(states.DeviceStates, PlanElement.UpdateDeviceState);
			Parallel.ForEach(states.GuardZoneStates.Union(states.SKDZoneStates).Union(states.ZoneStates), PlanElement.UpdateZoneState);
			//foreach (var state in states.DelayStates) {
			//}
			//foreach (var state in states.DirectionStates) {
			//}
			//foreach (var state in states.DoorStates) {
			//}
			//foreach (var state in states.MPTStates) {
			//}
			//foreach (var state in states.PumpStationStates) {
			//}
		}
Пример #8
0
		static void OnGKCallbackResult(GKCallbackResult gkCallbackResult)
		{
			CopyGKStates(gkCallbackResult.GKStates);
			CopyDeviceMeasureParametersStates(gkCallbackResult.GKStates);
			if (AlarmsUpdaterHub.Instance != null)
			{
				AlarmsUpdaterHub.Instance.BroadcastAlarms();
			}

			if (SoundsUpdaterHub.Instance != null)
			{
				SoundsUpdaterHub.Instance.BroadcastSounds();
			}
		}
Пример #9
0
		static void CheckPendingCards(GKCallbackResult gkCallbackResult)
		{
			foreach (var journalItem in gkCallbackResult.JournalItems)
			{
				if (journalItem.JournalEventNameType == JournalEventNameType.Восстановление_связи_с_прибором || journalItem.JournalEventNameType == JournalEventNameType.Начало_мониторинга)
				{
					var device = GKManager.Devices.FirstOrDefault(x => x.UID == journalItem.ObjectUID);
					{
						using (var databaseService = new RubezhDAL.DataClasses.DbService())
						{
							if (device != null)
							{
								var pendingCards = databaseService.CardTranslator.GetAllPendingCards(device.UID);
								if (pendingCards == null)
									return;
								foreach (var pendingCard in pendingCards)
								{
									var operationResult = databaseService.CardTranslator.GetSingle(pendingCard.CardUID);
									if (!operationResult.HasError && operationResult.Result != null)
									{
										var card = operationResult.Result;
										var getAccessTemplateOperationResult = databaseService.AccessTemplateTranslator.GetSingle(card.AccessTemplateUID);
										var employeeOperationResult = databaseService.EmployeeTranslator.GetSingle(card.EmployeeUID);
										var employeeName = employeeOperationResult.Result != null ? employeeOperationResult.Result.FIO : "";

										if ((PendingCardAction)pendingCard.Action == PendingCardAction.Delete)
										{
											var result = GKSKDHelper.RemoveCard(device, card, databaseService);
											if (!result.HasError)
											{
												databaseService.CardTranslator.DeleteAllPendingCards(pendingCard.CardUID, device.UID);
											}
										}
										if (!getAccessTemplateOperationResult.HasError)
										{
											var accessTemplateDoors = getAccessTemplateOperationResult.Result != null ? getAccessTemplateOperationResult.Result.CardDoors : new List<CardDoor>();
											var controllerCardSchedules = GKSKDHelper.GetGKControllerCardSchedules(card, accessTemplateDoors);
											foreach (var controllerCardSchedule in controllerCardSchedules)
											{
												switch ((PendingCardAction)pendingCard.Action)
												{
													case PendingCardAction.Add:
													case PendingCardAction.Edit:
														var result = GKSKDHelper.AddOrEditCard(controllerCardSchedule, card, employeeName, dbService: databaseService);
														if (!result.HasError)
														{
															databaseService.CardTranslator.DeleteAllPendingCards(pendingCard.CardUID, device.UID);
														}
														break;
												}
											}
										}
									}
									else
									{
										databaseService.CardTranslator.DeleteAllPendingCards(pendingCard.CardUID, device.UID);
									}
								}
							}
						}
					}
				}
			}
		}
Пример #10
0
		void OnGKCallbackResult(GKCallbackResult gkCallbackResult)
		{
			GKProcessorManager.OnGKCallbackResult(GKCallbackResult);
		}
Пример #11
0
		bool InitializeMonitoring()
		{
			bool IsPingFailure = false;
			bool IsInTechnologicalRegime = false;
			bool IsGetStatesFailure = false;
			IsHashFailure = false;

			foreach (var descriptor in GkDatabase.Descriptors)
			{
				descriptor.GKBase.InternalState.Clear();
			}

			while (true)
			{
				LastUpdateTime = DateTime.Now;
				GKCallbackResult = new GKCallbackResult();
				foreach (var descriptor in GkDatabase.Descriptors)
				{
					descriptor.GKBase.InternalState.IsInitialState = true;
				}

				using (var gkLifecycleManager = new GKLifecycleManager(GkDatabase.RootDevice, "Проверка связи"))
				{
					var deviceInfo = DeviceBytesHelper.GetDeviceInfo(GkDatabase.RootDevice);
					var pingResult = string.IsNullOrEmpty(deviceInfo);
					if (IsPingFailure != pingResult)
					{
						GKCallbackResult = new GKCallbackResult();
						IsPingFailure = pingResult;
						if (IsPingFailure)
							AddFailureJournalItem(JournalEventNameType.Нет_связи_с_ГК, JournalEventDescriptionType.Старт_мониторинга);
						else
							AddFailureJournalItem(JournalEventNameType.Связь_с_ГК_восстановлена, JournalEventDescriptionType.Старт_мониторинга);

						foreach (var descriptor in GkDatabase.Descriptors)
						{
							descriptor.GKBase.InternalState.IsConnectionLost = IsPingFailure;
							descriptor.GKBase.InternalState.IsInitialState = !IsPingFailure;
						}
						NotifyAllObjectsStateChanged();
						OnGKCallbackResult(GKCallbackResult);
					}

					if (IsPingFailure)
					{
						gkLifecycleManager.SetError("Ошибка");
						if (ReturnAfterWait(5000))
							return false;
						continue;
					}
				}

				var result = CheckTechnologicalRegime();
				if (IsInTechnologicalRegime != result)
				{
					GKCallbackResult = new GKCallbackResult();
					IsInTechnologicalRegime = result;
					if (IsInTechnologicalRegime)
						AddFailureJournalItem(JournalEventNameType.ГК_в_технологическом_режиме, "Старт мониторинга");
					else
						AddFailureJournalItem(JournalEventNameType.ГК_в_рабочем_режиме, "Старт мониторинга");

					NotifyAllObjectsStateChanged();
					OnGKCallbackResult(GKCallbackResult);
				}

				if (IsInTechnologicalRegime)
				{
					GKLifecycleManager.Add(GkDatabase.RootDevice, "Устройство в технологическом режиме");
					if (ReturnAfterWait(5000))
						return false;
					continue;
				}

				using (var gkLifecycleManager = new GKLifecycleManager(GkDatabase.RootDevice, "Запрос хэша"))
				{
					var hashResult = GetHashResult();

					if (IsHashFailure != hashResult.Item1)
					{
						GKCallbackResult = new GKCallbackResult();
						IsHashFailure = hashResult.Item1;
						if (IsHashFailure)
							AddFailureJournalItem(JournalEventNameType.Конфигурация_прибора_не_соответствует_конфигурации_ПК, JournalEventDescriptionType.Не_совпадает_хэш);
						else
							AddFailureJournalItem(JournalEventNameType.Конфигурация_прибора_соответствует_конфигурации_ПК, JournalEventDescriptionType.Совпадает_хэш);

						foreach (var descriptor in GkDatabase.Descriptors)
						{
							descriptor.GKBase.InternalState.IsDBMissmatch = IsHashFailure;
							descriptor.GKBase.InternalState.IsInitialState = false;
						}
						NotifyAllObjectsStateChanged();
						OnGKCallbackResult(GKCallbackResult);
					}

					if (IsHashFailure)
					{
						gkLifecycleManager.SetError(hashResult.Item2 == null ? "Ошибка" : "Не совпадает хэш");
						if (ReturnAfterWait(5000))
							return false;
						continue;
					}
				}

				GKCallbackResult = new GKCallbackResult();
				if (!ReadMissingJournalItems())
					AddFailureJournalItem(JournalEventNameType.Ошибка_при_синхронизации_журнала);
				OnGKCallbackResult(GKCallbackResult);

				GKCallbackResult = new GKCallbackResult();
				GetAllStates();
				result = IsDBMissmatchDuringMonitoring || !IsConnected;
				if (IsGetStatesFailure != result)
				{
					IsGetStatesFailure = result;
					if (IsGetStatesFailure)
						AddFailureJournalItem(JournalEventNameType.Ошибка_при_опросе_состояний_компонентов_ГК, DBMissmatchDuringMonitoringReason);
					else
						AddFailureJournalItem(JournalEventNameType.Устранена_ошибка_при_опросе_состояний_компонентов_ГК);
				}
				using (var gkLifecycleManager = new GKLifecycleManager(GkDatabase.RootDevice, "Передача состояний объектов"))
				{
					OnGKCallbackResult(GKCallbackResult);
				}

				if (IsGetStatesFailure)
				{
					GKLifecycleManager.Add(GkDatabase.RootDevice, "Ошибки при опросе состояний объектов");
					if (ReturnAfterWait(5000))
						return false;
					continue;
				}

				using (var gkLifecycleManager = new GKLifecycleManager(GkDatabase.RootDevice, "Передача состояний объектов"))
				{
					GKCallbackResult = new GKCallbackResult();
					foreach (var descriptor in GkDatabase.Descriptors)
					{
						descriptor.GKBase.InternalState.IsInitialState = false;
					}
					NotifyAllObjectsStateChanged();
					OnGKCallbackResult(GKCallbackResult);
				}

				return true;
			}
		}
Пример #12
0
		void OnRunThread()
		{
			while (true)
			{
				try
				{
					if (IsStopping)
						return;
					if (!InitializeMonitoring())
						return;
					if (IsStopping)
						return;
				}
				catch (Exception e)
				{
					AddMessage(JournalEventNameType.Ошибка_инициализации_мониторинга);
					Logger.Error(e, "JournalWatcher.InitializeMonitoring");
				}

				GKCallbackResult = new GKCallbackResult();
				var journalItem = new JournalItem()
					{
						SystemDateTime = DateTime.Now,
						DeviceDateTime = DateTime.Now,
						JournalObjectType = JournalObjectType.GKDevice,
						ObjectUID = GkDatabase.RootDevice.UID,
						JournalEventNameType = JournalEventNameType.Начало_мониторинга,
					};
				AddJournalItem(journalItem);
				OnGKCallbackResult(GKCallbackResult);

				while (true)
				{
					if (IsStopping)
						return;

					Monitor.TryEnter(CallbackResultLocker, TimeSpan.FromSeconds(30));
					{
						GKCallbackResult = new GKCallbackResult();
					}
					Monitor.Exit(CallbackResultLocker);

					RunMonitoring();

					Monitor.TryEnter(CallbackResultLocker, TimeSpan.FromSeconds(30));
					{
						OnGKCallbackResult(GKCallbackResult);
					}
					Monitor.Exit(CallbackResultLocker);

					if (IsStopping)
						return;

					if (IsHashFailure)
						break;

					if (StopEvent != null)
					{
						var pollInterval = 10;
						var property = GkDatabase.RootDevice.Properties.FirstOrDefault(x => x.Name == "PollInterval");
						if (property != null)
						{
							pollInterval = property.Value;
						}
						if (ReturnAfterWait(pollInterval))
							break;
					}

					WaitIfSuspending();
					LastUpdateTime = DateTime.Now;
				}
			}
		}
Пример #13
0
		void SetDescriptorsSuspending(bool isSuspending)
		{
			Monitor.TryEnter(CallbackResultLocker, TimeSpan.FromSeconds(30));
			{
				GKCallbackResult = new GKCallbackResult();
				foreach (var descriptor in GkDatabase.Descriptors)
				{
					if (descriptor.GKBase.InternalState != null)
					{
						descriptor.GKBase.InternalState.IsSuspending = isSuspending;
					}
				}
				NotifyAllObjectsStateChanged();
				OnGKCallbackResult(GKCallbackResult);
			}
			Monitor.Exit(CallbackResultLocker);
		}
Пример #14
0
		public static void AddGKMessage(JournalEventNameType journalEventNameType, JournalEventDescriptionType journalEventDescriptionType, string description, GKBase gkBase, string userName)
		{
			Guid uid = Guid.Empty;
			var journalObjectType = JournalObjectType.None;
			if (gkBase != null)
			{
				uid = gkBase.UID;
				if (gkBase is GKDevice)
				{
					journalObjectType = JournalObjectType.GKDevice;
				}
				if (gkBase is GKZone)
				{
					journalObjectType = JournalObjectType.GKZone;
				}
				if (gkBase is GKDirection)
				{
					journalObjectType = JournalObjectType.GKDirection;
				}
				if (gkBase is GKDelay)
				{
					journalObjectType = JournalObjectType.GKDelay;
				}
				if (gkBase is GKPim)
				{
					journalObjectType = JournalObjectType.GKPim;
				}
				if (gkBase is GKGuardZone)
				{
					journalObjectType = JournalObjectType.GKGuardZone;
				}
				if (gkBase is GKSKDZone)
				{
					journalObjectType = JournalObjectType.GKSKDZone;
				}
				if (gkBase is GKDoor)
				{
					journalObjectType = JournalObjectType.GKDoor;
				}
				if (gkBase is GKMPT)
				{
					journalObjectType = JournalObjectType.GKMPT;
				}
				if (gkBase is GKPumpStation)
				{
					journalObjectType = JournalObjectType.GKPumpStation;
				}
			}

			var journalItem = new JournalItem
			{
				SystemDateTime = DateTime.Now,
				DeviceDateTime = null,
				JournalObjectType = journalObjectType,
				JournalEventNameType = journalEventNameType,
				JournalEventDescriptionType = journalEventDescriptionType,
				DescriptionText = description,
				ObjectUID = uid,
				UserName = userName,
				JournalSubsystemType = JournalSubsystemType.GK
			};
			if (gkBase != null)
			{
				journalItem.ObjectName = gkBase.PresentationName;
				var gkObjectNo = gkBase.GKDescriptorNo;
				if (gkObjectNo > 0)
					journalItem.JournalDetalisationItems.Add(new JournalDetalisationItem("Компонент ГК", gkObjectNo.ToString()));
			}

			var gkCallbackResult = new GKCallbackResult();
			gkCallbackResult.JournalItems.Add(journalItem);
			OnGKCallbackResult(gkCallbackResult);
		}