NTP Analyzer  0.8.2
Analyze the operation of time servers
AboutPageSyntaxNode.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 AboutPageSyntaxNode : SyntaxNode<AboutPageConfiguration>
33  {
34  public AboutPageSyntaxNode(string name, int line)
35  : base(Symbol.KeywordAboutPage, name, line, true)
36  {
37  }
38 
39  private Uri location;
40 
42  {
43  var frequency = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFrequency) as IntegerSettingNode;
44  var initialRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordInitialRun) as BooleanSettingNode;
45  var fixedRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFixedRun) as BooleanSettingNode;
46  var title = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTitle) as StringSettingNode ??
47  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordPageTitle) as StringSettingNode;
48  var serverId = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordServerId) as IntegerSettingNode;
49  var contentTitle = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordContentTitle) as StringSettingNode;
50  var content = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordContent) as StringSettingNode;
51  var pageTemplate = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordPageTemplate) as PageThemeNode;
52  var dest = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordDestinations) as FileDestinationSyntaxNode;
53 
54  return new AboutPageConfiguration(
55  Name,
56  frequency?.Value,
57  initialRun?.Value,
58  fixedRun?.Value,
59  title?.Value,
60  pageTemplate?.PageTheme,
61  serverId?.Value,
62  contentTitle?.Value,
63  content?.Value,
64  location,
65  dest?.Compile()
66  );
67  }
68 
69  protected override void ValidateMandatories()
70  {
71  CheckIsUnique(new List<Symbol>
72  {
73  Symbol.KeywordFrequency,
74  Symbol.KeywordInitialRun,
75  Symbol.KeywordFixedRun,
76  Symbol.KeywordTitle,
77  Symbol.KeywordPageTitle,
78  Symbol.KeywordPageTemplate,
79  Symbol.KeywordContentTitle,
80  Symbol.KeywordContent,
81  Symbol.KeywordServerId,
82  Symbol.KeywordLink
83  });
84 
85  CheckAllIsPresent(new List<Symbol>
86  {
87  Symbol.KeywordDestinations,
88  Symbol.KeywordContentTitle,
89  Symbol.KeywordContent
90  });
91 
92  CheckOnlyOneIsPresent(new List<Symbol>
93  {
94  Symbol.KeywordTitle,
95  Symbol.KeywordPageTitle
96  });
97  }
98 
99  protected override void ValidateReferences(SymbolTable table)
100  {
101  var link = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordLink) as StringSettingNode;
102  if (link == null)
103  return;
104 
105  var keyword = Keyword.Find(Symbol.KeywordLink).Name;
106  location = CheckLink(link.Value, keyword);
107  }
108 
109  protected override void ValidateTypes()
110  {
111  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordFrequency);
112  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordInitialRun);
113  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordFixedRun);
114  CheckTypeIs<PageThemeNode>(Symbol.KeywordPageTemplate);
115  CheckTypeIs<StringSettingNode>(Symbol.KeywordTitle);
116  CheckTypeIs<StringSettingNode>(Symbol.KeywordPageTitle);
117  CheckTypeIs<StringSettingNode>(Symbol.KeywordContentTitle);
118  CheckTypeIs<StringSettingNode>(Symbol.KeywordContent);
119  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordServerId);
120  CheckTypeIs<StringSettingNode>(Symbol.KeywordLink);
121  }
122  }
123 }
override void ValidateMandatories()
Override to validates the mandatory types in this syntax node.
override AboutPageConfiguration InternalCompile()
override void ValidateReferences(SymbolTable table)
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
override void ValidateTypes()
Override to validates the types in this syntax node.