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); }
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); }
private void LoadParts(SqlServerConnection connection, string interchangeId, string tag) { string sql = string.Empty; Guid _interchangeId = new Guid(interchangeId); try { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("select ContentType,CharSet,TextData,ImageData,Msg.MessageId As MessageId FROM [MessageArchive].[dbo].[Part] Part inner join [MessageArchive].[dbo].[Message] Msg on part.MessageId=msg.MessageId"); sqlBuilder.Append(archiveType != String.Empty ? " inner join [MessageArchive].[dbo].[ArchiveType] At on msg.ArchiveTypeId=At.Id " : ""); sqlBuilder.Append(sourceSystem != String.Empty ? " inner join [MessageArchive].[dbo].[Endpoint] SE on msg.SourceSystemId=SE.Id " : ""); sqlBuilder.Append(targetSystem != String.Empty ? " inner join [MessageArchive].[dbo].[Endpoint] TE on msg.TargetSystemId=TE.Id " : ""); sqlBuilder.Append(" where Msg.InterchangeId=@MessageId and Msg.Tag=@ArchiveTag "); sqlBuilder.Append(archiveType != String.Empty ? " and At.Name=@ArchiveType " : ""); sqlBuilder.Append(sourceSystem != String.Empty ? " and SE.Name=@SourceSystem " : ""); sqlBuilder.Append(targetSystem != String.Empty ? " and TE.Name=@TargetSystem " : ""); sqlBuilder.Append(" and Msg.Description=@Description "); sql = sqlBuilder.ToString(); SqlCommand sqlCommand = new SqlCommand(sql); SqlParameter parmMessageId = sqlCommand.Parameters.Add("@MessageId", SqlDbType.UniqueIdentifier); SqlParameter parmArchiveTag = sqlCommand.Parameters.Add("@ArchiveTag", SqlDbType.NVarChar); SqlParameter parmArchiveType = sqlCommand.Parameters.Add("@ArchiveType", SqlDbType.NVarChar); SqlParameter parmSourceSystem = sqlCommand.Parameters.Add("@SourceSystem", SqlDbType.NVarChar); SqlParameter parmTargetSystem = sqlCommand.Parameters.Add("@TargetSystem", SqlDbType.NVarChar); SqlParameter parmDescription = sqlCommand.Parameters.Add("@Description", SqlDbType.NVarChar); parmMessageId.Value = _interchangeId; parmArchiveTag.Value = archiveTag; parmArchiveType.Value = archiveType; parmSourceSystem.Value = sourceSystem; parmTargetSystem.Value = targetSystem; parmDescription.Value = description; using (SqlDataReader reader = connection.ExecuteReader(sqlCommand)) { while (reader.Read()) { IDataRecord partRecord = (IDataRecord)reader; contentType = (string)partRecord["ContentType"]; charSet = (string)partRecord["CharSet"]; messageId = (Guid)partRecord["MessageId"]; if (contentType == "text/xml") { string xml = (string)partRecord["TextData"]; TextReader textReader = new StringReader(xml); contentAsXmlDocument = new XmlDocument(); contentAsXmlDocument.Load(textReader); } else if (contentType == "text/plain") { contentAsText = (string)partRecord["TextData"]; } else if (contentType == "application/octet-stream" || contentType == "binary") { contentAsByteArray = (byte[])partRecord["ImageData"]; } } } } catch (Exception exception) { Logger.WriteTrace(string.Format("Load of MessageProperties records from message archive failed." + sql + "\r\n", exception.ToString())); throw exception; } }