NTP Analyzer  0.8.2
Analyze the operation of time servers
HostLineRender.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System.Text;
24 using Ntp.Analyzer.Objects;
25 using Ntp.Common.Web;
26 
27 namespace Ntp.Analyzer.Render.Host
28 {
29  public sealed class HostLineRender : HtmlObjectRender
30  {
31  public HostLineRender(StatusLine statusLine, PeerPageConfiguration peerPages)
32  : base(peerPages?.WebPath)
33  {
34  this.statusLine = statusLine;
35  this.peerPages = peerPages;
36  }
37 
38  private readonly PeerPageConfiguration peerPages;
39  private readonly StatusLine statusLine;
40 
41  private AssociationEntry Peer => statusLine.Peer;
42 
43  private TimeServer Server => statusLine.PeerActivity.Peer.Server;
44 
45  private string PeerName
46  {
47  get
48  {
49  string name = statusLine.PeerActivity.Peer.Name;
50  return name.Substring(0, name.Length > 18 ? 18 : name.Length);
51  }
52  }
53 
54  private string Country => Server != null ? Server.Country : string.Empty;
55 
56  private string Location => string.IsNullOrEmpty(Server?.DisplayLocation)
57  ? "Unknown"
58  : Server.DisplayLocation;
59 
60  private int PageId => statusLine.PeerActivity.Id;
61 
62  public override string Render()
63  {
64  var builder = new StringBuilder();
65 
66  builder.Append($"<td>{Peer.TallyChar}</td>");
67  builder.Append($"<td>{PeerName}</td>");
68  builder.Append($@"<td class=""aright"">{Peer.Stratus}</td>");
69  builder.Append($@"<td class=""aright"">{Peer.LastPoll}</td>");
70  builder.Append($@"<td class=""aright2"">{Peer.Poll}</td>");
71  builder.Append($@"<td class=""aright"">{Peer.Reach}</td>");
72  builder.Append($@"<td class=""aright"">{Peer.Delay.ToString("0.000")}</td>");
73  builder.Append($@"<td class=""aright"">{Peer.Offset.ToString("0.000")}</td>");
74  builder.Append($@"<td class=""aright"">{Peer.Jitter.ToString("0.000")}</td>");
75  builder.Append($@"<td class=""aright"">{Country}</td>");
76 
77  if (peerPages != null)
78  {
79  builder.Append(@"<td><a href=""");
80  builder.Append(peerPages.GetLink(PageId).ToHtmlString());
81  builder.Append(@""">");
82  builder.Append(Location);
83  builder.AppendLine("</a></td>");
84  }
85  else
86  {
87  builder.Append(@"<td>");
88  builder.Append(Location);
89  builder.AppendLine("</td>");
90  }
91 
92  return builder.ToString();
93  }
94 
95  public override string RenderFooter()
96  {
97  return "</tr>";
98  }
99 
100  public override string RenderHead()
101  {
102  return "<tr>";
103  }
104  }
105 }
HostLineRender(StatusLine statusLine, PeerPageConfiguration peerPages)
A status line for an NTP Server containing information about configuration, peer and server details...
Definition: StatusLine.cs:28
readonly PeerPageConfiguration peerPages
abstract string DisplayLocation
Definition: TimeServer.cs:54
Peer(int id, string name, string ip, TimeServer server)
Definition: Peer.cs:26