Files
ntpa/Ntp.Analyzer/Render/Host/DefaultHostPageRender.cs
T
2016-03-06 00:15:13 +01:00

127 lines
5.6 KiB
C#

//
// HostPageHtmlRender.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
//
// Copyright (c) 2013 Carsten Sonne Larsen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Linq;
using System.Text;
using Ntp.Analyzer.Config.Page;
namespace Ntp.Analyzer.Render.Host
{
public sealed class DefaultHostPageRender : HtmlObjectRender
{
private readonly HostPageConfiguration config;
private readonly string ip;
private readonly int refresh;
public DefaultHostPageRender (HostPageConfiguration config, string ip, int refresh)
: base(config.WebPath)
{
this.config = config;
this.ip = ip;
this.refresh = refresh;
}
public override string RenderHead ()
{
StringBuilder builder = new StringBuilder ();
builder.AppendLine ("<!DOCTYPE html>");
builder.AppendLine ("<html><head>");
builder.AppendLine (@"<meta charset=""UTF-8"">");
builder.AppendLine (@"<style type=""text/css"" media=""screen"">");
builder.AppendLine ("body {font-family: monospace; line-height:100%; }");
builder.AppendLine ("table { border-collapse:collapse; border-spacing: 0; width: 940px; }");
builder.AppendLine (
"th { text-align: left; font-weight: bold; border-bottom: 2px solid; padding: 0px; padding-top: 5px; padding-bottom: 3px;}");
builder.AppendLine ("td { padding: 0px; padding-right: 7px; padding-left: 2px; padding-top: 2px; padding-bottom: 2px; }");
builder.AppendLine ("td.aright { text-align: right; padding-right: 17px;}");
builder.AppendLine ("td.spc { padding: 0px; line-height: 5px; }");
builder.AppendLine ("td.but { border-top: 2px solid; padding: 0px; padding-top: 2px; line-height: 7px; }");
builder.AppendLine ("a:link { color:#33348e; text-decoration: none; }");
builder.AppendLine ("a:visited { color:#33348e; text-decoration: none; }");
builder.AppendLine ("a:hover { color:#33348e; text-decoration: underline;; }");
builder.AppendLine ("a:active { color:#7476b4; text-decoration: underline; }");
builder.AppendLine ("</style>");
builder.AppendLine ("<title>");
builder.AppendLine (config.ServerName);
builder.AppendLine ("</title>");
builder.AppendLine (@"<meta http-equiv=""refresh"" content=""" + refresh + @""">");
builder.AppendLine ("</head>");
return builder.ToString ();
}
public override string Render ()
{
return "<body>";
}
public override string RenderFooter ()
{
StringBuilder builder = new StringBuilder ();
builder.AppendLine (String.Empty);
DateTime now = DateTime.Now;
builder.AppendLine ("<br>");
builder.Append ("Local time is ");
builder.Append (now.ToLongDateString () + " ");
builder.Append (TimeZoneInfo.Local.StandardName + " ");
builder.Append (now.ToLongTimeString () + ". ");
builder.AppendLine ("<br><br>");
if (config.PoolMember) {
string poolLink = "http://www.pool.ntp.org/scores/" + ip;
string poolText = String.Format (@"<a href=""{0}"">pool.ntp.org</a>", poolLink);
builder.Append ("Server is pool member on ");
builder.Append (poolText);
}
if (config.PeerSummeries.Pages.Count () != 0) {
builder.AppendLine ("<br><br>");
builder.Append ("Peer graphs are available with ");
builder.Append (@"<a href=""");
builder.Append (config.PeerSummeries.Pages.First ().Link);
builder.Append (@""">");
builder.Append (config.PeerSummeries.Pages.First ().Title);
builder.Append (@"</a> and ");
builder.Append (@"<a href=""");
builder.Append (config.PeerSummeries.Pages.ToList () [1].Link);
builder.Append (@""">");
builder.Append (config.PeerSummeries.Pages.ToList () [1].Title);
builder.Append (@"</a>.");
}
builder.AppendLine ("<br><br>");
builder.AppendLine ("Page refreshes every 5 minutes.");
builder.AppendLine ("</body>");
builder.AppendLine ("</html>");
return builder.ToString ();
}
}
}