mirror of
https://bitbucket.org/anguist/ntpa
synced 2026-10-01 15:58:16 +00:00
145 lines
5.0 KiB
C#
145 lines
5.0 KiB
C#
//
|
|
// PeerPageConfiguration.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.Globalization;
|
|
using Ntp.Analyzer.Config.Destination;
|
|
using Ntp.Analyzer.Config.Graph;
|
|
using Ntp.Analyzer.Config.Navigation;
|
|
using Ntp.Config;
|
|
|
|
namespace Ntp.Analyzer.Config.Page
|
|
{
|
|
public sealed class PeerPageConfiguration : PageConfigurationBase, ILinkable
|
|
{
|
|
private PeerPageConfiguration (
|
|
ServerConfiguration server,
|
|
string configName,
|
|
int indentLevel,
|
|
string theme,
|
|
string title,
|
|
IEnumerable<GraphSetConfiguration> graphs,
|
|
DestinationCollection destinations,
|
|
string link)
|
|
: base (
|
|
server,
|
|
configName,
|
|
indentLevel,
|
|
theme,
|
|
title,
|
|
destinations,
|
|
link)
|
|
{
|
|
this.graphs = new List<GraphSetConfiguration> (graphs);
|
|
graphPages = new List<PeerGraphPageConfiguration> ();
|
|
}
|
|
|
|
private static readonly String[] Params = new[] {
|
|
"PeerPage",
|
|
"Template",
|
|
"PageTitle",
|
|
GraphSetConfiguration.Identifier,
|
|
DirectoryCollection.Identifier,
|
|
"Link"
|
|
};
|
|
private readonly List<PeerGraphPageConfiguration> graphPages;
|
|
private readonly List<GraphSetConfiguration> graphs;
|
|
|
|
/// <summary>
|
|
/// Gets the graphs to be displayed on this page.
|
|
/// </summary>
|
|
/// <value>The peer graphs.</value>
|
|
public IEnumerable<GraphSetConfiguration> Graphs {
|
|
get { return graphs; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the graph pages to be linked from this page.
|
|
/// </summary>
|
|
/// <value>The graph pages.</value>
|
|
public IEnumerable<PeerGraphPageConfiguration> GraphPages {
|
|
get { return graphPages; }
|
|
}
|
|
|
|
protected override IEnumerable<Object> Items {
|
|
get {
|
|
return new object[] {
|
|
ConfigName,
|
|
Theme,
|
|
Title,
|
|
Graphs,
|
|
Destinations,
|
|
Link
|
|
};
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the link related to specified peer.
|
|
/// </summary>
|
|
/// <returns>The link.</returns>
|
|
/// <param name="peerId">Peer identifier.</param>
|
|
public string GetLink (int peerId)
|
|
{
|
|
return WebPath + Link + peerId.ToString (CultureInfo.InvariantCulture) + ".html";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attachs the graph pages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Only use from <see cref="PeerGraphPageConfiguration" />
|
|
/// </remarks>
|
|
/// <param name="page">Page.</param>
|
|
internal void AttachGraphPages (PeerGraphPageConfiguration page)
|
|
{
|
|
graphPages.Add (page);
|
|
}
|
|
|
|
public override string ToString ()
|
|
{
|
|
return ConfigText (Params, Items);
|
|
}
|
|
|
|
public static PeerPageConfiguration Create (
|
|
ServerConfiguration server,
|
|
ConfigurationBlock config,
|
|
IEnumerable<PeerGraphConfiguration> peerGraphs)
|
|
{
|
|
OptionSet options = GetOptions (Params, config);
|
|
|
|
return new PeerPageConfiguration (
|
|
server,
|
|
GetOptionConfigName (options, Params [0], Params [0], true),
|
|
config.IndentLevel,
|
|
GetOptionString (options, "Template", Params [0], false, "default"),
|
|
GetOptionString (options, "PageTitle", Params [0], false, String.Empty),
|
|
GraphSetConfiguration.Create (server, peerGraphs, config, Params [0]),
|
|
DirectoryCollection.Create (server, config),
|
|
GetOptionString (options, "Link", Params [0], true));
|
|
}
|
|
}
|
|
} |