Ejemplo n.º 1
0
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_connection != null)
                        {
                            m_connection.Disconnected -= m_connection_Disconnected;
                            m_connection.Dispose();
                            m_connection = null;
                        }

                        m_dataPipe?.Dispose();

                        if ((object)m_eventTimer != null)
                        {
                            m_eventTimer.Elapsed -= m_eventTimer_Elapsed;
                            m_eventTimer.Dispose();
                        }
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Disconnects from the configured PI server if a connection is open
 /// </summary>
 protected override void AttemptDisconnection()
 {
     if ((object)m_connection != null)
     {
         m_connection.Dispose();
         m_connection = null;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns <see cref="PIConnection"/> to the pool.
        /// </summary>
        /// <param name="connection"><see cref="PIConnection"/> to return to the pool.</param>
        /// <exception cref="InvalidOperationException">Provided PIConnection does not belong to this connection pool.</exception>
        public void ReturnPooledConnection(PIConnection connection)
        {
            if ((object)connection == null)
            {
                return;
            }

            lock (m_connectionPool)
            {
                if (!m_connectionPool.Contains(connection))
                {
                    throw new InvalidOperationException("Provided PIConnection does not belong to this connection pool");
                }

                if (connection.AccessCount > 0)
                {
                    connection.AccessCount--;
                }

                if (connection.AccessCount < 1)
                {
                    if (m_connectionPool.Count > m_minimumPoolSize && m_connectionPool.Remove(connection))
                    {
                        connection.Disconnected -= connection_Disconnected;
                        connection.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="PIOutputAdapter"/> 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 ((object)m_mapRequestQueue != null)
                        {
                            m_mapRequestQueue.Dispose();
                        }

                        if ((object)m_archiveQueue != null)
                        {
                            m_archiveQueue.Dispose();
                        }

                        if ((object)m_connection != null)
                        {
                            m_connection.Disconnected -= m_connection_Disconnected;
                            m_connection.Dispose();
                            m_connection = null;
                        }

                        if ((object)m_mappedPIPoints != null)
                        {
                            m_mappedPIPoints.Clear();
                        }
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }