Ejemplo n.º 1
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="DNP3InputAdapter"/> 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 override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if (m_active)
                        {
                            m_active = false;

                            if ((object)m_channel != null)
                            {
                                // Shutdown the communications channel
                                m_channel.Shutdown();
                                m_channel = null;
                            }
                        }

                        // Detach from the time-series sequence of events new measurements event
                        if ((object)m_soeHandler != null)
                        {
                            m_soeHandler.NewMeasurements -= OnNewMeasurements;
                            m_soeHandler = null;
                        }

                        lock (s_adapters)
                        {
                            // Remove this adapter from the available list
                            s_adapters.Remove(this);

                            // See if we are disposing the status proxy instance
                            if (ReferenceEquals(s_statusProxy, this))
                            {
                                // Attempt to find a new status proxy
                                if (s_adapters.Count > 0)
                                {
                                    s_statusProxy = s_adapters[0];
                                }
                                else
                                {
                                    s_statusProxy = null;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes <see cref="DNP3InputAdapter"/>
        /// </summary>
        public override void Initialize()
        {
            Dictionary <string, string> settings = Settings;
            string setting;
            double pollingInterval;
            double timestampDifferentiation;

            base.Initialize();

            if (!settings.TryGetValue("CommsFilePath", out m_commsFilePath) || string.IsNullOrWhiteSpace(m_commsFilePath))
            {
                throw new ArgumentException("The required commsFile parameter was not specified");
            }

            if (!settings.TryGetValue("MappingFilePath", out m_mappingFilePath) || string.IsNullOrWhiteSpace(m_mappingFilePath))
            {
                throw new ArgumentException("The required mappingFile parameter was not specified");
            }

            if (settings.TryGetValue("PollingInterval", out setting) && double.TryParse(setting, out pollingInterval))
            {
                PollingInterval = pollingInterval;
            }

            m_masterConfig   = ReadConfig <MasterConfiguration>(m_commsFilePath);
            m_measurementMap = ReadConfig <MeasurementMap>(m_mappingFilePath);

            m_soeHandler = new TimeSeriesSOEHandler(new MeasurementLookup(m_measurementMap));
            m_soeHandler.NewMeasurements += OnNewMeasurements;

            // The TimestampDifferentiation property is a passthrough to the m_soeHandler.TimestampDifferentiation,
            // so m_soeHandler must be initialized before reading this property from the connection string
            if (settings.TryGetValue("TimestampDifferentiation", out setting) && double.TryParse(setting, out timestampDifferentiation))
            {
                TimestampDifferentiation = timestampDifferentiation;
            }

            lock (s_adapters)
            {
                // Add adapter to list of available adapters
                s_adapters.Add(this);

                // If no adapter has been designated as the status proxy, might as well be this one
                if ((object)s_statusProxy == null)
                {
                    s_statusProxy = this;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes <see cref="DNP3InputAdapter"/>
        /// </summary>
        public override void Initialize()
        {
            Dictionary <string, string> settings = Settings;

            base.Initialize();

            settings.TryGetValue("CommsFilePath", out m_commsFilePath);

            if (string.IsNullOrWhiteSpace(m_commsFilePath))
            {
                throw new ArgumentException("The required commsFile parameter was not specified");
            }

            settings.TryGetValue("MappingFilePath", out m_mappingFilePath);

            if (string.IsNullOrWhiteSpace(m_mappingFilePath))
            {
                throw new ArgumentException("The required mappingFile parameter was not specified");
            }

            m_masterConfig   = ReadConfig <MasterConfiguration>(m_commsFilePath);
            m_measurementMap = ReadConfig <MeasurementMap>(m_mappingFilePath);

            m_soeHandler = new TimeSeriesSOEHandler(new MeasurementLookup(m_measurementMap));
            m_soeHandler.NewMeasurements += OnNewMeasurements;

            lock (s_adapters)
            {
                // Add adapter to list of available adapters
                s_adapters.Add(this);

                // If no adapter has been designated as the status proxy, might as well be this one
                if ((object)s_statusProxy == null)
                {
                    s_statusProxy = this;
                }
            }
        }