NTP Analyzer  0.8.2
Analyze the operation of time servers
TrafficGraphSyntaxNode.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.Collections.Generic;
23 using System.Linq;
27 using Ntp.Analyzer.Config.Table;
28 
29 namespace Ntp.Analyzer.Config.Syntax
30 {
31  public sealed class TrafficGraphSyntaxNode : SyntaxNode<TrafficGraphConfiguration>
32  {
33  public TrafficGraphSyntaxNode(string name, int line)
34  : base(Symbol.KeywordTrafficGraph, name, line, true)
35  {
36  }
37 
39  {
40  var frequency = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFrequency) as IntegerSettingNode;
41  var initialRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordInitialRun) as BooleanSettingNode;
42  var fixedRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFixedRun) as BooleanSettingNode;
43  var title = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTitle) as StringSettingNode;
44  var width = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordWidth) as IntegerSettingNode;
45  var height = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordHeight) as IntegerSettingNode;
46  var timespan = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTimespan) as IntegerSettingNode;
47  var stamp = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTimeStamp) as TimeStampNode ??
48  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphTime) as TimeStampNode;
49  var recv = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphReceived) as NumericSettingNode;
50  var ignore = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphIgnored) as NumericSettingNode;
51  var drop = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphDropped) as NumericSettingNode;
52  var sent = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphSent) as NumericSettingNode;
53  var notSent = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphNotSent) as NumericSettingNode;
54  var avgRecv = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphAvgReceived) as NumericSettingNode;
55  var avgIgnore = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphAvgIgnored) as NumericSettingNode;
56  var avgDrop = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphAvgDropped) as NumericSettingNode;
57  var avgSent = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphAvgSent) as NumericSettingNode;
58  var avgNotSent = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphAvgNotSent) as NumericSettingNode;
59  var interval = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphPlotInterval) as IntegerSettingNode;
60  var rate = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphPacketRate) as IntegerSettingNode;
61  var dest = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordDestinations) as FileDestinationSyntaxNode;
62  var links = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordWebLinks) as WebLinkSyntaxNode;
63 
64  return new TrafficGraphConfiguration(
65  Name,
66  frequency?.Value,
67  initialRun?.Value,
68  fixedRun?.Value,
69  title?.Value,
70  width?.Value,
71  height?.Value,
72  timespan?.Value,
73  stamp?.DateTimeKind,
74  recv?.Value,
75  ignore?.Value,
76  drop?.Value,
77  sent?.Value,
78  notSent?.Value,
79  avgRecv?.Value,
80  avgIgnore?.Value,
81  avgDrop?.Value,
82  avgSent?.Value,
83  avgNotSent?.Value,
84  interval?.Value,
85  rate?.Value,
86  dest?.Compile(),
87  links?.Compile()
88  );
89  }
90 
91  protected override void ValidateMandatories()
92  {
93  CheckIsUnique(new List<Symbol>
94  {
95  Symbol.KeywordFrequency,
96  Symbol.KeywordInitialRun,
97  Symbol.KeywordFixedRun,
98  Symbol.KeywordTitle,
99  Symbol.KeywordWidth,
100  Symbol.KeywordHeight,
101  Symbol.KeywordTimespan,
102  Symbol.KeywordTimeStamp,
103  Symbol.KeywordGraphTime,
104  Symbol.KeywordGraphReceived,
105  Symbol.KeywordGraphIgnored,
106  Symbol.KeywordGraphDropped,
107  Symbol.KeywordGraphSent,
108  Symbol.KeywordGraphNotSent,
109  Symbol.KeywordGraphAvgReceived,
110  Symbol.KeywordGraphAvgIgnored,
111  Symbol.KeywordGraphAvgDropped,
112  Symbol.KeywordGraphAvgSent,
113  Symbol.KeywordGraphAvgNotSent,
114  Symbol.KeywordGraphPlotInterval,
115  Symbol.KeywordGraphPacketRate,
116  Symbol.KeywordDestinations,
117  Symbol.KeywordWebLinks
118  });
119 
120  CheckAllIsPresent(new List<Symbol>
121  {
122  Symbol.KeywordTitle,
123  Symbol.KeywordDestinations
124  });
125 
126  CheckOneIsPresent(new List<Symbol>
127  {
128  Symbol.KeywordGraphReceived,
129  Symbol.KeywordGraphIgnored,
130  Symbol.KeywordGraphDropped,
131  Symbol.KeywordGraphSent,
132  Symbol.KeywordGraphNotSent,
133  Symbol.KeywordGraphAvgReceived,
134  Symbol.KeywordGraphAvgIgnored,
135  Symbol.KeywordGraphAvgDropped,
136  Symbol.KeywordGraphAvgSent,
137  Symbol.KeywordGraphAvgNotSent,
138  Symbol.KeywordGraphPlotInterval,
139  Symbol.KeywordGraphPacketRate
140  });
141 
142  CheckOnlyOneIsPresent(new List<Symbol>
143  {
144  Symbol.KeywordGraphTime,
145  Symbol.KeywordTimeStamp
146  });
147  }
148 
149  protected override void ValidateTypes()
150  {
151  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordFrequency);
152  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordInitialRun);
153  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordFixedRun);
154  CheckTypeIs<StringSettingNode>(Symbol.KeywordTitle);
155  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordWidth);
156  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordHeight);
157  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordTimespan);
158  CheckTypeIs<TimeStampNode>(Symbol.KeywordGraphTime);
159  CheckTypeIs<TimeStampNode>(Symbol.KeywordTimeStamp);
160  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphReceived);
161  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphIgnored);
162  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphDropped);
163  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphSent);
164  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphNotSent);
165  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphAvgReceived);
166  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphAvgIgnored);
167  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphAvgDropped);
168  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphAvgSent);
169  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphAvgNotSent);
170  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphPlotInterval);
171  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphPacketRate);
172  }
173  }
174 }
override TrafficGraphConfiguration InternalCompile()
Traffic graph configuration used when creating Analyzer.Graph.TrafficGraph.
override void ValidateMandatories()
Override to validates the mandatory types in this syntax node.
override void ValidateTypes()
Override to validates the types in this syntax node.