diff --git a/LoggingMonkey.Web/Controllers/MainController.cs b/LoggingMonkey.Web/Controllers/MainController.cs index 508c462..ace1ae3 100644 --- a/LoggingMonkey.Web/Controllers/MainController.cs +++ b/LoggingMonkey.Web/Controllers/MainController.cs @@ -45,8 +45,13 @@ public void Index([FromUri] SearchModel model) model.FromDate = ConvertQueryValueToDate("FromDate"); model.ToDate = ConvertQueryValueToDate("ToDate"); + var beginTime = DateTime.Now; + var messages = MessageRetriever.Get(model); - var vm = new IndexViewModel { Search = model, DisplayOptions = displayOptions, Messages = messages }; + + var timeSpan = DateTime.Now - beginTime; + + var vm = new IndexViewModel { Search = model, DisplayOptions = displayOptions, Messages = messages, TimeElapsedMs = timeSpan.TotalMilliseconds }; UnbufferedRenderer.Render(ControllerContext, ViewData, TempData, Response, vm); } diff --git a/LoggingMonkey.Web/Helpers/MessageRetriever.cs b/LoggingMonkey.Web/Helpers/MessageRetriever.cs index 66f2468..bb81229 100644 --- a/LoggingMonkey.Web/Helpers/MessageRetriever.cs +++ b/LoggingMonkey.Web/Helpers/MessageRetriever.cs @@ -9,7 +9,9 @@ namespace LoggingMonkey.Web.Helpers { public static class MessageRetriever { - private static readonly CachedHashedWebCsvFile Tor = new CachedHashedWebCsvFile (Path.Combine(Path.GetTempPath(), "tor.csv"), @"http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv"); + private const string TorIpListAddress = @"http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv"; + + private static readonly CachedHashedWebCsvFile Tor = new CachedHashedWebCsvFile (Path.Combine(Path.GetTempPath(), "tor.csv"), TorIpListAddress); public static MessagesModel Get(SearchModel search) { @@ -26,14 +28,14 @@ public static MessagesModel Get(SearchModel search) var lines = FastLogReader.ReadAllLines(networkName, channelName, search.FromDate.Value, search.ToDate.Value); - Process(output, Filter(lines, search)); + Process(output, Filter(lines, search, output)); search.FromDate = prevFromDate; search.ToDate = prevToDate; return output; } - private static IEnumerable Filter(IEnumerable lines, SearchModel search) + private static IEnumerable Filter(IEnumerable lines, SearchModel search, MessagesModel output) { var regexOptions = RegexOptions.Compiled | (search.IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase); @@ -73,14 +75,19 @@ public static MessagesModel Get(SearchModel search) { // NOTE: The order of these if-statements matters. + output.LinesSearched++; + if (isDirectLineMatch(line)) { + output.LinesMatching++; + // We have a match, but we also have some outstanding context lines to // print prior to this one, so do that now. if (search.Context != 0) { while (queue.Count != 0) { + output.LinesDisplaying++; yield return queue.Dequeue(); } @@ -105,11 +112,12 @@ public static MessagesModel Get(SearchModel search) } // Fallthrough, print a direct match or one of the current trailing lines. + output.LinesDisplaying++; yield return line; } } - class PreviousMessageState + class MessageState { public void InitializeIfBlank(FastLogReader.Line line) { @@ -123,7 +131,7 @@ public bool IsLinePartOfMessage(FastLogReader.Line line) return (messageExists && nick == line.Nick && type == line.Type && line.When.Subtract(when.Value).Minutes <= 1); } - public void WriteNewState(FastLogReader.Line line) + public void SetState(FastLogReader.Line line) { nick = line.Nick; type = line.Type; @@ -139,14 +147,9 @@ public void WriteNewState(FastLogReader.Line line) private static void Process(MessagesModel model, IEnumerable lines) { - // - // This process could be refactored into some black LINQ magic, but - // for now, just keep track of previous Nick and Type. - // - Message msg = null; - var previousState = new PreviousMessageState(); + var previousState = new MessageState(); foreach (var line in lines) { @@ -162,7 +165,7 @@ private static void Process(MessagesModel model, IEnumerable continue; } - previousState.WriteNewState(line); + previousState.SetState(line); msg = new Message { UsesTor = isTor, Type = line.Type, Nick = line.Nick, Timestamp = line.When }; diff --git a/LoggingMonkey.Web/Models/IndexViewModel.cs b/LoggingMonkey.Web/Models/IndexViewModel.cs index 6aa3334..6fdbc6e 100644 --- a/LoggingMonkey.Web/Models/IndexViewModel.cs +++ b/LoggingMonkey.Web/Models/IndexViewModel.cs @@ -5,5 +5,14 @@ public class IndexViewModel public SearchModel Search { get; set; } public DisplayOptionsModel DisplayOptions { get; set; } public MessagesModel Messages { get; set; } + public double TimeElapsedMs { get; set; } + + public string FormattedTimeElapsed + { + get + { + return string.Format("{0:0.00}", TimeElapsedMs/1000.0); + } + } } } diff --git a/LoggingMonkey.Web/Models/MessagesModel.cs b/LoggingMonkey.Web/Models/MessagesModel.cs index 1f6ce51..67b364e 100644 --- a/LoggingMonkey.Web/Models/MessagesModel.cs +++ b/LoggingMonkey.Web/Models/MessagesModel.cs @@ -27,7 +27,11 @@ public MessagesModel() public string ChannelName { get; set; } - public decimal TimeElapsed { get; set; } + public int LinesDisplaying { get; set; } + + public int LinesMatching { get; set; } + + public int LinesSearched { get; set; } public List Messages { get; set; } diff --git a/LoggingMonkey.Web/Views/Unbuffered/PostMessages.cshtml b/LoggingMonkey.Web/Views/Unbuffered/PostMessages.cshtml index 9134533..d5d9616 100644 --- a/LoggingMonkey.Web/Views/Unbuffered/PostMessages.cshtml +++ b/LoggingMonkey.Web/Views/Unbuffered/PostMessages.cshtml @@ -1,4 +1,9 @@ @model LoggingMonkey.Web.Models.IndexViewModel +

+ @Model.Messages.LinesSearched lines searched. @Model.Messages.LinesMatching lines matched. @Model.Messages.LinesDisplaying lines displayed. +
+ (@Model.FormattedTimeElapsed seconds) +

\ No newline at end of file