NTP Analyzer  0.8.2
Analyze the operation of time servers
BootstrapSummaryGraphRender.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.Analyzer.Data;
29 using Ntp.Common.Web;
30 
31 namespace Ntp.Analyzer.Render.Summary
32 {
34  {
36  Uri webPath,
37  int hostId,
39  IEnumerable<GraphSetConfiguration> graphs)
40  : base(webPath)
41  {
42  this.hostId = hostId;
43  this.page = page;
44  this.graphs = new List<GraphSetConfiguration>(graphs);
45  }
46 
47  private readonly List<GraphSetConfiguration> graphs;
48  private readonly int hostId;
50 
51  public override string Render()
52  {
53  var builder = new StringBuilder();
54  int count = 1;
55 
56  foreach (var graphSet in graphs)
57  {
58  string open = count == 1 ? " in" : string.Empty;
59 
60  builder.AppendLine(@" <div class=""panel panel-default"">");
61  builder.AppendLine(@" <div class=""panel-heading"">");
62  builder.AppendLine(@" <h4 class=""panel-title"">");
63 
64  // Include panel counter
65  builder.Append(@" <a class=""accordion-toggle"" data-toggle=""collapse"" ");
66  builder.Append(@"data-parent=""#accordion"" href=""#collapse");
67  builder.Append(count);
68  builder.AppendLine(@""">");
69 
70  builder.AppendLine(@" " + graphSet.Title);
71  builder.AppendLine(@" </a>");
72  builder.AppendLine(@" </h4>");
73  builder.AppendLine(@" </div>");
74 
75  // Include panel counter
76  builder.Append(@" <div id=""collapse");
77  builder.Append(count);
78  builder.Append($@""" class=""panel-collapse collapse{open}"">");
79  builder.AppendLine();
80  builder.AppendLine(@" <div class=""panel-body"">");
81 
82 
83  var peers = DataFace.Instance.PeerActivities.
84  Where(p => p.Host.Id == hostId && p.IsActive);
85 
86  foreach (var entry in peers)
87  {
88  foreach (var graph in graphSet.Graphs)
89  {
90  builder.Append(@" <div class=""container theme-graph2"">");
91  builder.Append(@"<a href=""");
92  builder.Append(page.GetPeerLink(entry.Id).ToHtmlString());
93  builder.Append(@""">");
94  builder.Append(@"<img class=""img-responsive"" src=""");
95  builder.Append(graph.GetLink(graphSet, entry.Name).ToHtmlString());
96  builder.Append(@""" alt=""");
97  builder.Append(graph.GetAltName(graphSet, entry.Name));
98  builder.Append(@""">");
99  builder.AppendLine(@"</a></div>");
100  }
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 }
BootstrapSummaryGraphRender(Uri webPath, int hostId, PeerSummaryPageConfiguration page, IEnumerable< GraphSetConfiguration > graphs)
Singleton facade class used to access memory persistent data.
Definition: DataFace.cs:30
PeerActivityDatabaseMapper PeerActivities
Gets the peer activity mapper.
Definition: DataFace.cs:99
static DataFace Instance
Gets the Singleton instance.
Definition: DataFace.cs:51