//
// HostPageHtmlRender.cs
//
// Author:
// Carsten Sonne Larsen
//
// 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 ("");
builder.AppendLine ("");
builder.AppendLine (@"");
builder.AppendLine (@"");
builder.AppendLine ("");
builder.AppendLine (config.ServerName);
builder.AppendLine ("");
builder.AppendLine (@"");
builder.AppendLine ("");
return builder.ToString ();
}
public override string Render ()
{
return "";
}
public override string RenderFooter ()
{
StringBuilder builder = new StringBuilder ();
builder.AppendLine (String.Empty);
DateTime now = DateTime.Now;
builder.AppendLine ("
");
builder.Append ("Local time is ");
builder.Append (now.ToLongDateString () + " ");
builder.Append (TimeZoneInfo.Local.StandardName + " ");
builder.Append (now.ToLongTimeString () + ". ");
builder.AppendLine ("
");
if (config.PoolMember) {
string poolLink = "http://www.pool.ntp.org/scores/" + ip;
string poolText = String.Format (@"pool.ntp.org", poolLink);
builder.Append ("Server is pool member on ");
builder.Append (poolText);
}
if (config.PeerSummeries.Pages.Count () != 0) {
builder.AppendLine ("
");
builder.Append ("Peer graphs are available with ");
builder.Append (@"");
builder.Append (config.PeerSummeries.Pages.First ().Title);
builder.Append (@" and ");
builder.Append (@"");
builder.Append (config.PeerSummeries.Pages.ToList () [1].Title);
builder.Append (@".");
}
builder.AppendLine ("
");
builder.AppendLine ("Page refreshes every 5 minutes.");
builder.AppendLine ("");
builder.AppendLine ("");
return builder.ToString ();
}
}
}