// // PeerInfoHtmlRender.cs // // Author: // Carsten Sonne Larsen // // Copyright (c) 2013-2016 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 DefaultPeerInfoRender : HtmlObjectRender { private readonly TimeServer server; public DefaultPeerInfoRender(string webPath, TimeServer server, string name) : base(webPath) { this.server = server; this.name = name; } private const string na = " "; private readonly string name; public override string RenderHead() { StringBuilder builder = new StringBuilder(); builder.Append("

"); builder.Append(server != null ? server.Name : name); builder.Append("

    

Stratum "); builder.Append(server != null ? GetStratumText() : na); builder.AppendLine(" server

"); return builder.ToString(); } public override string Render() { StringBuilder builder = new StringBuilder(); builder.AppendLine(""); builder.AppendLine(@""); builder.AppendLine(""); builder.AppendLine(""); builder.Append(@" "); builder.AppendLine(""); builder.AppendLine(""); builder.Append(@" "); builder.AppendLine(""); builder.AppendLine(""); builder.Append(" "); builder.Append(" "); builder.AppendLine(""); builder.AppendLine(""); builder.Append(" "); builder.Append(" "); builder.AppendLine(""); builder.AppendLine(""); builder.Append(@" "); builder.Append(" "); builder.AppendLine(""); builder.AppendLine(""); builder.Append(""); if (server != null && server.Id <= 10000) { builder.Append (@" "); } else { builder.Append (@" "); } builder.AppendLine(""); builder.AppendLine(""); builder.AppendLine("
Server location"); builder.Append(server != null ? server.Location : na); builder.AppendLine("
Synchronization"); builder.Append(server != null ? server.Server : na); builder.AppendLine("
IP address"); builder.Append(server != null && server.Address != null ? server.Address.ToString() : String.Empty); builder.AppendLine("Access policy"); builder.Append(server != null ? GetServerAccess() : na); builder.AppendLine("
IPv6 address"); builder.Append(server != null ? server.V6Address ?? "N/A" : na); builder.AppendLine("Service area"); builder.Append(server != null ? GetServiceArea() : na); builder.AppendLine("
Pool member info"); builder.Append(server != null ? GetPoolMemberLink() : na); builder.AppendLine("Provider page"); builder.Append(server != null ? GetProviderLink() : na); builder.AppendLine("
Description updated"); builder.Append(server != null ? server.Updated.ToLongDateString() : na); builder.AppendLine("Additional infosupport.ntp.orgAdditional info" + na + "
"); return builder.ToString(); } public override string RenderFooter() { return String.Empty; } #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 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.Empty; string firstLetter = description.Substring(0, 1); string rest = description.Substring(1); return firstLetter.ToUpper() + rest; } private string GetPoolMemberLink() { if (!server.IsPoolMember) return "Server is not a pool member"; StringBuilder builder = new StringBuilder(); builder.Append(@"pool.ntp.org"); return builder.ToString(); } private string GetProviderLink() { if (server.ProviderPage == null) return "Not found"; StringBuilder builder = new StringBuilder(); builder.Append(@""); builder.Append(server.ProviderPage); builder.Append(""); return builder.ToString(); } #endregion } }