/// <summary> /// Writes the message into the Auditing database if required and updates the correlation Guid for that message if /// it doesn't already exist /// </summary> /// <param name="message">Message to audit</param> /// <returns>A string result of the auditing</returns> public string ProcessWorker(T2.SendingMessage.Library.Message message) { try { if (clients == null) { throw new Exception("Please call the initialise call before calling the worker"); } // Get the client Client client = clients.GetByName(message.AdditionalInformation.UserId.ToString()); if (client == null) { throw new Exception(string.Format("Could not find a matching client for user '{0}'", message.AdditionalInformation.UserName)); } // Check if the message already exists Vox.Auditing.Model.Message auditMessage = messages.GetByGuid(message.AdditionalInformation.MessageId); if (auditMessage != null) { // Add the current message onto the audit trail auditMessage.AddAudit(new Guid(message.CorrelationId), message.DestinationName); } else { // Message has not been seen before. Need to create the master auditing records for it // Check if the batch exists if (client.CurrentBatch != null) { // Create a new message for the batch Model.Message newMessage = new Model.Message(0, message.AdditionalInformation.MessageId.ToString()) { BatchID = client.CurrentBatch.ID, ClientID = client.ID, MessageDateTime = DateTime.Now, MessageApplicationID = messages.GetMessageApplicationID(new Guid(message.ApplicationId)) }; messages.Add(newMessage); } else { throw new Exception(string.Format("No available batch is open for client '{0}'", client.Name)); } } } catch (Exception e) { T2.SendingMessage.Library.Interface.IMessageQueueConnector queue = T2.SendingMessage.Library.MessageQueueFactory.Create(); queue.SendAsyncExceptionMessage(e, "Vox.Auditing", message); } return ""; }
/// <summary> /// Writes the message into the Auditing database if required and updates the correlation Guid for that message if /// it doesn't already exist /// </summary> /// <param name="message">Message to audit</param> /// <returns>A string result of the auditing</returns> public string ProcessWorker(T2.SendingMessage.Library.Message message) { try { if (clients == null) { throw new Exception("Please call the initialise call before calling the worker"); } // Get the client Client client = clients.GetByName(message.AdditionalInformation.UserId.ToString()); if (client == null) { throw new Exception(string.Format("Could not find a matching client for user '{0}'", message.AdditionalInformation.UserName)); } // Check if the message already exists Vox.Auditing.Model.Message auditMessage = messages.GetByGuid(message.AdditionalInformation.MessageId); if (auditMessage != null) { // Add the current message onto the audit trail auditMessage.AddAudit(new Guid(message.CorrelationId), message.DestinationName); } else { // Message has not been seen before. Need to create the master auditing records for it // Check if the batch exists if (client.CurrentBatch != null) { // Create a new message for the batch Model.Message newMessage = new Model.Message(0, message.AdditionalInformation.MessageId.ToString()) { BatchID = client.CurrentBatch.ID, ClientID = client.ID, MessageDateTime = DateTime.Now, MessageApplicationID = messages.GetMessageApplicationID(new Guid(message.ApplicationId)) }; messages.Add(newMessage); } else { throw new Exception(string.Format("No available batch is open for client '{0}'", client.Name)); } } } catch (Exception e) { T2.SendingMessage.Library.Interface.IMessageQueueConnector queue = T2.SendingMessage.Library.MessageQueueFactory.Create(); queue.SendAsyncExceptionMessage(e, "Vox.Auditing", message); } return(""); }
/// <summary> /// Gets a message from the repository by the given ID /// </summary> /// <param name="aID">The integer identifier for the message</param> /// <returns>A Message object or Null</returns> public Model.Message GetByID(int aID) { if (aID <= 0) { throw new ArgumentException("Cannot search for a Message Object with a non positive ID", "aID"); } Message result = null; using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) { var selectResult = from m in context.Messages where m.MessageID == aID select m; // Check the results. Can only have one result if (selectResult.Count() == 1) { DataModel.Message selectedMessage = selectResult.First(); result = new Message(selectedMessage.MessageID, selectedMessage.MessageNumber) { ClientID = selectedMessage.MessageClientID, MessageDateTime = selectedMessage.MessageDateTime, BatchID = selectedMessage.BatchID, MessageApplicationID = selectedMessage.MessageApplicationID }; } } return result; }
private bool entity_AddMessageAudit(Message message, Guid correlationID, string state) { bool saved = false; using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) { context.MessageAudits.AddObject(new DataModel.MessageAudit() { MessageCorrelationID = correlationID.ToString(), MessageID = message.ID, MessageDateTime = DateTime.Now, MessageState = state }); saved = context.SaveChanges() > 0; } return saved; }