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.Collections.Generic; 23 using System.Text; 24 using Ntp.Analyzer.Config.Node.Page; 25 using Ntp.Analyzer.Import; 26 27 namespace Ntp.Analyzer.Render.Host 28 { 29 public sealed class DefaultHostTableRender : HtmlObjectRender 30 { DefaultHostTableRender(HostPageConfiguration page)31 public DefaultHostTableRender(HostPageConfiguration page) 32 : base(page.WebPath) 33 { 34 columns = new List<string> 35 { 36 " ", 37 "Name", 38 "st", 39 "when", 40 "poll", 41 page.ServerType == ServerType.Ntpctl ? "trust" : "reach", 42 " delay", 43 "offset", 44 "jitter", 45 "iso ", 46 "location" 47 }.ToArray(); 48 } 49 50 private readonly string[] columns; 51 Render()52 public override string Render() 53 { 54 return string.Empty; 55 } 56 RenderFooter()57 public override string RenderFooter() 58 { 59 var builder = new StringBuilder(); 60 61 builder.Append(MakeSpacer()); 62 builder.Append("<tr>"); 63 64 for (int index = 0; index < columns.Length; index++) 65 { 66 builder.Append(@"<td class=""but""> </td>"); 67 } 68 69 builder.AppendLine("</tr>"); 70 builder.AppendLine("</table>"); 71 72 return builder.ToString(); 73 } 74 RenderHead()75 public override string RenderHead() 76 { 77 var builder = new StringBuilder(); 78 79 builder.Append("<table><tr>"); 80 81 foreach (string column in columns) 82 { 83 builder.Append("<th>"); 84 builder.Append(column); 85 builder.Append("</th>"); 86 } 87 88 builder.AppendLine("</tr>"); 89 builder.Append(MakeSpacer()); 90 91 return builder.ToString(); 92 } 93 MakeSpacer()94 private string MakeSpacer() 95 { 96 var builder = new StringBuilder(); 97 98 builder.Append("<tr>"); 99 100 for (int index = 0; index < columns.Length; index++) 101 { 102 builder.Append(@"<td class=""spc""> </td>"); 103 } 104 105 builder.AppendLine("</tr>"); 106 107 return builder.ToString(); 108 } 109 } 110 }