Skip to content

Instantly share code, notes, and snippets.

Created February 8, 2012 15:38
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/29deb19a382dcb64055c to your computer and use it in GitHub Desktop.
Save anonymous/29deb19a382dcb64055c to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using AzureLogViewer.ViewModel.AzureDiagnostics;
namespace AzureLogViewer.CSViews.AzureDiagnostics
{
/// <summary>
/// View for ShowLog controller.
/// </summary>
public class ShowPerformanceCountersView : AbstractAzureDiagnosticsView<ShowPerformanceCountersViewModel>
{
private Func<PerformanceCounterColumnKey, object> ShowPerformanceCounterValue(IDictionary<PerformanceCounterColumnKey, double?> data)
{
return column => new object[]
{
new XAttribute("class", "data"),
data[column].HasValue ? data[column].Value.ToString("0.0000") : "-",
};
}
private IEnumerable<object> ShowPerformanceCounterEntry(Tuple<AzureDiagnosticsRowKey, IDictionary<PerformanceCounterColumnKey, double?>> entry)
{
return new[] { GetAzureDiagnosticsRowDescription(entry.Item1) }
.Concat(Model.PerformanceCounterTable.Columns.Select(ShowPerformanceCounterValue(entry.Item2)));
}
/// <summary>
/// Returns the page main content (excuding headers/footers/etc).
/// </summary>
protected override XElement[] GetSpecificAzureDiagnosticsBodyContent()
{
return new[]
{
Model.HasRemainingPerformanceCounterEntries
? ShowWarning("Some entries might not be shown. Total {0} entries shown.", Model.PerformanceCounterTable.Count)
: null,
Model.PerformanceCounterTable.Any()
? Html.XCreateTable(
attributes: new[] { Html.CreateClassAttribute("list") },
tHeadData: new[]
{
Html.XCreateTableHeadRow(
tCellsContent: new object[]
{
new object[]
{
Html.CreateClassAttribute("loghead-information"),
"Information"
},
}
.Concat(Model.PerformanceCounterTable.Columns.Select(column => column.CounterName))),
},
tRowsContent: Model.PerformanceCounterTable.OrderByDescending(entry => entry.Item1.Timestamp).Select(ShowPerformanceCounterEntry),
tFootData: new[]
{
Html.XCreateTableHeadRow(
tCellsContent: new object[]
{
new object[]
{
new XAttribute("colspan", "3"),
string.Format("Total {0} entries", Model.PerformanceCounterTable.Count)
},
}),
})
: ShowWarning("No entries found for your request."),
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment