// // BootstrapPeerInfoRender.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.Globalization; using System.Text; using Ntp.Analyzer.Objects; namespace Ntp.Analyzer.Render.Peer { public sealed class BootstrapPeerInfoRender : HtmlObjectRender { private readonly DateTime next; private readonly DateTime now; private readonly TimeServer server; public BootstrapPeerInfoRender(string webPath, TimeServer server, DateTime now, DateTime next) : base(webPath) { this.server = server; this.now = now; this.next = next; } public override string RenderHead() { StringBuilder builder = new StringBuilder(); builder.AppendLine(@"
"); builder.AppendLine(@"
"); builder.Append("

"); builder.Append(server.Name); builder.Append("

    

Stratum "); builder.Append(GetStratumText()); builder.AppendLine(" server

"); builder.Append("

"); builder.Append(now.ToLongDateString() + " CEST "); builder.Append(now.ToLongTimeString() + ". "); builder.Append("Next refresh scheduled at "); builder.Append(next.ToShortTimeString()); builder.AppendLine(".

"); return builder.ToString(); } public override string Render() { StringBuilder builder = new StringBuilder(); builder.AppendLine(@"
"); builder.AppendLine(@"
Server location
"); builder.AppendLine(String.Format(@"
{0}
", server.Location)); builder.AppendLine(@"
"); builder.AppendLine(@"
"); builder.AppendLine(@"
Synchronization
"); builder.AppendFormat(@"
{0}
", GetServerSync()); builder.AppendLine(@"
"); builder.AppendLine(@"
"); builder.AppendLine(@"
IP address
"); builder.AppendLine(String.Format(@"
{0}
", server.Address)); builder.AppendLine(@"
Access policy
"); builder.AppendLine(String.Format(@"
{0}
", GetServerAccess())); builder.AppendLine(@"
"); builder.AppendLine(@"
"); builder.AppendLine(@"
IPv6 address
"); builder.AppendLine(String.Format(@"
{0}
", server.V6Address ?? "N/A")); builder.AppendLine(@"
Service area
"); builder.AppendLine(String.Format(@"
{0}
", GetServiceArea())); builder.AppendLine(@"
"); builder.AppendLine(@"
"); builder.AppendLine(@"
Pool member
"); builder.AppendLine(String.Format(@"
{0}
", GetPoolMemberStatus())); builder.AppendLine(@"
Description
"); builder.AppendLine(String.Format(@"
{0}
", server.Updated.ToLongDateString())); builder.AppendLine(@"
"); builder.AppendLine(@"

"); if (server.IsPoolMember) { builder.AppendLine(String.Format(@" {0}   ", GetPoolMemberLink())); } if (server.ProviderPage != null) { builder.AppendLine(String.Format(@" {0}   ", GetProviderLink())); } builder.AppendLine( String.Format( @" View info on support.ntp.org »", server.Id.ToString(CultureInfo.InvariantCulture).PadLeft(6, '0'))); builder.AppendLine(@"

"); return builder.ToString(); } public override string RenderFooter() { StringBuilder builder = new StringBuilder(); builder.AppendLine("
"); builder.AppendLine("
"); return builder.ToString(); } #region Translators private string GetStratumText() { switch (server.Stratum) { case 1: return "one"; case 2: return "two"; case 3: return "three"; case 4: return "four"; case 5: return "five"; case 6: return "six"; case 7: return "seven"; default: return "Unknown"; } } private string GetServerSync() { return server.Server.Trim() != String.Empty ? server.Server : " "; } private string GetServerAccess() { switch (server.AccessPolicy) { case "OpenAccess": return "Open access"; default: return "Unknown"; } } private string GetServiceArea() { string description = server.ServiceArea.Trim(); if (description == String.Empty) return " "; string firstLetter = description.Substring(0, 1); string rest = description.Substring(1); return firstLetter.ToUpper() + rest; } private string GetPoolMemberStatus() { return server.IsPoolMember ? "Server is pool member" : "Server is not a pool member"; } private string GetPoolMemberLink() { if (!server.IsPoolMember) return "Server is not a pool member"; StringBuilder builder = new StringBuilder(); builder.Append(@"View info on pool.ntp.org »"); return builder.ToString(); } private string GetProviderLink() { if (server.ProviderPage == null) return "Not found"; StringBuilder builder = new StringBuilder(); builder.Append(@"View info on "); builder.Append(server.ProviderPage); builder.Append(" »"); return builder.ToString(); } #endregion } }