/// <summary> /// Gets all log entries. /// </summary> /// <returns></returns> /// public static List <LogEntry> GetLogEntries(LogEntryCriteria searchCriteria, string sortExpression, int startRowIndex, int maximumRows, out int totalRows) { List <LogEntry> entries = GetLogEntries( searchCriteria, sortExpression, startRowIndex, maximumRows, out totalRows, true); //if (searchCriteria.RequiresAcknowledgement!=null) //{ // //if the search criteria specifies that only entries that require or don't require // //ack should be returned then filter the list here as the RequiresAcknowledgement property is only populated in the business // //layer rather than returned from the GetLogEntires SP. It cannot be returned from the SP because // //at the time of writing this the log entries are held in a seperate DB to the ErrorType table which sepcifies // //if the error type RequiresAcknowledgement // entries = entries.FindAll(delegate(LogEntry obj) // { // return obj.RequiresAcknowledgement == searchCriteria.RequiresAcknowledgement; // }); //} return(entries); }
/// <summary> /// Gets the log entries. /// </summary> /// <param name="searchCriteria">The search criteria.</param> /// <param name="sortExpression">The sort expression.</param> /// <param name="startRowIndex">Start index of the row.</param> /// <param name="maximumRows">The maximum rows.</param> /// <returns></returns> public static List <LogEntry> GetLogEntries(LogEntryCriteria searchCriteria, string sortExpression, int startRowIndex, int maximumRows) { int totalRows; List <LogEntry> logs = GetLogEntries(searchCriteria, sortExpression, startRowIndex, maximumRows, out totalRows); if (string.IsNullOrEmpty(sortExpression)) { sortExpression = "TimeStamp"; } logs.Sort(new UniversalComparer <LogEntry>(sortExpression)); logCount = totalRows; return(logs); }
/// <summary> /// Gets the log entries. /// </summary> /// <param name="searchCriteria">The search criteria.</param> /// <param name="sortExpression">The sort expression.</param> /// <param name="startRowIndex">Start index of the row.</param> /// <param name="maximumRows">The maximum rows.</param> /// <param name="totalRows">The total rows.</param> /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param> /// <returns></returns> public static List <LogEntry> GetLogEntries(LogEntryCriteria searchCriteria, string sortExpression, int startRowIndex, int maximumRows, out int totalRows, bool fullyPopulate) { List <LogEntry> logEntries = new List <LogEntry>(); int rows = 0; try { //pre load an error type collection as this will be used in the custom fill method, this should be //more efficient than finding a related error type for each log entryone at a time if (searchCriteria.OpcoCode != Null.NullString && searchCriteria.CategoryName != Null.NullString && searchCriteria.ErrorType != Null.NullString) { ErrorType errorType = ErrorTypeController.GetErrorType(searchCriteria.ErrorType, searchCriteria.OpcoCode, searchCriteria.CategoryName); if (errorType != null) { errorTypes = new List <ErrorType>(); errorTypes.Add(errorType); } } else { errorTypes = ErrorTypeController.GetErrorTypes(searchCriteria.OpcoCode, searchCriteria.CategoryName, ""); } logEntries = CBO <LogEntry> .FillCollection( DataAccessProvider.Instance(DATAPROVIDER).GetLogEntries(searchCriteria, sortExpression, startRowIndex, maximumRows, out rows), CustomFill, fullyPopulate); errorTypes.Clear(); errorTypes = null; } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } totalRows = rows; return(logEntries); }
public void FindByWithNoDomainEventShouldBeCountOf4() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); var criteria = new LogEntryCriteria { FromTimestamp = new DateTime(2019, 2, 2).Ticks, ToTimestamp = new DateTime(2019, 9, 10).Ticks, }; // Act var result = repository.FindBy(criteria); // Assert Assert.AreEqual(4, result.Count()); }
public void ReplayEventCallsFindByOnRepositoryWithRightCriteria() { // Arrange var logEntryCriteria = new LogEntryCriteria(); var sender = new object(); var basicDeliverEventArgs = new BasicDeliverEventArgs { BasicProperties = new BasicProperties { Type = "SomeCommand", Timestamp = new AmqpTimestamp(new DateTime(2019, 6, 4).Ticks), }, Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new ReplayEventsCommand { EventType = "DomainEvent", RoutingKey = "Test.*" })), RoutingKey = "TestQueue" }; var eventReplayerMock = new Mock <IEventReplayer>(); var repositoryMock = new Mock <IAuditLogRepository <LogEntry, long> >(); var repository = repositoryMock.Object; var eventReplayer = eventReplayerMock.Object; var routingKeyMatcherMock = new Mock <IRoutingKeyMatcher>(); var routingKeyMatcher = routingKeyMatcherMock.Object; var eventBusMock = new Mock <IEventBus>(); var eventBus = eventBusMock.Object; var modelMock = new Mock <IModel>(); var model = modelMock.Object; eventBusMock.Setup(mock => mock.Model).Returns(model); var commandListener = new AuditLogCommandListener(repository, eventReplayer, routingKeyMatcher, eventBus); repositoryMock.Setup(mock => mock.FindBy(It.IsAny <LogEntryCriteria>())) .Callback((LogEntryCriteria criteria) => logEntryCriteria = criteria); // Act commandListener.Handle(sender, basicDeliverEventArgs); // Assert.AreEqual("DomainEvent", logEntryCriteria.EventType); Assert.AreEqual("Test.*", logEntryCriteria.RoutingKey); Assert.AreEqual(null, logEntryCriteria.FromTimestamp); Assert.AreEqual(null, logEntryCriteria.ToTimestamp); }
public void FindByWithTimestampsOutOfReachShouldBeCountOf0() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); var criteria = new LogEntryCriteria { EventType = "DomainEvent", FromTimestamp = new DateTime(2019, 6, 7).Ticks, ToTimestamp = new DateTime(2019, 6, 10).Ticks, }; // Act var result = repository.FindBy(criteria); // Assert Assert.AreEqual(0, result.Count()); }
public void FindByIsInstanceOfIEnumerableOfLogEntry() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); var criteria = new LogEntryCriteria { EventType = "DomainEvent", FromTimestamp = new DateTime(2019, 7, 1).Ticks, ToTimestamp = new DateTime(2019, 7, 3).Ticks, }; // Act var result = repository.FindBy(criteria); // Assert Assert.IsInstanceOfType(result, typeof(IEnumerable <LogEntry>)); }
private ReplayEventsResponse ReplayEvents(ReplayEventsCommand command) { try { var criteria = new LogEntryCriteria { EventType = command.EventType, RoutingKey = command.RoutingKey, FromTimestamp = command.FromTimestamp, ToTimestamp = command.ToTimestamp }; var logEntries = _repository.FindBy(criteria).ToList(); _logger.LogTrace($"Found {logEntries.Count} log entries"); logEntries = logEntries .Where(entry => _routingKeyMatcher.IsMatch(criteria.RoutingKey, entry.RoutingKey)).ToList(); _logger.LogTrace($"Filtered log entries, which results in {logEntries.Count} log entries"); _eventReplayer.RegisterReplayExchange(command.ReplayExchangeName); _eventReplayer.ReplayLogEntries(logEntries); _logger.LogTrace($"Replayed {logEntries.Count} log entries"); } catch (Exception exception) { _logger.LogError($"Internal error occured, with exception: {exception.Message}"); return(new ReplayEventsResponse { Code = StatusCodes.Status500InternalServerError, Status = "Internal Error" }); } _logger.LogTrace("Sending response"); return(new ReplayEventsResponse { Code = StatusCodes.Status200OK, Status = "OK" }); }
/// <summary> /// Numbers the of log entries. /// </summary> /// <param name="searchCriteria">The search criteria.</param> /// <param name="sortExpression">The sort expression.</param> /// <param name="startRowIndex">Start index of the row.</param> /// <param name="maximumRows">The maximum rows.</param> /// <returns></returns> public static Int32 NumberOfLogEntries(LogEntryCriteria searchCriteria, string sortExpression, int startRowIndex, int maximumRows) { return(logCount); }