Exemple #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="AlarmMonitor"/> class.
        /// </summary>
        /// <param name="singleton">Indicates whether this instance should update the global reference to become the singleton.</param>
        public AlarmMonitor(bool singleton = false)
        {
            object refreshInterval = IsolatedStorageManager.ReadFromIsolatedStorage("AlarmStatusRefreshInterval") ?? DefaultRefreshInterval;

            if (!int.TryParse(refreshInterval.ToString(), out m_refreshInterval))
            {
                m_refreshInterval = DefaultRefreshInterval;
            }

            m_currentAlarmsLock = new object();
            m_currentAlarms     = new HashSet <Alarm>();

            m_refreshTimer          = new Timer(m_refreshInterval * 1000);
            m_refreshTimer.Elapsed += RefreshTimer_Elapsed;

            m_alarmStatusQuery = new AlarmStatusQuery();
            m_alarmStatusQuery.RaisedAlarmStates += m_alarmStatusQuery_RaisedAlarmStates;
            m_alarmStatusQuery.ProcessException  += m_alarmStatusQuery_ProcessException;

            // Load all alarms defined in the database
            UpdateDefinedAlarms();

            // Setup subscription to subscribe to all alarm measurements
            m_subscriptionInfo = new UnsynchronizedSubscriptionInfo(false)
            {
                FilterExpression = "FILTER ActiveMeasurements WHERE SignalType='ALRM'"
            };

            m_dataSubscriber = new DataSubscriber();
            m_dataSubscriber.ConnectionEstablished  += m_dataSubscriber_ConnectionEstablished;
            m_dataSubscriber.ReceivedServerResponse += m_dataSubscriber_ReceivedServerResponse;
            m_dataSubscriber.NewMeasurements        += m_dataSubscriber_NewMeasurements;
            m_dataSubscriber.ProcessException       += m_dataSubscriber_ProcessException;
            m_dataSubscriber.ConnectionString        = GetDataPublisherConnectionString();
            m_dataSubscriber.OperationalModes       |= OperationalModes.UseCommonSerializationFormat | OperationalModes.CompressSignalIndexCache | OperationalModes.CompressPayloadData;
            m_dataSubscriber.DataLossInterval        = -1;
            m_dataSubscriber.Initialize();

            if (singleton)
            {
                Default = this;
            }
        }
Exemple #2
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="AlarmMonitor"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_refreshTimer != null)
                        {
                            m_refreshTimer.Dispose();
                            m_refreshTimer = null;
                        }

                        if ((object)m_alarmStatusQuery != null)
                        {
                            m_alarmStatusQuery.RaisedAlarmStates -= m_alarmStatusQuery_RaisedAlarmStates;
                            m_alarmStatusQuery.ProcessException  -= m_alarmStatusQuery_ProcessException;
                            m_alarmStatusQuery.Dispose();
                            m_alarmStatusQuery = null;
                        }

                        if ((object)m_dataSubscriber != null)
                        {
                            m_dataSubscriber.ConnectionEstablished  -= m_dataSubscriber_ConnectionEstablished;
                            m_dataSubscriber.ReceivedServerResponse -= m_dataSubscriber_ReceivedServerResponse;
                            m_dataSubscriber.NewMeasurements        -= m_dataSubscriber_NewMeasurements;
                            m_dataSubscriber.ProcessException       -= m_dataSubscriber_ProcessException;
                            m_dataSubscriber.Dispose();
                            m_dataSubscriber = null;
                        }
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a new instance of the <see cref="AlarmMonitor"/> class.
        /// </summary>
        /// <param name="singleton">Indicates whether this instance should update the global reference to become the singleton.</param>
        public AlarmMonitor(bool singleton = false)
        {
            object refreshInterval = IsolatedStorageManager.ReadFromIsolatedStorage("AlarmStatusRefreshInterval") ?? DefaultRefreshInterval;

            if (!int.TryParse(refreshInterval.ToString(), out m_refreshInterval))
                m_refreshInterval = DefaultRefreshInterval;

            m_currentAlarmsLock = new object();
            m_currentAlarms = new HashSet<Alarm>();

            m_refreshTimer = new Timer(m_refreshInterval * 1000);
            m_refreshTimer.Elapsed += RefreshTimer_Elapsed;

            m_alarmStatusQuery = new AlarmStatusQuery();
            m_alarmStatusQuery.RaisedAlarmStates += m_alarmStatusQuery_RaisedAlarmStates;
            m_alarmStatusQuery.ProcessException += m_alarmStatusQuery_ProcessException;

            // Load all alarms defined in the database
            UpdateDefinedAlarms();

            // Setup subscription to subscribe to all alarm measurements
            m_subscriptionInfo = new UnsynchronizedSubscriptionInfo(false)
            {
                FilterExpression = "FILTER ActiveMeasurements WHERE SignalType='ALRM'"
            };

            m_dataSubscriber = new DataSubscriber();
            m_dataSubscriber.ConnectionEstablished += m_dataSubscriber_ConnectionEstablished;
            m_dataSubscriber.ReceivedServerResponse += m_dataSubscriber_ReceivedServerResponse;
            m_dataSubscriber.NewMeasurements += m_dataSubscriber_NewMeasurements;
            m_dataSubscriber.ProcessException += m_dataSubscriber_ProcessException;
            m_dataSubscriber.ConnectionString = GetDataPublisherConnectionString();
            m_dataSubscriber.OperationalModes |= OperationalModes.UseCommonSerializationFormat | OperationalModes.CompressSignalIndexCache | OperationalModes.CompressPayloadData;
            m_dataSubscriber.DataLossInterval = -1;
            m_dataSubscriber.Initialize();

            if (singleton)
                Default = this;
        }
Exemple #4
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="AlarmMonitor"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_refreshTimer != null)
                        {
                            m_refreshTimer.Dispose();
                            m_refreshTimer = null;
                        }

                        if ((object)m_alarmStatusQuery != null)
                        {
                            m_alarmStatusQuery.RaisedAlarmStates -= m_alarmStatusQuery_RaisedAlarmStates;
                            m_alarmStatusQuery.ProcessException -= m_alarmStatusQuery_ProcessException;
                            m_alarmStatusQuery.Dispose();
                            m_alarmStatusQuery = null;
                        }

                        if ((object)m_dataSubscriber != null)
                        {
                            m_dataSubscriber.ConnectionEstablished -= m_dataSubscriber_ConnectionEstablished;
                            m_dataSubscriber.ReceivedServerResponse -= m_dataSubscriber_ReceivedServerResponse;
                            m_dataSubscriber.NewMeasurements -= m_dataSubscriber_NewMeasurements;
                            m_dataSubscriber.ProcessException -= m_dataSubscriber_ProcessException;
                            m_dataSubscriber.Dispose();
                            m_dataSubscriber = null;
                        }
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                }
            }
        }