NTP Analyzer  0.8.2
Analyze the operation of time servers
BootstrapHostGraphRender.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;
23 using System.Collections.Generic;
24 using System.Linq;
25 using System.Text;
28 using Ntp.Common.Web;
29 
30 namespace Ntp.Analyzer.Render.Host
31 {
33  {
35  Uri webPath,
37  IEnumerable<GraphSetConfiguration> graphs)
38  : base(webPath)
39  {
40  this.page = page;
41  this.graphs = new List<GraphSetConfiguration>(graphs);
42  }
43 
44  private readonly List<GraphSetConfiguration> graphs;
45  private readonly HostPageConfiguration page;
46 
47  public override string Render()
48  {
49  var builder = new StringBuilder();
50  int count = 1;
51 
52  foreach (var graphSet in graphs)
53  {
54  //string open = (count == 1) ? " in" : String.Empty;
55  string open = string.Empty;
56 
57  builder.AppendLine(@" <div class=""panel panel-default"">");
58  builder.AppendLine(@" <div class=""panel-heading"">");
59  builder.AppendLine(@" <h4 class=""panel-title"">");
60 
61  // Include panel counter
62  builder.Append(@" <a class=""accordion-toggle"" data-toggle=""collapse"" ");
63  builder.Append(@"data-parent=""#accordion"" href=""#collapse");
64  builder.Append(count);
65  builder.AppendLine(@""">");
66 
67  builder.AppendLine($@" {graphSet.Title}");
68  builder.AppendLine(@" </a>");
69  builder.AppendLine(@" </h4>");
70  builder.AppendLine(@" </div>");
71 
72  builder.Append(@" <div id=""collapse");
73  builder.Append(count);
74  builder.Append($@""" class=""panel-collapse collapse{open}"">");
75  builder.AppendLine();
76  builder.AppendLine(@" <div class=""panel-body"">");
77 
78  foreach (var graph in graphSet.Graphs)
79  {
80  builder.Append(@" <div class=""container theme-graph2"">");
81 
82  if (page.GraphPages.Count() != 0)
83  {
84  builder.Append(@"<a href=""");
85  builder.Append(page.GraphPages.First().GetLink(graphSet, graph).ToHtmlString());
86  builder.Append(@""">");
87  }
88 
89  builder.Append(@"<img class=""img-responsive"" src=""");
90  builder.Append(graph.GetLink(graphSet).ToHtmlString());
91  builder.Append(@""" alt=""");
92  builder.Append(graph.GetAltName(graphSet));
93  builder.Append(@""">");
94 
95  if (page.GraphPages.Count() != 0)
96  {
97  builder.Append(@"</a>");
98  }
99 
100  builder.AppendLine(@"</div>");
101  }
102 
103  builder.AppendLine(@" </div>");
104  builder.AppendLine(@" </div>");
105  builder.AppendLine(@" </div>");
106 
107  count++;
108  }
109 
110  return builder.ToString();
111  }
112 
113  public override string RenderFooter()
114  {
115  var builder = new StringBuilder();
116 
117  builder.AppendLine(@" </div>");
118  builder.AppendLine(@" </div>");
119 
120  return builder.ToString();
121  }
122 
123  public override string RenderHead()
124  {
125  var builder = new StringBuilder();
126 
127  builder.AppendLine(@" <div class=""container theme-graph"">");
128  builder.AppendLine(@" <div class=""panel-group"" id=""accordion"">");
129 
130  return builder.ToString();
131  }
132  }
133 }
BootstrapHostGraphRender(Uri webPath, HostPageConfiguration page, IEnumerable< GraphSetConfiguration > graphs)
Configuration for a HTML page showing status and graphs for a hosted NTP server.