NTP Analyzer  0.8.2
Analyze the operation of time servers
PeerSummaryPageSyntaxNode.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;
28 using Ntp.Analyzer.Config.Table;
29 
30 namespace Ntp.Analyzer.Config.Syntax
31 {
32  public sealed class PeerSummaryPageSyntaxNode : SyntaxNode<PeerSummaryPageConfiguration>
33  {
34  public PeerSummaryPageSyntaxNode(string name, int line)
35  : base(Symbol.KeywordPeerSummaryPage, name, line, true)
36  {
37  }
38 
39  private Uri location;
41 
43  {
44  var frequency = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFrequency) as IntegerSettingNode;
45  var initialRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordInitialRun) as BooleanSettingNode;
46  var fixedRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFixedRun) as BooleanSettingNode;
47  var title = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTitle) as StringSettingNode ??
48  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordPageTitle) as StringSettingNode;
49  var pageTemplate = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordPageTemplate) as PageThemeNode;
50  var graphSets = Nodes.Where(n => n.Symbol == Symbol.KeywordGraphSet).Cast<GraphSetSyntaxNode>();
51  var dest = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordDestinations) as FileDestinationSyntaxNode;
52 
54  Name,
55  frequency?.Value,
56  initialRun?.Value,
57  fixedRun?.Value,
58  pageTemplate?.PageTheme,
59  title?.Value,
60  pageNode.Compile(),
61  graphSets.Select(g => g.Compile()),
62  dest?.Compile(),
63  location
64  );
65  }
66 
67  protected override void InternalResolve(SymbolTable table)
68  {
69  var name = Nodes.Single(n => n.Symbol == Symbol.KeywordPeerPage) as StringSettingNode;
70  if (name != null)
71  pageNode = table.Lookup(name.Value) as PeerPageSyntaxNode;
72  }
73 
74  protected override void ValidateMandatories()
75  {
76  CheckIsUnique(new List<Symbol>
77  {
78  Symbol.KeywordFrequency,
79  Symbol.KeywordInitialRun,
80  Symbol.KeywordFixedRun,
81  Symbol.KeywordTitle,
82  Symbol.KeywordPageTitle,
83  Symbol.KeywordLink,
84  Symbol.KeywordPeerPage,
85  Symbol.KeywordPageTemplate,
86  Symbol.KeywordDestinations
87  });
88 
89  CheckOnlyOneIsPresent(new List<Symbol>
90  {
91  Symbol.KeywordTitle,
92  Symbol.KeywordPageTitle
93  });
94 
95  CheckAllIsPresent(new List<Symbol>
96  {
97  Symbol.KeywordPeerPage,
98  Symbol.KeywordGraphSet,
99  Symbol.KeywordDestinations
100  });
101  }
102 
103  protected override void ValidateReferences(SymbolTable table)
104  {
105  var pageName = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordPeerPage) as StringSettingNode;
106  if (pageName != null)
107  {
108  string keyword = Keyword.Find(Symbol.KeywordPeerPage).Name;
109 
110  var reference = table.Lookup(pageName.Value);
111  if (reference == null)
112  {
113  AddReferenceNameError(pageName, keyword, pageName.Value);
114  }
115  else if (!(reference is PeerPageSyntaxNode))
116  {
117  AddReferenceTypeError(pageName, keyword, keyword, pageName.Value);
118  }
119  }
120 
121  var link = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordLink) as StringSettingNode;
122  if (link == null)
123  return;
124 
125  var linkKeyword = Keyword.Find(Symbol.KeywordLink).Name;
126  location = CheckLink(link.Value, linkKeyword);
127  }
128 
129  protected override void ValidateTypes()
130  {
131  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordFrequency);
132  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordInitialRun);
133  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordFixedRun);
134  CheckTypeIs<StringSettingNode>(Symbol.KeywordTitle);
135  CheckTypeIs<StringSettingNode>(Symbol.KeywordPageTitle);
136  CheckTypeIs<StringSettingNode>(Symbol.KeywordPeerPage);
137  CheckTypeIs<StringSettingNode>(Symbol.KeywordLink);
138  CheckTypeIs<PageThemeNode>(Symbol.KeywordPageTemplate);
139  }
140  }
141 }
override void ValidateMandatories()
Override to validates the mandatory types in this syntax node.
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
override void ValidateTypes()
Override to validates the types in this syntax node.
override PeerSummaryPageConfiguration InternalCompile()
ISyntaxNode Lookup(string name)
Definition: SymbolTable.cs:41