Пример #1
0
        /// <summary>
        /// Initializes the <see cref="AlarmAdapter"/>.
        /// </summary>
        public override void Initialize()
        {
            Dictionary <string, string> settings;
            string setting;
            double logProcessingDelay;

            // Run base class initialization
            base.Initialize();
            settings = Settings;

            // Load optional parameters
            if (settings.TryGetValue("supportsTemporalProcessing", out setting))
            {
                m_supportsTemporalProcessing = setting.ParseBoolean();
            }
            else
            {
                m_supportsTemporalProcessing = false;
            }

            if (settings.TryGetValue("useAlarmLog", out setting))
            {
                m_useAlarmLog = setting.ParseBoolean();
            }
            else
            {
                m_useAlarmLog = false;
            }

            if (!settings.TryGetValue("bulkInsertLimit", out setting) || !int.TryParse(setting, out m_bulkInsertLimit))
            {
                m_bulkInsertLimit = 300;
            }

            if (settings.TryGetValue("logProcessingDelay", out setting) && double.TryParse(setting, out logProcessingDelay))
            {
                m_logProcessingDelay = (int)(logProcessingDelay * 1000.0D);
            }
            else
            {
                m_logProcessingDelay = 1000;
            }

            try
            {
                // Set up alarm service
                m_alarmService = new AlarmService(this);
                m_alarmService.SettingsCategory         = base.Name.Replace("!", "").ToLower() + m_alarmService.SettingsCategory;
                m_alarmService.ServiceProcessException += AlarmService_ServiceProcessException;
                m_alarmService.PersistSettings          = true;
                m_alarmService.Initialize();
            }
            catch (Exception ex)
            {
                OnProcessException(MessageLevel.Error, new InvalidOperationException($"Unable to initialize alarm service due to exception: {ex.Message}", ex));
            }

            // Run the process measurements operation to ensure that the alarm configuration is up to date
            if (Interlocked.CompareExchange(ref m_dataSourceState, Modified, Modified) == Modified)
            {
                m_processMeasurementsOperation.AsynchronousExecutionMode = AsynchronousExecutionMode.Long;
                m_processMeasurementsOperation.RunOnceAsync();
            }
        }