public void Cleanup()
        {
            if (connection != null)
            {
                // Work around, close the connection manually.
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }

                connection.Dispose();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Component"></see> 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 (disposed)
     {
         return;
     }
     if (disposing)
     {
         ReliableConnection.Dispose();
     }
     disposed = true;
     base.Dispose(disposing);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves data from the specified queue item stored in the persistence queue.
        /// </summary>
        /// <param name="queueItemId">The unique identity of the item.</param>
        /// <param name="headerXPath">The optional set of XPath expressions defining a header portion of the queue data.</param>
        /// <param name="bodyXPath">The optional set of XPath expressions defining a body portion of the queue data.</param>
        /// <param name="footerXPath">The optional set of XPath expressions defining a footer portion of the queue data.</param>
        /// <param name="nsManager">The optional XML namespace manager that will be used for XML namespace resolution.</param>
        /// <returns>An instance of the XML reader that provides non-cached, forward-only access to queue item data.</returns>
        public XmlReader DequeueXmlData(Guid queueItemId, IEnumerable <string> headerXPath, IEnumerable <string> bodyXPath, IEnumerable <string> footerXPath, XmlNamespaceManager nsManager)
        {
            var callToken      = TraceManager.DataAccessComponent.TraceIn(queueItemId.ToString());
            var scopeStartMain = TraceManager.DataAccessComponent.TraceStartScope(Resources.ScopeSqlAzurePersistenceQueueDequeueXmlDataMain, callToken);

            ReliableSqlConnection dbConnection = null;
            bool leaveConnectionOpen           = false;

            try
            {
                // SQL connection is intentionally left non-disposed here. It will be disposed along with XmlReader which this method returns (if at all).
                // This behavior is enforced through specifying CommandBehavior.CloseConnection when invoking the ExecuteCommand method.
                dbConnection = new ReliableSqlConnection(this.dbConnectionString, this.connectionRetryPolicy, this.commandRetryPolicy);

                using (IDbCommand dequeueCommand = CustomSqlCommandFactory.SqlAzurePersistenceQueue.CreateDequeueXmlDataCommand(dbConnection, queueItemId, headerXPath != null ? headerXPath.ToArray <string>() : null, bodyXPath != null ? bodyXPath.ToArray <string>() : null, footerXPath != null ? footerXPath.ToArray <string>() : null, nsManager))
                {
                    TraceManager.DataAccessComponent.TraceCommand(dequeueCommand);

                    XmlReader xmlDataReader = dbConnection.ExecuteCommand <XmlReader>(dequeueCommand, CommandBehavior.CloseConnection);

                    if (xmlDataReader != null && xmlDataReader.Read())
                    {
                        XmlReaderSettings readerSettings = new XmlReaderSettings()
                        {
                            CheckCharacters = false, IgnoreComments = true, IgnoreProcessingInstructions = true, IgnoreWhitespace = true, ValidationType = ValidationType.None, ConformanceLevel = ConformanceLevel.Auto
                        };
                        XmlReader nonValidatingReader = XmlReader.Create(xmlDataReader, readerSettings);

                        leaveConnectionOpen = true;
                        return(nonValidatingReader);
                    }
                }
            }
            catch (Exception ex)
            {
                TraceManager.DataAccessComponent.TraceError(ex, callToken);
            }
            finally
            {
                if (dbConnection != null && !leaveConnectionOpen)
                {
                    dbConnection.Dispose();
                }

                TraceManager.DataAccessComponent.TraceEndScope(Resources.ScopeSqlAzurePersistenceQueueDequeueXmlDataMain, scopeStartMain, callToken);
                TraceManager.DataAccessComponent.TraceOut(callToken);
            }

            return(null);
        }
Exemplo n.º 4
0
        public void Cleanup()
        {
            RetryPolicyFactory.SetRetryManager(null, false);

            if (connection != null)
            {
                // Work around, close the connection manually.
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }

                connection.Dispose();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Performs a query against the XML data stored in the queue item.
        /// </summary>
        /// <param name="queueItemId">The unique identity of the queue item.</param>
        /// <param name="xPathCollection">One or more XPath expressions which will be invoked against the queue item's XML data.</param>
        /// <param name="nsManager">The XML namespace manager that will be used for XML namespace resolution.</param>
        /// <returns>An instance of the XML reader that provides non-cached, forward-only access to queue item data.</returns>
        public XmlReader QueryXmlData(Guid queueItemId, IEnumerable <string> xPathCollection, XmlNamespaceManager nsManager)
        {
            var callToken      = TraceManager.DataAccessComponent.TraceIn(queueItemId.ToString());
            var scopeStartMain = TraceManager.DataAccessComponent.TraceStartScope(Resources.ScopeSqlAzurePersistenceQueueQueryXmlDataMain, callToken);

            ReliableSqlConnection dbConnection = null;
            bool leaveConnectionOpen           = false;

            try
            {
                // SQL connection is intentionally left non-disposed here. It will be disposed along with XmlReader which this method returns (if at all).
                // This behavior is enforced through specifying CommandBehavior.CloseConnection when invoking the ExecuteCommand method.
                dbConnection = new ReliableSqlConnection(this.dbConnectionString, this.connectionRetryPolicy, this.commandRetryPolicy);

                using (IDbCommand queryCommand = CustomSqlCommandFactory.SqlAzurePersistenceQueue.CreateQueryXmlDataCommand(dbConnection, queueItemId, xPathCollection != null ? xPathCollection.ToArray <string>() : null, nsManager))
                {
                    TraceManager.DataAccessComponent.TraceCommand(queryCommand);

                    XmlReader xmlDataReader = dbConnection.ExecuteCommand <XmlReader>(queryCommand, CommandBehavior.CloseConnection);

                    if (xmlDataReader != null && xmlDataReader.Read())
                    {
                        leaveConnectionOpen = true;
                        return(xmlDataReader);
                    }
                }
            }
            catch (Exception ex)
            {
                TraceManager.DataAccessComponent.TraceError(ex, callToken);
            }
            finally
            {
                if (dbConnection != null && !leaveConnectionOpen)
                {
                    dbConnection.Dispose();
                }

                TraceManager.DataAccessComponent.TraceEndScope(Resources.ScopeSqlAzurePersistenceQueueQueryXmlDataMain, scopeStartMain, callToken);
                TraceManager.DataAccessComponent.TraceOut(callToken);
            }

            return(null);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Disposes the underling <see cref="ReliableSqlConnection"/> as well as the current class.
 /// </summary>
 public new void Dispose()
 {
     ReliableConnection.Dispose();
     base.Dispose();
 }
Exemplo n.º 7
0
 public void Dispose()
 {
     _sqlConnection.Dispose();
 }