public void AddJournalItem(JournalItem journalItem) { GKDBHelper.Add(journalItem); var gkCallbackResult = new GKCallbackResult(); gkCallbackResult.JournalItems.Add(journalItem); NotifyGKObjectStateChanged(gkCallbackResult); }
public static void NotifyGKObjectStateChanged(GKCallbackResult gkCallbackResult) { var callbackResult = new CallbackResult() { CallbackResultType = CallbackResultType.GKObjectStateChanged, GKCallbackResult = gkCallbackResult }; CallbackManager.Add(callbackResult); }
public static void OnGKCallbackResult(GKCallbackResult gkCallbackResult) { if (gkCallbackResult.JournalItems.Count + gkCallbackResult.GKStates.DeviceStates.Count + gkCallbackResult.GKStates.ZoneStates.Count + gkCallbackResult.GKStates.DirectionStates.Count + gkCallbackResult.GKStates.DelayStates.Count + gkCallbackResult.GKStates.PimStates.Count + gkCallbackResult .GKStates.DeviceMeasureParameters.Count > 0) { if (GKCallbackResultEvent != null) GKCallbackResultEvent(gkCallbackResult); } }
static void OnGKCallbackResultEvent(GKCallbackResult gkCallbackResult) { FiresecService.Service.FiresecService.NotifyGKObjectStateChanged(gkCallbackResult); }
public static void AddGKMessage(EventName message, string description, XBase xBase, string userName, bool isAdministrator = false) { Guid uid = Guid.Empty; var journalItemType = JournalItemType.System; if (xBase != null) { if (xBase is XDevice) { uid = (xBase as XDevice).UID; journalItemType = JournalItemType.Device; } if (xBase is XZone) { uid = (xBase as XZone).UID; journalItemType = JournalItemType.Zone; } if (xBase is XDirection) { uid = (xBase as XDirection).UID; journalItemType = JournalItemType.Direction; } if (xBase is XDelay) { uid = (xBase as XDelay).UID; journalItemType = JournalItemType.Delay; } if (xBase is XPim) { uid = (xBase as XPim).UID; journalItemType = JournalItemType.Pim; } } var journalItem = new JournalItem() { SystemDateTime = DateTime.Now, DeviceDateTime = DateTime.Now, JournalItemType = journalItemType, StateClass = EventNamesHelper.GetStateClass(message), Name = message.ToDescription(), Description = description, ObjectUID = uid, ObjectStateClass = XStateClass.Norm, UserName = userName, SubsystemType = XSubsystemType.System }; if (xBase != null) { journalItem.ObjectName = xBase.PresentationName; journalItem.GKObjectNo = (ushort)xBase.GKDescriptorNo; } GKDBHelper.Add(journalItem); OnNewJournalItem(journalItem, isAdministrator); var gkCallbackResult = new GKCallbackResult(); gkCallbackResult.JournalItems.Add(journalItem); OnGKCallbackResult(gkCallbackResult); }
static void OnGKCallbackResult(GKCallbackResult gkCallbackResult) { ApplicationService.Invoke(() => { if (gkCallbackResult.JournalItems.Count > 0) { //ServiceFactoryBase.Events.GetEvent<NewXJournalEvent>().Publish(gkCallbackResult.JournalItems); } CopyGKStates(gkCallbackResult.GKStates); }); }
static void OnGKCallbackResult(GKCallbackResult gkCallbackResult) { ApplicationService.Invoke(() => { CopyGKStates(gkCallbackResult.GKStates); }); }
void OnGKCallbackResult(GKCallbackResult gkCallbackResult) { ApplicationService.Invoke(() => { if (gkCallbackResult.JournalItems.Count > 0) { ServiceFactory.Events.GetEvent<NewXJournalEvent>().Publish(gkCallbackResult.JournalItems); } CopyGKStates(gkCallbackResult.GKStates); ServiceFactoryBase.Events.GetEvent<GKObjectsStateChangedEvent>().Publish(null); }); }
void SetDescriptorsSuspending(bool isSuspending) { lock (CallbackResultLocker) { GKCallbackResult = new GKCallbackResult(); foreach (var descriptor in GkDatabase.Descriptors) { if (descriptor.XBase.BaseState != null) { descriptor.XBase.BaseState.IsSuspending = isSuspending; } } NotifyAllObjectsStateChanged(); OnGKCallbackResult(GKCallbackResult); } }
void OnGKCallbackResult(GKCallbackResult gkCallbackResult) { GKProcessorManager.OnGKCallbackResult(GKCallbackResult); }
public Watcher(GkDatabase gkDatabase) { GkDatabase = gkDatabase; GKCallbackResult = new GKCallbackResult(); }
bool InitializeMonitoring() { bool IsPingFailure = false; bool IsInTechnologicalRegime = false; bool IsGetStatesFailure = false; IsHashFailure = false; foreach (var descriptor in GkDatabase.Descriptors) { descriptor.XBase.BaseState.Clear(); } while (true) { LastUpdateTime = DateTime.Now; GKCallbackResult = new GKCallbackResult(); foreach (var descriptor in GkDatabase.Descriptors) { descriptor.XBase.BaseState.IsInitialState = true; } var deviceInfo = DeviceBytesHelper.GetDeviceInfo(GkDatabase.RootDevice); var result = string.IsNullOrEmpty(deviceInfo); if (IsPingFailure != result) { GKCallbackResult = new GKCallbackResult(); IsPingFailure = result; if (IsPingFailure) AddFailureJournalItem(EventName.Нет_связи_с_ГК, EventDescription.Старт_мониторинга); else AddFailureJournalItem(EventName.Связь_с_ГК_восстановлена, EventDescription.Старт_мониторинга); foreach (var descriptor in GkDatabase.Descriptors) { descriptor.XBase.BaseState.IsConnectionLost = IsPingFailure; descriptor.XBase.BaseState.IsInitialState = !IsPingFailure; } NotifyAllObjectsStateChanged(); OnGKCallbackResult(GKCallbackResult); } if (IsPingFailure) { if (ReturnArterWait(5000)) return false; continue; } result = CheckTechnologicalRegime(); if (IsInTechnologicalRegime != result) { GKCallbackResult = new GKCallbackResult(); IsInTechnologicalRegime = result; if (IsInTechnologicalRegime) AddFailureJournalItem(EventName.ГК_в_технологическом_режиме, "Старт мониторинга"); else AddFailureJournalItem(EventName.ГК_в_рабочем_режиме, "Старт мониторинга"); NotifyAllObjectsStateChanged(); OnGKCallbackResult(GKCallbackResult); } if (IsInTechnologicalRegime) { if (ReturnArterWait(5000)) return false; continue; } var hashBytes = GKFileInfo.CreateHash1(XManager.DeviceConfiguration, GkDatabase.RootDevice); var gkFileReaderWriter = new GKFileReaderWriter(); var gkFileInfo = gkFileReaderWriter.ReadInfoBlock(GkDatabase.RootDevice); result = gkFileInfo == null || !GKFileInfo.CompareHashes(hashBytes, gkFileInfo.Hash1); if (IsHashFailure != result) { GKCallbackResult = new GKCallbackResult(); IsHashFailure = result; if (IsHashFailure) AddFailureJournalItem(EventName.Конфигурация_прибора_не_соответствует_конфигурации_ПК, EventDescription.Не_совпадает_хэш); else AddFailureJournalItem(EventName.Конфигурация_прибора_соответствует_конфигурации_ПК, EventDescription.Совпадает_хэш); foreach (var descriptor in GkDatabase.Descriptors) { descriptor.XBase.BaseState.IsDBMissmatch = IsHashFailure; descriptor.XBase.BaseState.IsInitialState = false; } NotifyAllObjectsStateChanged(); OnGKCallbackResult(GKCallbackResult); } if (IsHashFailure) { if (ReturnArterWait(5000)) return false; continue; } GKCallbackResult = new GKCallbackResult(); if (!ReadMissingJournalItems()) AddFailureJournalItem(EventName.Ошибка_при_синхронизации_журнала); OnGKCallbackResult(GKCallbackResult); GKCallbackResult = new GKCallbackResult(); GetAllStates(); result = IsDBMissmatchDuringMonitoring || !IsConnected; if (IsGetStatesFailure != result) { IsGetStatesFailure = result; if (IsGetStatesFailure) AddFailureJournalItem(EventName.Ошибка_при_опросе_состояний_компонентов_ГК, DBMissmatchDuringMonitoringReason); else AddFailureJournalItem(EventName.Устранена_ошибка_при_опросе_состояний_компонентов_ГК); } OnGKCallbackResult(GKCallbackResult); if (IsGetStatesFailure) { if (ReturnArterWait(5000)) return false; continue; } GKCallbackResult = new GKCallbackResult(); foreach (var descriptor in GkDatabase.Descriptors) { descriptor.XBase.BaseState.IsInitialState = false; } NotifyAllObjectsStateChanged(); OnGKCallbackResult(GKCallbackResult); return true; } }
void OnRunThread() { while (true) { try { if (IsStopping) return; if (!InitializeMonitoring()) return; if (IsStopping) return; } catch (Exception e) { AddMessage(EventName.Ошибка_инициализации_мониторинга, ""); Logger.Error(e, "JournalWatcher.InitializeMonitoring"); } while (true) { if (IsStopping) return; lock (CallbackResultLocker) { GKCallbackResult = new GKCallbackResult(); } RunMonitoring(); lock (CallbackResultLocker) { OnGKCallbackResult(GKCallbackResult); } 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 (ReturnArterWait(pollInterval)) break; } WaitIfSuspending(); LastUpdateTime = DateTime.Now; } } }