/// <summary>
 /// Adds the message into the SQL database
 /// </summary>
 /// <param name="entity">A new message to add</param>
 /// <returns>True if the message was added</returns>
 public bool Add(Model.Message entity)
 {
     if (entity == null) { throw new ArgumentNullException("entity"); }
       if (entity.ID != 0) { throw new InvalidMessageException("Cannot add a message which has already been added!"); }
       if (entity.ClientID == 0) { throw new InvalidMessageException("Cannot add a message with no valid client!"); }
       if (entity.BatchID == 0) { throw new InvalidMessageException("Cannot add a message with no valid batch!"); }
       bool added = false;
       // Check if the batch is valid first
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     DataModel.Message newMessage = new DataModel.Message() {
       MessageNumber = entity.Name,
       BatchID = entity.BatchID,
       MessageDateTime = entity.MessageDateTime,
       MessageApplicationID = entity.MessageApplicationID,
       MessageClientID = entity.ClientID
     };
     context.Messages.AddObject(newMessage);
     added = context.SaveChanges() != 0;
     if (added) {
       AddMessageToDictionary(entity);
       entity.ID = newMessage.MessageID;
     }
       }
       return added;
 }
Exemple #2
0
        /// <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);
        }
        /// <summary>
        /// Retrieves the batch from the database by search on the BatchID. If a negative ID is used it will throw an ArgumentException
        /// </summary>
        /// <param name="aID">A batch ID</param>
        /// <returns>Null if the batch ID doesn't exist, otherwise a Batch Object with the given ID</returns>
        public Vox.Auditing.Model.Batch GetByID(int aID)
        {
            if (aID <= 0)
            {
                throw new ArgumentException("Cannot search for a Batch Object with a non positive ID", "aID");
            }
            Batch result = null;

            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                var selectResult = from m in context.Batches
                                   where m.BatchID == aID
                                   select m;
                // Check the results. Can only have one result
                if (selectResult.Count() == 1)
                {
                    DataModel.Batch selectedBatch = selectResult.First();
                    result = new Batch(selectedBatch.BatchID, selectedBatch.BatchNumber)
                    {
                        ClientID   = selectedBatch.MessageClientID,
                        StartDate  = selectedBatch.StartDate,
                        FinishDate = selectedBatch.FinishDate
                    };
                }
            }
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Gets the Client from the database using the unique name as the lookup parameter
        /// </summary>
        /// <param name="aName">A unique string Identifier</param>
        /// <returns>A Client for the given ID, other Null if the client does not exist</returns>
        public Client GetByName(string aName)
        {
            if (string.IsNullOrEmpty(aName))
            {
                throw new ArgumentException("Cannot search for a Client Object with a empty ID", "aName");
            }
            Client result = null;

            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                var selectResult = from m in context.MessageClients
                                   where m.MessageClientIdentifier == aName
                                   select m;
                // Check the results. Can only have one result
                if (selectResult.Count() == 1)
                {
                    var selectedClient = selectResult.First();
                    result = new Client(selectedClient.MessageClientID, selectedClient.MessageClientIdentifier);
                    var currentSelectBatch = from b in context.Batches
                                             where b.MessageClientID == result.ID && b.FinishDate == null
                                             select b;
                    if (currentSelectBatch.Count() == 1)
                    {
                        var selectedBatch = currentSelectBatch.First();
                        result.CurrentBatch = new Batch(selectedBatch.BatchID, selectedBatch.BatchNumber)
                        {
                            ClientID   = selectedBatch.MessageClientID,
                            StartDate  = selectedBatch.StartDate,
                            FinishDate = null
                        };
                    }
                    ;
                }
            }
            return(result);
        }
 /// <summary>
 /// Gets the Client from the database using the unique name as the lookup parameter
 /// </summary>
 /// <param name="aName">A unique string Identifier</param>
 /// <returns>A Client for the given ID, other Null if the client does not exist</returns>
 public Client GetByName(string aName)
 {
     if (string.IsNullOrEmpty(aName)) { throw new ArgumentException("Cannot search for a Client Object with a empty ID", "aName"); }
       Client result = null;
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     var selectResult = from m in context.MessageClients
                    where m.MessageClientIdentifier == aName
                    select m;
     // Check the results. Can only have one result
     if (selectResult.Count() == 1) {
       var selectedClient = selectResult.First();
       result = new Client(selectedClient.MessageClientID, selectedClient.MessageClientIdentifier);
       var currentSelectBatch = from b in context.Batches
                            where b.MessageClientID == result.ID && b.FinishDate == null
                            select b;
       if (currentSelectBatch.Count() == 1) {
     var selectedBatch = currentSelectBatch.First();
     result.CurrentBatch = new Batch(selectedBatch.BatchID, selectedBatch.BatchNumber) {
       ClientID = selectedBatch.MessageClientID,
       StartDate = selectedBatch.StartDate,
       FinishDate = null
     };
       };
     }
       }
       return result;
 }
        /// <summary>
        /// Updates an existing batch entity (Normally this will be to set the end date on the batch)
        /// </summary>
        /// <param name="entity">Batch to update</param>
        /// <returns>True if the batch was altered</returns>
        public bool Update(Vox.Auditing.Model.Batch entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.ID == 0)
            {
                throw new InvalidBatchException("Cannot updated a batch which has not been added!");
            }
            if (entity.ClientID == 0)
            {
                throw new InvalidBatchException("Cannot update a batch with no valid client!");
            }
            bool updated = false;

            // Check if the batch is valid first
            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                // Check that no existing batches are open for the current client ID
                var validBatch = from m in context.Batches
                                 where m.BatchID == entity.ID
                                 select m;
                if (validBatch.Count() == 1)
                {
                    DataModel.Batch selectBatch = validBatch.First();
                    selectBatch.FinishDate = entity.FinishDate;
                    updated = context.SaveChanges() != 0;
                }
                else
                {
                    throw new InvalidBatchException(string.Format("Batch '{0}' does not exist", entity.Number));
                }
            }
            return(updated);
        }
 /// <summary>
 /// Creates a new Batch entry for the given client in the table. The combination of BatchNumber and Client must be unique, if not a InvalidBatchException will
 /// be thrown. In addition existing batches must be closed first.
 /// </summary>
 /// <param name="entity">Batch which will be added.</param>
 /// <returns>True if the batch was succesfully added, otherwise false. If the batch is invalid an InvalidBatchException will be thrown</returns>
 public bool Add(Vox.Auditing.Model.Batch entity)
 {
     if (entity == null) { throw new ArgumentNullException("entity"); }
       if (entity.ID != 0) { throw new InvalidBatchException("Cannot add a batch which has already been added!"); }
       if (entity.ClientID == 0) { throw new InvalidBatchException("Cannot add a batch with no valid client!"); }
       bool added = false;
       // Check if the batch is valid first
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     // Check that no existing batches are open for the current client ID
     var validBatch = from m in context.Batches
                  where m.MessageClientID == entity.ClientID && m.FinishDate == null
                  select m;
     if (validBatch.Count() == 0) {
       // Try and add the new batch
       context.Batches.AddObject(new DataModel.Batch() {
     BatchID = entity.ID,
     BatchNumber = entity.Number,
     MessageClientID = entity.ClientID,
     StartDate = entity.StartDate
       });
       added = context.SaveChanges() != 0;
     } else {
       throw new InvalidBatchException(string.Format("Batch '{0}' is still open for the given client", validBatch.First().BatchNumber));
     }
       }
       return added;
 }
 /// <summary>
 /// Adds a client to the repository. The client entity will be slightly validated before it can be added.
 /// </summary>
 /// <param name="entity">A client entity to add</param>
 /// <returns>True if the entity was added, otherwise false</returns>
 public bool Add(Model.Client entity)
 {
     if (entity == null) { throw new ArgumentNullException("entity"); }
       if (entity.ID != 0) { throw new InvalidClientException("Cannot add a client which has already been added!"); }
       bool added = false;
       // Check if the client is valid first
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     context.MessageClients.AddObject(new DataModel.MessageClient() {
       MessageClientIdentifier = entity.Name
     });
     added = context.SaveChanges() != 0;
       }
       return added;
 }
Exemple #9
0
        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);
        }
 /// <summary>
 /// Gets the Client from the database using the integer ID as the lookup parameter
 /// </summary>
 /// <param name="aID">A unique Integer Identifier which matches the MessageClientID in the MessageClient Table</param>
 /// <returns>A Client for the given ID, other Null if the client does not exist</returns>
 public Client GetByID(int aID)
 {
     if (aID <= 0) { throw new ArgumentException("Cannot search for a Client Object with a non positive ID", "aID"); }
       Client result = null;
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     var selectResult = from m in context.MessageClients
                    where m.MessageClientID == aID
                    select m;
     // Check the results. Can only have one result
     if (selectResult.Count() == 1) {
       DataModel.MessageClient selectedClient = selectResult.First();
       result = new Client(selectedClient.MessageClientID, selectedClient.MessageClientIdentifier);
     }
       }
       return result;
 }
 /// <summary>
 /// Retrieves the batch from the database by search on the BatchID. If a negative ID is used it will throw an ArgumentException
 /// </summary>
 /// <param name="aID">A batch ID</param>
 /// <returns>Null if the batch ID doesn't exist, otherwise a Batch Object with the given ID</returns>
 public Vox.Auditing.Model.Batch GetByID(int aID)
 {
     if (aID <= 0) { throw new ArgumentException("Cannot search for a Batch Object with a non positive ID", "aID"); }
       Batch result = null;
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     var selectResult = from m in context.Batches
                    where m.BatchID == aID
                    select m;
     // Check the results. Can only have one result
     if (selectResult.Count() == 1) {
       DataModel.Batch selectedBatch = selectResult.First();
       result = new Batch(selectedBatch.BatchID, selectedBatch.BatchNumber) {
     ClientID = selectedBatch.MessageClientID,
     StartDate = selectedBatch.StartDate,
     FinishDate = selectedBatch.FinishDate
       };
     }
       }
       return result;
 }
        /// <summary>
        /// Creates a new Batch entry for the given client in the table. The combination of BatchNumber and Client must be unique, if not a InvalidBatchException will
        /// be thrown. In addition existing batches must be closed first.
        /// </summary>
        /// <param name="entity">Batch which will be added.</param>
        /// <returns>True if the batch was succesfully added, otherwise false. If the batch is invalid an InvalidBatchException will be thrown</returns>
        public bool Add(Vox.Auditing.Model.Batch entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.ID != 0)
            {
                throw new InvalidBatchException("Cannot add a batch which has already been added!");
            }
            if (entity.ClientID == 0)
            {
                throw new InvalidBatchException("Cannot add a batch with no valid client!");
            }
            bool added = false;

            // Check if the batch is valid first
            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                // Check that no existing batches are open for the current client ID
                var validBatch = from m in context.Batches
                                 where m.MessageClientID == entity.ClientID && m.FinishDate == null
                                 select m;
                if (validBatch.Count() == 0)
                {
                    // Try and add the new batch
                    context.Batches.AddObject(new DataModel.Batch()
                    {
                        BatchID         = entity.ID,
                        BatchNumber     = entity.Number,
                        MessageClientID = entity.ClientID,
                        StartDate       = entity.StartDate
                    });
                    added = context.SaveChanges() != 0;
                }
                else
                {
                    throw new InvalidBatchException(string.Format("Batch '{0}' is still open for the given client", validBatch.First().BatchNumber));
                }
            }
            return(added);
        }
 /// <summary>
 /// Gets a message from the repository by the given message application ID
 /// </summary>
 /// <param name="aID">The Guid for the given message</param>
 /// <returns>A Message object or Null</returns>
 public Model.Message GetByGuid(Guid aGuid)
 {
     if (aGuid == Guid.Empty) { throw new ArgumentException("Cannot search for a Message Object with a empty Guid", "aGuid"); }
       Message result = null;
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     var selectResult = from m in context.Messages
                    where m.MessageNumber == aGuid.ToString()
                    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;
 }
Exemple #14
0
        /// <summary>
        /// Gets the Client from the database using the integer ID as the lookup parameter
        /// </summary>
        /// <param name="aID">A unique Integer Identifier which matches the MessageClientID in the MessageClient Table</param>
        /// <returns>A Client for the given ID, other Null if the client does not exist</returns>
        public Client GetByID(int aID)
        {
            if (aID <= 0)
            {
                throw new ArgumentException("Cannot search for a Client Object with a non positive ID", "aID");
            }
            Client result = null;

            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                var selectResult = from m in context.MessageClients
                                   where m.MessageClientID == aID
                                   select m;
                // Check the results. Can only have one result
                if (selectResult.Count() == 1)
                {
                    DataModel.MessageClient selectedClient = selectResult.First();
                    result = new Client(selectedClient.MessageClientID, selectedClient.MessageClientIdentifier);
                }
            }
            return(result);
        }
Exemple #15
0
        /// <summary>
        /// Adds the message into the SQL database
        /// </summary>
        /// <param name="entity">A new message to add</param>
        /// <returns>True if the message was added</returns>
        public bool Add(Model.Message entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.ID != 0)
            {
                throw new InvalidMessageException("Cannot add a message which has already been added!");
            }
            if (entity.ClientID == 0)
            {
                throw new InvalidMessageException("Cannot add a message with no valid client!");
            }
            if (entity.BatchID == 0)
            {
                throw new InvalidMessageException("Cannot add a message with no valid batch!");
            }
            bool added = false;

            // Check if the batch is valid first
            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                DataModel.Message newMessage = new DataModel.Message()
                {
                    MessageNumber        = entity.Name,
                    BatchID              = entity.BatchID,
                    MessageDateTime      = entity.MessageDateTime,
                    MessageApplicationID = entity.MessageApplicationID,
                    MessageClientID      = entity.ClientID
                };
                context.Messages.AddObject(newMessage);
                added = context.SaveChanges() != 0;
                if (added)
                {
                    AddMessageToDictionary(entity);
                    entity.ID = newMessage.MessageID;
                }
            }
            return(added);
        }
Exemple #16
0
        /// <summary>
        /// Adds a client to the repository. The client entity will be slightly validated before it can be added.
        /// </summary>
        /// <param name="entity">A client entity to add</param>
        /// <returns>True if the entity was added, otherwise false</returns>
        public bool Add(Model.Client entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.ID != 0)
            {
                throw new InvalidClientException("Cannot add a client which has already been added!");
            }
            bool added = false;

            // Check if the client is valid first
            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                context.MessageClients.AddObject(new DataModel.MessageClient()
                {
                    MessageClientIdentifier = entity.Name
                });
                added = context.SaveChanges() != 0;
            }
            return(added);
        }
Exemple #17
0
        /// <summary>
        /// Gets the application ID for the given Message Application Guid
        /// </summary>
        /// <param name="aGuid">Guid of the application auditing messages</param>
        /// <returns>A integer Id of the Application or 0 if the application does not exist</returns>
        public int GetMessageApplicationID(Guid aGuid)
        {
            if (aGuid == Guid.Empty)
            {
                throw new ArgumentNullException("aGuid");
            }
            int applicationID = 0;

            using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
                var result = from a in context.MessageApplications
                             where a.MessageApplicationGuid == aGuid
                             select a;
                if (result.Count() == 1)
                {
                    applicationID = result.First().MessageApplicationID;
                }
                else
                {
                    throw new Exception(string.Format("No message application has been configured for '{0}'", aGuid));
                }
            }
            return(applicationID);
        }
 /// <summary>
 /// Gets the application ID for the given Message Application Guid
 /// </summary>
 /// <param name="aGuid">Guid of the application auditing messages</param>
 /// <returns>A integer Id of the Application or 0 if the application does not exist</returns>
 public int GetMessageApplicationID(Guid aGuid)
 {
     if (aGuid == Guid.Empty) { throw new ArgumentNullException("aGuid"); }
       int applicationID = 0;
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     var result = from a in context.MessageApplications
              where a.MessageApplicationGuid == aGuid
              select a;
     if (result.Count() == 1) {
       applicationID = result.First().MessageApplicationID;
     } else {
       throw new Exception(string.Format("No message application has been configured for '{0}'", aGuid));
     }
       }
       return applicationID;
 }
 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;
 }
 /// <summary>
 /// Updates an existing batch entity (Normally this will be to set the end date on the batch)
 /// </summary>
 /// <param name="entity">Batch to update</param>
 /// <returns>True if the batch was altered</returns>
 public bool Update(Vox.Auditing.Model.Batch entity)
 {
     if (entity == null) { throw new ArgumentNullException("entity"); }
       if (entity.ID == 0) { throw new InvalidBatchException("Cannot updated a batch which has not been added!"); }
       if (entity.ClientID == 0) { throw new InvalidBatchException("Cannot update a batch with no valid client!"); }
       bool updated = false;
       // Check if the batch is valid first
       using (DataModel.VoxAuditingEntities context = new DataModel.VoxAuditingEntities(connectionString)) {
     // Check that no existing batches are open for the current client ID
     var validBatch = from m in context.Batches
                  where m.BatchID == entity.ID
                  select m;
     if (validBatch.Count() == 1) {
       DataModel.Batch selectBatch = validBatch.First();
       selectBatch.FinishDate = entity.FinishDate;
       updated = context.SaveChanges() != 0;
     } else {
       throw new InvalidBatchException(string.Format("Batch '{0}' does not exist", entity.Number));
     }
       }
       return updated;
 }