示例#1
0
        public Enrich(string interchangeId, string tag)
        {
            SqlServerConnection connection = null;

            try
            {
                connection = new SqlServerConnection("MessageArchive");
                connection.RefreshConfiguration();
                connection.Open();
                SplitArchiveTag(tag);
                LoadParts(connection, interchangeId, tag);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                    connection = null;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Archive the message and its parts and optionally archives the message and part properties.
 /// </summary>
 /// <param name="expiryMinutes">The amount of time (in minutes) before the archived message expires and will be automatically deleted from the archive.</param>
 /// <param name="includeProperties">A flag indicating if properties should be archived along with the message.</param>
 /// <param name="tag">An ArchiveTag to be associated with the archived message.</param>
 public Task Archive(int expiryMinutes, bool includeProperties, ArchiveTag tag)
 {
     return(Task.Factory.StartNew(() =>
     {
         try
         {
             if (tag.ArchiveType.Active)
             {
                 using (SqlServerConnection connection = new SqlServerConnection("MessageArchive"))
                 {
                     connection.RefreshConfiguration();
                     connection.Open();
                     connection.BeginTransaction();
                     try
                     {
                         ArchiveMessage(expiryMinutes, connection);
                         if (includeProperties)
                         {
                             ArchiveMessageProperties(connection);
                         }
                         ArchiveParts(connection);
                         if (includeProperties)
                         {
                             ArchivePartProperties(connection);
                         }
                         connection.Commit();
                     }
                     catch (Exception ex)
                     {
                         if (connection.IsOpen())
                         {
                             connection.Rollback();
                         }
                         throw ex;
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Logger.WriteError(string.Format("Error archiving a message to database. The message will be writen to archive directory for later archival.  \r\n Details: {0}", ex.ToString()), 128);
             HandleFailedArchiveMessage();
         }
     }));
 }
示例#3
0
        private static Dictionary <string, Endpoint> LoadEndpointDictionary()
        {
            SqlServerConnection           connection = null;
            Dictionary <string, Endpoint> endpoints  = new Dictionary <string, Endpoint>(StringComparer.InvariantCultureIgnoreCase);

            try
            {
                // Connect to the database to load settings.
                string     sql        = null;
                SqlCommand sqlCommand = null;
                connection = new SqlServerConnection("MessageArchive");
                connection.RefreshConfiguration();
                connection.Open();

                // Load the dictionary of Endpoint records.
                sql = "SELECT [Id], [Name] " +
                      "FROM [MessageArchive].[dbo].[Endpoint]";
                sqlCommand = new SqlCommand(sql);
                using (SqlDataReader reader = connection.ExecuteReader(sqlCommand))
                {
                    while (reader.Read())
                    {
                        IDataRecord record   = (IDataRecord)reader;
                        Endpoint    endpoint = new Endpoint(record);
                        endpoints.Add(endpoint.Name, endpoint);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteWarning("Error while loading Tag data." + ex);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                    connection = null;
                }
            }

            return(endpoints);
        }
示例#4
0
        private static Dictionary <string, ArchiveType> LoadArchiveTypeDictionary()
        {
            SqlServerConnection connection = null;
            Dictionary <string, ArchiveType> archiveTypes = new Dictionary <string, ArchiveType>(StringComparer.InvariantCultureIgnoreCase);

            try
            {
                // Connect to the database to load settings.
                string     sql        = null;
                SqlCommand sqlCommand = null;
                connection = new SqlServerConnection("MessageArchive");
                connection.RefreshConfiguration();
                connection.Open();
                // Load the dictionary of ArchiveType records.
                sql = "SELECT [Id], [Name], [Active], [DefaultExpiry] " +
                      "FROM [MessageArchive].[dbo].[ArchiveType]";
                sqlCommand = new SqlCommand(sql);
                using (SqlDataReader reader = connection.ExecuteReader(sqlCommand))
                {
                    while (reader.Read())
                    {
                        IDataRecord record      = (IDataRecord)reader;
                        ArchiveType archiveType = new ArchiveType(record);
                        archiveTypes.Add(archiveType.Name, archiveType);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteWarning("Error while loading Tag data." + ex);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                    connection = null;
                }
            }
            return(archiveTypes);
        }