// Decompiled with JetBrains decompiler
// Type: Sitecore.sitecore.admin.stats
// Assembly: Sitecore.Client, Version=18.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: C7059C67-2306-48C0-9640-BA8B104F7B8E
// Assembly location: C:\inetpub\wwwroot\sc103lkgsc.dev.local\bin\Sitecore.Client.dll
// XML documentation location: C:\inetpub\wwwroot\sc103lkgsc.dev.local\bin\Sitecore.Client.xml
using Sitecore;
using Sitecore.DependencyInjection;
using Sitecore.Diagnostics;
using Sitecore.Web;
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace CustomizeAdminPageAccess
{
[AllowDependencyInjection]
/// The statistics page.
public class stats : AdminPage
{
/// form1 control.
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
protected HtmlForm form1;
/// siteSelector control.
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
protected HtmlGenericControl siteSelector;
/// renderings control.
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
protected PlaceHolder renderings;
/// c_reset control.
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
protected Button c_reset;
/// Handles the Click event of the 'Reset' button.
/// The sender.
///
/// The instance containing the event data.
///
protected void c_reset_Click(object sender, EventArgs arguments)
{
Assert.ArgumentNotNull(sender, nameof(sender));
Assert.ArgumentNotNull((object)arguments, nameof(arguments));
Statistics.Clear();
this.renderings.Controls.Clear();
}
/// Handles the Load event of the Page control.
/// The source of the event.
///
/// The instance containing the event data.
///
protected void Page_Load(object sender, EventArgs arguments)
{
Assert.ArgumentNotNull(sender, nameof(sender));
Assert.ArgumentNotNull((object)arguments, nameof(arguments));
this.CheckSecurity();
this.ShowSiteSelector();
this.ShowRenderingStats(this.Request.QueryString["site"]);
}
/// Gets the site names.
/// The site names.
private static string[] GetSiteNames()
{
List stringList = new List();
foreach (Statistics.RenderingData renderingStatistic in Statistics.RenderingStatistics)
{
if (!stringList.Contains(renderingStatistic.SiteName))
stringList.Add(renderingStatistic.SiteName);
}
return stringList.ToArray();
}
/// Shows the rendering stats.
/// Name of the site.
private void ShowRenderingStats(string siteName)
{
HtmlTable htmlTable = new HtmlTable()
{
Border = 1,
CellPadding = 2
};
HtmlUtil.AddRow(htmlTable, new string[11]
{
"Rendering",
"Site",
"Count",
"From cache",
"Avg. time (ms)",
"Avg. items",
"Max. time",
"Max. items",
"Total time",
"Total items",
"Last run"
});
SortedList sortedList = new SortedList();
foreach (Statistics.RenderingData renderingStatistic in Statistics.RenderingStatistics)
{
if (siteName == null || renderingStatistic.SiteName.Equals(siteName, StringComparison.OrdinalIgnoreCase))
sortedList.Add(renderingStatistic.SiteName + (object)(int)byte.MaxValue + renderingStatistic.TraceName, renderingStatistic);
}
foreach (Statistics.RenderingData renderingData in (IEnumerable)sortedList.Values)
{
HtmlTableRow htmlTableRow = HtmlUtil.AddRow(htmlTable, (object)renderingData.TraceName, (object)renderingData.SiteName, (object)renderingData.RenderCount, (object)renderingData.UsedCache, (object)renderingData.AverageTime.TotalMilliseconds, (object)renderingData.AverageItemsAccessed, (object)renderingData.MaxTime.TotalMilliseconds, (object)renderingData.MaxItemsAccessed, (object)renderingData.TotalTime, (object)renderingData.TotalItemsAccessed, (object)DateUtil.ToServerTime(renderingData.LastRendered));
for (int index = 2; index < htmlTableRow.Cells.Count; ++index)
htmlTableRow.Cells[index].Align = "right";
}
this.renderings.Controls.Add((Control)htmlTable);
}
/// Shows the site selector.
private void ShowSiteSelector()
{
string[] siteNames = stats.GetSiteNames();
Array.Sort(siteNames);
HtmlTable table = HtmlUtil.CreateTable(1, siteNames.Length + 1);
table.Border = 0;
table.CellPadding = 5;
table.Rows[0].Cells[0].InnerHtml = "All sites";
int index = 1;
foreach (string str in siteNames)
{
table.Rows[0].Cells[index].InnerHtml = string.Format("{0}", (object)str);
++index;
}
this.siteSelector.Controls.Add((Control)table);
}
}
}