Files

138 lines
6.3 KiB
C#
Raw Permalink Normal View History

2016-08-06 16:19:35 +02:00
//
2017-07-13 22:32:11 +02:00
// Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
2016-08-06 16:19:35 +02:00
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Collections.Generic;
using System.Linq;
using Ntp.Analyzer.Config.Node.Graph;
2016-09-04 23:43:39 +02:00
using Ntp.Analyzer.Config.Syntax.Option;
2016-08-06 16:19:35 +02:00
using Ntp.Analyzer.Config.Syntax.Setting;
using Ntp.Analyzer.Config.Table;
namespace Ntp.Analyzer.Config.Syntax
{
public sealed class PeerGraphSyntaxNode : SyntaxNode<PeerGraphConfiguration>
{
public PeerGraphSyntaxNode(string name, int line)
: base(Symbol.KeywordPeerGraph, name, line, true)
{
}
2016-08-18 19:18:52 +02:00
protected override PeerGraphConfiguration InternalCompile()
{
var frequency = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFrequency) as IntegerSettingNode;
var initialRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordInitialRun) as BooleanSettingNode;
var fixedRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFixedRun) as BooleanSettingNode;
var title = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTitle) as StringSettingNode;
var width = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordWidth) as IntegerSettingNode;
var height = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordHeight) as IntegerSettingNode;
var timespan = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTimespan) as IntegerSettingNode;
2016-09-08 21:29:33 +02:00
var stamp = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordTimeStamp) as TimeStampNode ??
Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphTime) as TimeStampNode;
2016-08-18 19:18:52 +02:00
var filter = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFilterFactor) as NumericSettingNode;
var jitter = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordJitter) as NumericSettingNode;
var offset = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordOffset) as NumericSettingNode;
var balance = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphBalance) as NumericSettingNode;
var delay = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphDelay) as NumericSettingNode;
var dest = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordDestinations) as DirDestinationSyntaxNode;
var links = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordWebLinks) as WebLinkSyntaxNode;
return new PeerGraphConfiguration(
Name,
frequency?.Value,
initialRun?.Value,
fixedRun?.Value,
title?.Value,
width?.Value,
height?.Value,
timespan?.Value,
2016-09-04 23:43:39 +02:00
stamp?.DateTimeKind,
2016-08-18 19:18:52 +02:00
filter?.Value,
balance?.Value,
delay?.Value,
jitter?.Value,
offset?.Value,
dest?.Compile(),
links?.Compile()
);
}
2016-08-06 16:19:35 +02:00
protected override void ValidateMandatories()
{
CheckIsUnique(new List<Symbol>
{
Symbol.KeywordFrequency,
Symbol.KeywordInitialRun,
Symbol.KeywordFixedRun,
Symbol.KeywordTitle,
Symbol.KeywordWidth,
Symbol.KeywordHeight,
Symbol.KeywordTimespan,
2016-09-04 23:43:39 +02:00
Symbol.KeywordTimeStamp,
2016-09-08 21:29:33 +02:00
Symbol.KeywordGraphTime,
2016-08-06 16:19:35 +02:00
Symbol.KeywordFilterFactor,
Symbol.KeywordGraphBalance,
Symbol.KeywordGraphDelay,
Symbol.KeywordJitter,
Symbol.KeywordOffset,
Symbol.KeywordDestinations,
Symbol.KeywordWebLinks
});
CheckAllIsPresent(new List<Symbol>
{
Symbol.KeywordTitle,
Symbol.KeywordDestinations
});
CheckOneIsPresent(new List<Symbol>
{
Symbol.KeywordGraphBalance,
Symbol.KeywordGraphDelay,
Symbol.KeywordJitter,
Symbol.KeywordOffset
});
2016-09-08 21:29:33 +02:00
CheckOnlyOneIsPresent(new List<Symbol>
{
Symbol.KeywordGraphTime,
Symbol.KeywordTimeStamp
});
2016-08-06 16:19:35 +02:00
}
protected override void ValidateTypes()
{
CheckTypeIs<IntegerSettingNode>(Symbol.KeywordFrequency);
CheckTypeIs<BooleanSettingNode>(Symbol.KeywordInitialRun);
CheckTypeIs<BooleanSettingNode>(Symbol.KeywordFixedRun);
CheckTypeIs<StringSettingNode>(Symbol.KeywordTitle);
CheckTypeIs<IntegerSettingNode>(Symbol.KeywordWidth);
CheckTypeIs<IntegerSettingNode>(Symbol.KeywordHeight);
CheckTypeIs<IntegerSettingNode>(Symbol.KeywordTimespan);
2016-09-08 21:29:33 +02:00
CheckTypeIs<TimeStampNode>(Symbol.KeywordGraphTime);
2016-09-04 23:43:39 +02:00
CheckTypeIs<TimeStampNode>(Symbol.KeywordTimeStamp);
2016-08-06 16:19:35 +02:00
CheckTypeIs<NumericSettingNode>(Symbol.KeywordFilterFactor);
CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphBalance);
CheckTypeIs<NumericSettingNode>(Symbol.KeywordGraphDelay);
CheckTypeIs<NumericSettingNode>(Symbol.KeywordJitter);
CheckTypeIs<NumericSettingNode>(Symbol.KeywordOffset);
}
}
}