Files
ntpa/Ntp.Analyzer/Config/Page/HostGraphPageConfiguration.cs
T
2016-03-05 15:25:01 +01:00

144 lines
5.0 KiB
C#

//
// HostGrapPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2014 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.Config;
namespace Ntp.Analyzer.Config.Page
{
public sealed class HostGraphPageConfiguration : GraphPageConfiguration
{
public HostGraphPageConfiguration (
ServerConfiguration server,
string configName,
int indentLevel,
string theme,
string title,
HostPageConfiguration page,
int linkIndex,
DestinationCollection destinations,
string link)
: base (
server,
configName,
indentLevel,
theme,
title,
linkIndex,
destinations,
link)
{
this.page = page;
page.AttachGraphPages (this);
}
private static readonly String[] Params = new[] {
"HostGraphPage",
"Template",
"PageTitle",
"GraphPage",
"LinkIndex",
DirectoryCollection.Identifier,
"Link"
};
private readonly HostPageConfiguration page;
public override IEnumerable<GraphSetConfiguration> GraphSets {
get { return page.Graphs; }
}
protected override IEnumerable<Object> Items {
get {
return new object[] {
ConfigName,
Theme,
Title,
page != null ? page.ConfigName : null,
LinkIndex,
Destinations,
Link
};
}
}
public string GetFileName (GraphSetConfiguration graphSet, GraphBaseConfiguration graph)
{
return graph.GetAltName (graphSet, null).
Replace (".png", String.Empty).
Replace ('.', '-')
+ ".html";
}
public string GetLink (GraphSetConfiguration graphSet, GraphBaseConfiguration graph)
{
return WebPath + Link +
graph.GetAltName (graphSet, null).
Replace (".png", String.Empty).
Replace ('.', '-')
+ ".html";
}
public override string ToString ()
{
return ConfigText (Params, Items);
}
public static HostGraphPageConfiguration Create (
ServerConfiguration server,
ConfigurationBlock config,
IEnumerable<HostPageConfiguration> hostPages)
{
OptionSet options = GetOptions (Params, config);
string hostPagesName = GetOptionString (options, "GraphPage", "HostGraphPage", false);
HostPageConfiguration hostPage = null;
if (hostPagesName != String.Empty) {
hostPage = hostPages.SingleOrDefault (pp => pp.ConfigName == hostPagesName);
if (hostPage == null) {
ConfigError ("Cannot find GraphPage " + hostPagesName + " specified in HostGraphPage");
}
}
return new HostGraphPageConfiguration (
server,
GetOptionConfigName (options, "HostGraphPage", "HostGraphPage", true),
config.IndentLevel,
GetOptionString (options, "Template", "HostGraphPage", false, "default"),
GetOptionString (options, "PageTitle", "HostGraphPage", false, String.Empty),
hostPage,
GetOptionInteger (options, "LinkIndex", "HostGraphPage", true),
DirectoryCollection.Create (server, config),
GetOptionString (options, "Link", "HostGraphPage", true)
);
}
}
}