Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2012 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b4339b404eaf8be2956e to your computer and use it in GitHub Desktop.
Save anonymous/b4339b404eaf8be2956e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.Linq;
using AzureLogViewer.Models;
using AzureLogViewer.Tools;
using AzureLogViewer.ViewModel;
using AzureLogViewer.ViewModel.Log;
namespace AzureLogViewer.Views.Log
{
public class ShowLogView : AbstractXmlViewPage<ShowLogViewModel>
{
private static readonly HashSet<LogEntryLevel> s_knownLevels = new HashSet<LogEntryLevel> {
LogEntryLevel.Error,
LogEntryLevel.Information,
LogEntryLevel.Warning,
};
private object ShowLevelIcon(LogEntryLevel level)
{
return Html.XCreateSpan(
new XAttribute("class", String.Format("log-level-{0}", level.ToString().ToLower())),
new XAttribute("title", level.ToString()));
}
private Tuple<XAttribute[], IEnumerable<object>> ShowLogEntry(LogEntry entry)
{
return new Tuple<XAttribute[], IEnumerable<object>>(
new[]
{
Html.CreateClassAttribute(string.Format("record-{0}", entry.Level.ToString().ToLower())),
new XAttribute("entry-partitionkey", entry.PartitionKey),
new XAttribute("entry-rowkey", entry.RowKey),
},
new object[]
{
new[]
{
new XAttribute("class", "log-level-icon"),
ShowLevelIcon(entry.Level),
},
Html.XMultiline(
s_knownLevels.Contains(entry.Level) ? null : entry.Level.ToString(),
ShowDate(entry.Timestamp),
entry.Role,
string.Format("Instance {0}", entry.ShortInstance)),
Html.XCreateDiv(new XAttribute("class", "plaintext"), entry.Message),
});
}
protected override string GetTitle()
{
return String.Format("Log '{0}'", Model.CurrentLogName);
}
/// <summary>
/// Returns the logs selection menu (for header).
/// </summary>
private XElement GetPeriodsList()
{
return Html.XCreateUl(
new[] { new XAttribute("class", "links") },
PeriodExtensions.AvailablePeriods.Select(
Html.XPageOuterElementCreator(
Model.CurrentPeriod,
period => Url.RouteUrl("ShowLog", new { logName = Model.CurrentLogName, period = period }))));
}
protected override XElement[] GetSpecificBodyContent()
{
return new[]
{
Html.XCreateHead(1, GetTitle()),
GetPeriodsList(),
Model.HasRemainingLogEntries
? Html.XCreateDiv(
new XAttribute("class", "warning"),
String.Format("Some entries might not be shown. Total {0} entries shown.", Model.LogEntries.Count))
: null,
Model.LogEntries.Any()
? Html.XCreateTable(
attributes: new[] { new XAttribute("class", "list") },
tHeadData: new[]
{
Html.XCreateTableHeadRow(
new object[]
{
new object[]
{
new XAttribute("colspan", "2"),
"Information"
},
"Message",
}),
},
tRowsContent: Model.LogEntries.OrderByDescending(entry => entry.Timestamp).Select(ShowLogEntry))
: Html.XCreateDiv(
new XAttribute("class", "warning"),
"No entries found for your request"),
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment