mirror of
https://bitbucket.org/anguist/ntpa
synced 2026-10-01 15:58:16 +00:00
147 lines
5.8 KiB
C#
147 lines
5.8 KiB
C#
//
|
|
// PeerPageConfiguration.cs
|
|
//
|
|
// Author:
|
|
// Carsten Sonne Larsen <cs@innolan.dk>
|
|
//
|
|
// 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.Linq;
|
|
using System.Collections.Generic;
|
|
using Ntp.Config;
|
|
using Ntp.Analyzer.Export;
|
|
using Ntp.Analyzer.Config.Graph;
|
|
using Ntp.Analyzer.Config.Navigation;
|
|
|
|
namespace Ntp.Analyzer.Config.Page
|
|
{
|
|
public sealed class PeerPageConfiguration : PageConfigurationBase, ILinkable
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.Page.PeerPageConfiguration"/> class.
|
|
/// </summary>
|
|
/// <param name="configName">Config name.</param>
|
|
/// <param name="server">Server.</param>
|
|
/// <param name="frequency">Frequency.</param>
|
|
/// <param name="initialRun">If set to <c>true</c> initial run.</param>
|
|
/// <param name="theme">Theme.</param>
|
|
/// <param name="title">Title.</param>
|
|
/// <param name="graphs">Graphs.</param>
|
|
/// <param name="destinations">Destinations.</param>
|
|
/// <param name="link">Link.</param>
|
|
private PeerPageConfiguration (
|
|
string configName,
|
|
ServerConfiguration server,
|
|
int frequency,
|
|
bool initialRun,
|
|
string theme,
|
|
string title,
|
|
IEnumerable<GraphSetConfiguration> graphs,
|
|
IEnumerable<StreamDestination> destinations,
|
|
string link)
|
|
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
|
|
{
|
|
this.graphs = new List<GraphSetConfiguration>(graphs);
|
|
graphPages = new List<PeerGraphPageConfiguration> ();
|
|
}
|
|
|
|
private readonly List<GraphSetConfiguration> graphs;
|
|
private readonly List<PeerGraphPageConfiguration> graphPages;
|
|
|
|
/// <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; }
|
|
}
|
|
|
|
/// <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 () + ".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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a new instance from the specified configuration lines.
|
|
/// </summary>
|
|
/// <param name="server">Server.</param>
|
|
/// <param name="config">Config.</param>
|
|
/// <param name="peerGraphs">Peer graphs.</param>
|
|
public static PeerPageConfiguration Create (
|
|
ServerConfiguration server,
|
|
ConfigurationBlock config,
|
|
IEnumerable<PeerGraphConfiguration> peerGraphs)
|
|
{
|
|
Dictionary<String, String> options = GetOptions (new String[] {
|
|
"PeerPage",
|
|
"Frequency",
|
|
"InitialRun",
|
|
"Template",
|
|
"PageTitle",
|
|
"Link"
|
|
}, config.Lines);
|
|
|
|
// Find destination options
|
|
List<DirectoryStreamDestination> directories = new List<DirectoryStreamDestination> ();
|
|
String[] destinationLines = FindSingleBlock ("Destinations", config.Lines).Lines;
|
|
string prefix = GetOptions (new String[] { "Prefix" }, destinationLines) ["Prefix"];
|
|
|
|
foreach (string destination in GetMultiOption ("Directory", destinationLines))
|
|
directories.Add (new DirectoryStreamDestination (server.FilePath, destination, prefix));
|
|
|
|
// Create it.
|
|
return new PeerPageConfiguration (
|
|
GetOptionConfigName(options, "PeerPage"),
|
|
server,
|
|
GetOptionInteger (options, "Frequency"),
|
|
GetOptionBoolean (options, "InitialRun"),
|
|
GetOptionString (options, "Template", "default"),
|
|
GetOptionString (options, "PageTitle", String.Empty),
|
|
GraphSetConfiguration.Create (server, peerGraphs, config),
|
|
directories,
|
|
GetOptionString (options, "Link", "CONFIG ERROR: Link"));
|
|
}
|
|
}
|
|
}
|