// // HostLineHtmlRender.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.Text; using Ntp.Analyzer.Config.Page; using Ntp.Analyzer.Objects.Live; using Ntp.Analyzer.Objects; namespace Ntp.Analyzer.Render.Host { public sealed class HostLineRender : HtmlObjectRender { private readonly PeerPageConfiguration peerPages; private readonly StatusLine statusLine; public HostLineRender(StatusLine statusLine, PeerPageConfiguration peerPages) : base(peerPages.WebPath) { this.statusLine = statusLine; this.peerPages = peerPages; } private AssociationEntry Peer { get { return statusLine.Peer; } } private NtpConfEntry Conf { get { return statusLine.Conf; } } private TimeServer Server { get { return statusLine.Server; } } public override string RenderHead() { return ""; } public override string Render() { StringBuilder builder = new StringBuilder(); string name = Conf.Name.Substring(0, Conf.Name.Length > 18 ? 18 : Conf.Name.Length); string country = (Server != null ? Server.Country : String.Empty); string location = (Server != null ? Server.DisplayLocation : "Unknown"); builder.Append("" + Peer.TallyChar + ""); builder.Append("" + name + ""); builder.Append(@"" + Peer.Stratus + ""); builder.Append(@"" + Peer.LastPoll + ""); builder.Append(@"" + Peer.Poll + ""); builder.Append(@"" + Peer.Reach + ""); builder.Append(@"" + Peer.Delay.ToString("0.000") + ""); builder.Append(@"" + Peer.Offset.ToString("0.000") + ""); builder.Append(@"" + Peer.Jitter.ToString("0.000") + ""); builder.Append(@"" + country + ""); builder.Append(@""); builder.Append(location); builder.AppendLine(""); return builder.ToString(); } public override string RenderFooter() { return ""; } } }