NTP Analyzer  0.8.2
Analyze the operation of time servers
NotifySyntaxNode.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;
24 using Ntp.Analyzer.Config.Node;
26 using Ntp.Analyzer.Config.Table;
27 
28 namespace Ntp.Analyzer.Config.Syntax
29 {
30  public sealed class NotifySyntaxNode : SyntaxNode<NotifyConfiguration>
31  {
32  public NotifySyntaxNode(string name, int line)
33  : base(Symbol.KeywordNotify, name, line)
34  {
35  }
36 
37  protected override NotifyConfiguration InternalCompile()
38  {
39  var frequency = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFrequency) as IntegerSettingNode;
40  var initialRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordInitialRun) as BooleanSettingNode;
41  var fixedRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFixedRun) as BooleanSettingNode;
42  var user = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordUser) as StringSettingNode ??
43  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordSmtpUser) as StringSettingNode;
44  var pass = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordPass) as StringSettingNode ??
45  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordSmtpPass) as StringSettingNode;
46  var host = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordIp) as StringSettingNode ??
47  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordHost) as StringSettingNode ??
48  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordHostAddress) as StringSettingNode ??
49  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordSmtpHost) as StringSettingNode ??
50  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordAddress) as StringSettingNode;
51  var port = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordPort) as IntegerSettingNode ??
52  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordSmtpPort) as IntegerSettingNode;
53  var ssl = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordEnableSsl) as BooleanSettingNode;
54  var sender = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordSender) as StringSettingNode;
55  var recipient = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordRecipient) as StringSettingNode ??
56  Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordMail) as StringSettingNode;
57  var subject = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordSubject) as StringSettingNode;
58 
59  return new NotifyConfiguration(
60  Name,
61  initialRun?.Value,
62  fixedRun?.Value,
63  frequency?.Value,
64  recipient?.Value,
65  subject?.Value,
66  sender?.Value,
67  host?.Value,
68  port?.Value,
69  user?.Value,
70  pass?.Value,
71  ssl?.Value
72  );
73  }
74 
75  protected override void ValidateMandatories()
76  {
77  CheckIsUnique(new List<Symbol>
78  {
79  Symbol.KeywordFrequency,
80  Symbol.KeywordInitialRun,
81  Symbol.KeywordFixedRun,
82  Symbol.KeywordUser,
83  Symbol.KeywordSmtpUser,
84  Symbol.KeywordPass,
85  Symbol.KeywordSmtpPass,
86  Symbol.KeywordIp,
87  Symbol.KeywordHost,
88  Symbol.KeywordAddress,
89  Symbol.KeywordHostAddress,
90  Symbol.KeywordSmtpHost,
91  Symbol.KeywordPort,
92  Symbol.KeywordSmtpPort,
93  Symbol.KeywordEnableSsl,
94  Symbol.KeywordSender,
95  Symbol.KeywordMail,
96  Symbol.KeywordRecipient,
97  Symbol.KeywordSubject
98  });
99 
100  CheckOnlyOneIsPresent(new List<Symbol>
101  {
102  Symbol.KeywordRecipient,
103  Symbol.KeywordMail
104  });
105 
106  CheckOnlyOneIsPresent(new List<Symbol>
107  {
108  Symbol.KeywordIp,
109  Symbol.KeywordHost,
110  Symbol.KeywordAddress,
111  Symbol.KeywordHostAddress,
112  Symbol.KeywordSmtpHost
113  });
114 
115  CheckOnlyOneIsPresent(new List<Symbol>
116  {
117  Symbol.KeywordSmtpPort,
118  Symbol.KeywordPort
119  });
120 
121  CheckOnlyOneIsPresent(new List<Symbol>
122  {
123  Symbol.KeywordSmtpUser,
124  Symbol.KeywordUser
125  });
126 
127  CheckOnlyOneIsPresent(new List<Symbol>
128  {
129  Symbol.KeywordSmtpPass,
130  Symbol.KeywordPass
131  });
132 
133  CheckAllIsPresent(new List<Symbol>
134  {
135  Symbol.KeywordSender,
136  Symbol.KeywordSubject
137  });
138 
139  CheckOneIsPresent(new List<Symbol>
140  {
141  Symbol.KeywordRecipient,
142  Symbol.KeywordMail
143  });
144 
145  CheckOneIsPresent(new List<Symbol>
146  {
147  Symbol.KeywordIp,
148  Symbol.KeywordHost,
149  Symbol.KeywordAddress,
150  Symbol.KeywordSmtpHost
151  });
152  }
153 
154  protected override void ValidateTypes()
155  {
156  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordFrequency);
157  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordInitialRun);
158  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordFixedRun);
159  CheckTypeIs<StringSettingNode>(Symbol.KeywordUser);
160  CheckTypeIs<StringSettingNode>(Symbol.KeywordPass);
161  CheckTypeIs<StringSettingNode>(Symbol.KeywordSmtpUser);
162  CheckTypeIs<StringSettingNode>(Symbol.KeywordSmtpPass);
163  CheckTypeIs<StringSettingNode>(Symbol.KeywordIp);
164  CheckTypeIs<StringSettingNode>(Symbol.KeywordHost);
165  CheckTypeIs<StringSettingNode>(Symbol.KeywordAddress);
166  CheckTypeIs<StringSettingNode>(Symbol.KeywordSmtpHost);
167  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordPort);
168  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordSmtpPort);
169  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordEnableSsl);
170  CheckTypeIs<StringSettingNode>(Symbol.KeywordSender);
171  CheckTypeIs<StringSettingNode>(Symbol.KeywordRecipient);
172  CheckTypeIs<StringSettingNode>(Symbol.KeywordSubject);
173  }
174  }
175 }
override void ValidateTypes()
Override to validates the types in this syntax node.
override NotifyConfiguration InternalCompile()
override void ValidateMandatories()
Override to validates the mandatory types in this syntax node.