// // HostPageConfiguration.cs // // Author: // Carsten Sonne Larsen // // Copyright (c) 2013 Carsten Sonne Larsen // // 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; using System.Collections.Generic; using System.Linq; using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Navigation; using Ntp.Analyzer.Config.Page.Collection; using Ntp.Config; namespace Ntp.Analyzer.Config.Page { /// /// Configuration for a HTML page showing status and graphs for an hosted NTP server. /// public sealed class HostPageConfiguration : PageConfigurationBase, ILinkable { private HostPageConfiguration ( ServerConfiguration server, string configName, int indentLevel, int frequency, bool initialRun, bool fixedRun, string theme, string title, bool poolMember, PeerPageConfiguration peerPage, IEnumerable graphs, SummeryCollection summeries, FileCollection destinations, string link) : base( server, configName, indentLevel, frequency, initialRun, fixedRun, theme, title, destinations, link) { this.poolMember = poolMember; this.peerPage = peerPage; this.graphs = new List (graphs); this.summeries = summeries; graphPages = new List (); } /// /// The parameters used in configuration files. /// private static readonly String[] Params = new[] { "HostPage", "Frequency", "InitialRun", "FixedRun", "Template", "PageTitle", "PoolMember", "PeerPages", GraphSetConfiguration.Identifier, SummeryCollection.Identifier, FileCollection.Identifier, "Link" }; private readonly List graphPages; private readonly List graphs; private readonly PeerPageConfiguration peerPage; private readonly bool poolMember; private readonly SummeryCollection summeries; /// /// Gets a value indicating whether there should be shown a link to pool.ntp.org. /// /// /// true if pool member; otherwise, false. /// public bool PoolMember { get { return poolMember; } } /// /// Gets the peer pages linked to this page. /// /// The peer page. public PeerPageConfiguration PeerPage { get { return peerPage; } } /// /// Gets the graphs to be displayed on this page. /// /// The host graphs. public IEnumerable Graphs { get { return graphs; } } /// /// Gets the peer summeries to be linked from this page. /// /// The peer summeries. public SummeryCollection PeerSummeries { get { return summeries; } } /// /// Gets the host graph pages to be linked from this page. /// /// The host graph pages. public IEnumerable GraphPages { get { return graphPages; } } /// /// Gets the values of settings in this configuration. /// /// The items. protected override IEnumerable Items { get { return new object[] { ConfigName, Frequency, InitialRun ? 1 : 0, FixedRun ? 1 : 0, Theme, Title, PoolMember ? 1 : 0, PeerPage.ConfigName, Graphs, PeerSummeries, Destinations, Link }; } } /// /// Attachs the host graph pages to this page. /// /// /// Only use from /// /// Page. internal void AttachGraphPages (HostGraphPageConfiguration page) { graphPages.Add (page); } /// /// Returns a that represents the current /// /// . /// /// /// A that represents the current . /// public override string ToString () { return ConfigText (Params, Items); } /// /// Factory method. /// /// Server. /// Config. /// Peer pages. /// Host graphs. /// Peer summeries. public static HostPageConfiguration Create ( ServerConfiguration server, ConfigurationBlock config, IEnumerable peerPages, IEnumerable hostGraphs, IEnumerable peerSummeries) { OptionSet options = GetOptions (Params, config); string peerPageName = GetOptionString (options, Params [7], Params [0], false); PeerPageConfiguration peerPage = null; if (peerPageName != String.Empty) { peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName); if (peerPage == null) { ConfigError ("Cannot find PeerPages " + peerPageName + " specified in HostPage"); } } return new HostPageConfiguration ( server, GetOptionConfigName (options, Params [0], Params [0], true), config.IndentLevel, GetOptionInteger (options, Params [1], Params [0], true), GetOptionBoolean (options, Params [2], Params [0], false, true), GetOptionBoolean (options, Params [3], Params [0], false, true), GetOptionString (options, Params [4], Params [0], false, "default"), GetOptionString (options, Params [5], Params [0], false, String.Empty), GetOptionBoolean (options, Params [6], Params [0], false), peerPage, GraphSetConfiguration.Create (server, hostGraphs, config, Params [0]), SummeryCollection.Create (server, peerSummeries, config, Params [0]), FileCollection.Create (server, config), GetOptionString (options, Params [11], Params [0], false, String.Empty) ); } } }