Esempio n. 1
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="IaonSession"/> 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)
                    {
                        DataSet dataSource = DataSource;

                        // Dispose filter adapters collection
                        if ((object)m_filterAdapters != null)
                        {
                            m_filterAdapters.Stop();
                            m_filterAdapters.Dispose();
                        }
                        m_filterAdapters = null;

                        // Dispose input adapters collection
                        if ((object)m_inputAdapters != null)
                        {
                            m_inputAdapters.Stop();
                            m_inputAdapters.NewMeasurements    -= NewMeasurementsHandler;
                            m_inputAdapters.ProcessingComplete -= ProcessingCompleteHandler;
                            m_inputAdapters.Dispose();
                        }
                        m_inputAdapters = null;

                        // Dispose action adapters collection
                        if ((object)m_actionAdapters != null)
                        {
                            m_actionAdapters.Stop();
                            m_actionAdapters.NewMeasurements        -= NewMeasurementsHandler;
                            m_actionAdapters.UnpublishedSamples     -= UnpublishedSamplesHandler;
                            m_actionAdapters.RequestTemporalSupport -= RequestTemporalSupportHandler;
                            m_actionAdapters.Dispose();
                        }
                        m_actionAdapters = null;

                        // Dispose output adapters collection
                        if ((object)m_outputAdapters != null)
                        {
                            m_outputAdapters.Stop();
                            m_outputAdapters.UnprocessedMeasurements -= UnprocessedMeasurementsHandler;
                            m_outputAdapters.Dispose();
                        }
                        m_outputAdapters = null;

                        // Dispose all adapters collection
                        if (m_allAdapters != null)
                        {
                            m_allAdapters.StatusMessage               -= StatusMessageHandler;
                            m_allAdapters.ProcessException            -= ProcessExceptionHandler;
                            m_allAdapters.InputMeasurementKeysUpdated -= InputMeasurementKeysUpdatedHandler;
                            m_allAdapters.OutputMeasurementsUpdated   -= OutputMeasurementsUpdatedHandler;
                            m_allAdapters.ConfigurationChanged        -= ConfigurationChangedHandler;
                            m_allAdapters.Disposed -= DisposedHandler;
                            m_allAdapters.Dispose();
                        }
                        m_allAdapters = null;

                        // Dispose of routing tables
                        if (m_routingTables != null)
                        {
                            m_routingTables.StatusMessage    -= m_routingTables_StatusMessage;
                            m_routingTables.ProcessException -= m_routingTables_ProcessException;
                            m_routingTables.Dispose();
                        }
                        m_routingTables = null;

                        if ((object)dataSource != null)
                        {
                            dataSource.Dispose();
                        }
                    }
                }
                finally
                {
                    m_disposed = true; // Prevent duplicate dispose.

                    if (Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="IaonSession"/> 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)
                    {
                        DataSet dataSource = this.DataSource;

                        // Dispose input adapters collection
                        if (m_inputAdapters != null)
                        {
                            m_inputAdapters.Stop();

                            if (m_useMeasurementRouting)
                            {
                                m_inputAdapters.NewMeasurements -= m_routingTables.RoutedMeasurementsHandler;
                            }
                            else
                            {
                                m_inputAdapters.NewMeasurements -= m_routingTables.BroadcastMeasurementsHandler;
                            }

                            m_inputAdapters.ProcessingComplete -= ProcessingCompleteHandler;
                            m_inputAdapters.Dispose();
                        }
                        m_inputAdapters = null;

                        // Dispose action adapters collection
                        if (m_actionAdapters != null)
                        {
                            m_actionAdapters.Stop();

                            if (m_useMeasurementRouting)
                            {
                                m_actionAdapters.NewMeasurements -= m_routingTables.RoutedMeasurementsHandler;
                            }
                            else
                            {
                                m_actionAdapters.NewMeasurements -= m_routingTables.BroadcastMeasurementsHandler;
                            }

                            m_actionAdapters.UnpublishedSamples -= UnpublishedSamplesHandler;
                            m_actionAdapters.Dispose();
                        }
                        m_actionAdapters = null;

                        // Dispose output adapters collection
                        if (m_outputAdapters != null)
                        {
                            m_outputAdapters.Stop();
                            m_outputAdapters.UnprocessedMeasurements -= UnprocessedMeasurementsHandler;
                            m_outputAdapters.Dispose();
                        }
                        m_outputAdapters = null;

                        // Dispose all adapters collection
                        if (m_allAdapters != null)
                        {
                            m_allAdapters.StatusMessage               -= StatusMessageHandler;
                            m_allAdapters.ProcessException            -= ProcessExceptionHandler;
                            m_allAdapters.InputMeasurementKeysUpdated -= InputMeasurementKeysUpdatedHandler;
                            m_allAdapters.OutputMeasurementsUpdated   -= OutputMeasurementsUpdatedHandler;
                            m_allAdapters.Disposed -= DisposedHandler;
                            m_allAdapters.Dispose();
                        }
                        m_allAdapters = null;

                        // Dispose of routing tables
                        if (m_routingTables != null)
                        {
                            m_routingTables.ProcessException -= m_routingTables_ProcessException;
                            m_routingTables.Dispose();
                        }
                        m_routingTables = null;

                        // Dispose of wait handle dictionary
                        if (m_waitHandles != null)
                        {
                            foreach (AutoResetEvent waitHandle in m_waitHandles.Values)
                            {
                                if (waitHandle != null)
                                {
                                    waitHandle.Close();
                                }
                            }

                            m_waitHandles.Clear();
                        }
                        m_waitHandles = null;

                        if ((object)dataSource != null)
                        {
                            dataSource.Dispose();
                        }
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.

                    if (Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
            }
        }