NTP Analyzer  0.8.2
Analyze the operation of time servers
PeerGraphSyntaxNode.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 PeerGraphSyntaxNode : SyntaxNode<PeerGraphConfiguration>
32  {
33  public PeerGraphSyntaxNode(string name, int line)
34  : base(Symbol.KeywordPeerGraph, 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 filter = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFilterFactor) as NumericSettingNode;
50  var jitter = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordJitter) as NumericSettingNode;
51  var offset = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordOffset) as NumericSettingNode;
52  var balance = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphBalance) as NumericSettingNode;
53  var delay = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphDelay) as NumericSettingNode;
54  var dest = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordDestinations) as DirDestinationSyntaxNode;
55  var links = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordWebLinks) as WebLinkSyntaxNode;
56 
57  return new PeerGraphConfiguration(
58  Name,
59  frequency?.Value,
60  initialRun?.Value,
61  fixedRun?.Value,
62  title?.Value,
63  width?.Value,
64  height?.Value,
65  timespan?.Value,
66  stamp?.DateTimeKind,
67  filter?.Value,
68  balance?.Value,
69  delay?.Value,
70  jitter?.Value,
71  offset?.Value,
72  dest?.Compile(),
73  links?.Compile()
74  );
75  }
76 
77  protected override void ValidateMandatories()
78  {
79  CheckIsUnique(new List<Symbol>
80  {
81  Symbol.KeywordFrequency,
82  Symbol.KeywordInitialRun,
83  Symbol.KeywordFixedRun,
84  Symbol.KeywordTitle,
85  Symbol.KeywordWidth,
86  Symbol.KeywordHeight,
87  Symbol.KeywordTimespan,
88  Symbol.KeywordTimeStamp,
89  Symbol.KeywordGraphTime,
90  Symbol.KeywordFilterFactor,
91  Symbol.KeywordGraphBalance,
92  Symbol.KeywordGraphDelay,
93  Symbol.KeywordJitter,
94  Symbol.KeywordOffset,
95  Symbol.KeywordDestinations,
96  Symbol.KeywordWebLinks
97  });
98 
99  CheckAllIsPresent(new List<Symbol>
100  {
101  Symbol.KeywordTitle,
102  Symbol.KeywordDestinations
103  });
104 
105  CheckOneIsPresent(new List<Symbol>
106  {
107  Symbol.KeywordGraphBalance,
108  Symbol.KeywordGraphDelay,
109  Symbol.KeywordJitter,
110  Symbol.KeywordOffset
111  });
112 
113  CheckOnlyOneIsPresent(new List<Symbol>
114  {
115  Symbol.KeywordGraphTime,
116  Symbol.KeywordTimeStamp
117  });
118  }
119 
120  protected override void ValidateTypes()
121  {
122  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordFrequency);
123  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordInitialRun);
124  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordFixedRun);
125  CheckTypeIs<StringSettingNode>(Symbol.KeywordTitle);
126  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordWidth);
127  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordHeight);
128  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordTimespan);
129  CheckTypeIs<TimeStampNode>(Symbol.KeywordGraphTime);
130  CheckTypeIs<TimeStampNode>(Symbol.KeywordTimeStamp);
131  CheckTypeIs<NumericSettingNode>(Symbol.KeywordFilterFactor);
132  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphBalance);
133  CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphDelay);
134  CheckTypeIs<NumericSettingNode>(Symbol.KeywordJitter);
135  CheckTypeIs<NumericSettingNode>(Symbol.KeywordOffset);
136  }
137  }
138 }
override void ValidateTypes()
Override to validates the types in this syntax node.
override PeerGraphConfiguration InternalCompile()
override void ValidateMandatories()
Override to validates the mandatory types in this syntax node.
Peer graph configuration used when creating Ntp.Analyzer.Graph.PeerGraph.