Version 0.2 changes

This commit is contained in:
2016-03-05 15:25:01 +01:00
parent 92e69371b4
commit 8c12f027b8
370 changed files with 40993 additions and 26326 deletions
@@ -2,9 +2,9 @@
// AboutPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -23,11 +23,12 @@
// 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 Ntp.Analyzer.Export;
using System.Collections.Generic;
using Ntp.Analyzer.Config.Destination;
using Ntp.Analyzer.Config.Navigation;
using Ntp.Config;
using System.Collections.Generic;
namespace Ntp.Analyzer.Config.Page
{
@@ -36,25 +37,40 @@ namespace Ntp.Analyzer.Config.Page
private AboutPageConfiguration (
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
int indentLevel,
string theme,
string title,
int serverId,
string header,
string content,
IEnumerable<StreamDestination> destinations,
string link
)
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
DestinationCollection destinations,
string link)
: base (
server,
configName,
indentLevel,
theme,
title,
destinations,
link)
{
this.header = header;
this.content = content;
this.serverId = serverId;
}
private readonly string header;
private static readonly String[] Params = new[] {
"AboutPage",
"Template",
"PageTitle",
"ServerID",
"ContentTitle",
"Content",
FileCollection.Identifier,
"Link"
};
private readonly string content;
private readonly string header;
private readonly int serverId;
public string Header {
@@ -69,44 +85,49 @@ namespace Ntp.Analyzer.Config.Page
get { return serverId; }
}
protected override IEnumerable<Object> Items {
get {
return new object[] {
ConfigName,
Theme,
Title,
ServerId,
Header,
Content,
Destinations,
Link
};
}
}
public override string ToString ()
{
return ConfigText (Params, Items);
}
public static AboutPageConfiguration Create (
ServerConfiguration server,
ConfigurationBlock config)
{
Dictionary<String, String> options = GetOptions (new String[] {
"AboutPage",
"Frequency",
"InitialRun",
"Template",
"PageTitle",
"ServerID",
"ContentTitle",
"Link"
}, config.Lines);
OptionSet options = GetOptions (Params, config);
ConfigurationBlock contentBlock = FindSingleBlock ("Content", config.Lines);
ConfigurationBlock contentBlock = FindSingleBlock ("Content", config);
string content =
string content =
String.Join (Environment.NewLine, contentBlock.Lines, 1, contentBlock.Lines.Length - 2)
.Trim().Replace("\t", String.Empty);
// Get destinations
List<StreamDestination> files = new List<StreamDestination> ();
foreach (string destination in GetMultiOption ("File", FindSingleBlock ("Destinations", config.Lines).Lines))
files.Add (new FileStreamDestination (server.FilePath, destination));
.Trim ().Replace ("\t", String.Empty);
return new AboutPageConfiguration (
server,
GetOptionConfigName (options, "AboutPage"),
GetOptionInteger (options, "Frequency"),
GetOptionBoolean (options, "InitialRun"),
GetOptionString (options, "Template", "default"),
GetOptionString (options, "PageTitle", "PageTitle"),
GetOptionInteger (options, "ServerID"),
GetOptionString (options, "ContentTitle", "ContentTitle"),
GetOptionConfigName (options, Params [0], Params [0], true),
config.IndentLevel,
GetOptionString (options, "Template", Params [0], false, "default"),
GetOptionString (options, "PageTitle", Params [0], true),
GetOptionInteger (options, "ServerID", Params [0], false),
GetOptionString (options, "ContentTitle", Params [0], false, "ContentTitle"),
content,
files,
GetOptionString (options, "Link", "CONFIG ERROR: LINK"));
FileCollection.Create (server, config),
GetOptionString (options, "Link", Params [0], true));
}
}
}
@@ -0,0 +1,99 @@
//
// SummeryCollection.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.Config;
namespace Ntp.Analyzer.Config.Page.Collection
{
public sealed class SummeryCollection : ConfigurationBase
{
public const string Identifier = "Summeries";
private readonly List<PeerSummeryPageConfiguration> pages;
public SummeryCollection(
string configName,
int indentLevel,
IEnumerable<PeerSummeryPageConfiguration> pages)
: base(configName, indentLevel)
{
this.pages = new List<PeerSummeryPageConfiguration>(pages);
}
protected override IEnumerable<Object> Items
{
get { return pages; }
}
public IEnumerable<PeerSummeryPageConfiguration> Pages
{
get { return pages; }
}
public override string ToString()
{
List<Object> values = new List<Object>();
values.Add(null);
IEnumerable<String> names = pages.Select(g => g.ConfigName);
values.AddRange(names);
List<String> settings = new List<string>();
settings.Add(Identifier);
int num = names.Count();
for (int i = 0; i < num; i++)
settings.Add("PeerSummeryPage");
return ConfigText(settings.ToArray(), values.ToArray());
}
public static SummeryCollection Create(
ServerConfiguration server,
IEnumerable<PeerSummeryPageConfiguration> peerSummeries,
ConfigurationBlock config,
string configPath)
{
List<PeerSummeryPageConfiguration> summeries = new List<PeerSummeryPageConfiguration>();
foreach (string name in GetMultiOption("PeerSummeryPage", FindSingleBlock(Identifier, config)))
{
PeerSummeryPageConfiguration summery = peerSummeries.SingleOrDefault(ps => ps.ConfigName == name);
if (summery != null)
summeries.Add(summery);
else
{
ConfigError("Cannot find PeerSummeryPage " + name + " specified in HostPage");
}
}
return new SummeryCollection(String.Empty, config.IndentLevel + 1, summeries);
}
}
}
@@ -2,9 +2,9 @@
// GraphPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -24,34 +24,37 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using Ntp.Analyzer.Config.Navigation;
using Ntp.Analyzer.Export;
using System.Collections.Generic;
using Ntp.Analyzer.Config.Graph;
using Ntp.Analyzer.Config.Destination;
using Ntp.Analyzer.Config.Navigation;
namespace Ntp.Analyzer.Config.Page
{
public abstract class GraphPageConfiguration : PageConfigurationBase, ILinkable
{
private readonly int linkIndex;
protected GraphPageConfiguration (
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
int indentLevel,
string theme,
string title,
int linkIndex,
IEnumerable<StreamDestination> destinations,
DestinationCollection destinations,
string link)
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
: base (
server,
configName,
indentLevel,
theme,
title,
destinations,
link)
{
this.linkIndex = linkIndex;
}
private readonly int linkIndex;
public abstract IEnumerable<GraphSetConfiguration> GraphSets { get; }
public int LinkIndex {
@@ -2,9 +2,9 @@
// HostGrapPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -23,13 +23,13 @@
// 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 Ntp.Analyzer.Export;
using Ntp.Config;
using System.Collections.Generic;
using System.Linq;
using Ntp.Analyzer.Config.Destination;
using Ntp.Analyzer.Config.Graph;
using Ntp.Analyzer.Objects;
using Ntp.Config;
namespace Ntp.Analyzer.Config.Page
{
@@ -38,41 +38,76 @@ namespace Ntp.Analyzer.Config.Page
public HostGraphPageConfiguration (
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
int indentLevel,
string theme,
string title,
HostPageConfiguration page,
int linkIndex,
IEnumerable<StreamDestination> destinations,
DestinationCollection destinations,
string link)
: base(server, configName, frequency, initialRun, theme, title, linkIndex, destinations, 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";
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";
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 (
@@ -80,46 +115,30 @@ namespace Ntp.Analyzer.Config.Page
ConfigurationBlock config,
IEnumerable<HostPageConfiguration> hostPages)
{
Dictionary<String, String> options = GetOptions (new String[] {
"HostGraphPage",
"Frequency",
"InitialRun",
"GraphPage",
"Template",
"PageTitle",
"LinkIndex",
"Link"
}, config.Lines);
OptionSet options = GetOptions (Params, config);
// Find peer page
string hostPagesName = options ["GraphPage"];
HostPageConfiguration hostPage = hostPages.SingleOrDefault (pp => pp.ConfigName == hostPagesName);
string hostPagesName = GetOptionString (options, "GraphPage", "HostGraphPage", false);
HostPageConfiguration hostPage = null;
if (hostPage == null) {
// TODO: Implement logging
;
if (hostPagesName != String.Empty) {
hostPage = hostPages.SingleOrDefault (pp => pp.ConfigName == hostPagesName);
if (hostPage == null) {
ConfigError ("Cannot find GraphPage " + hostPagesName + " specified in HostGraphPage");
}
}
// 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));
return new HostGraphPageConfiguration (
server,
GetOptionConfigName (options, "HostGraphPage"),
GetOptionInteger (options, "Frequency"),
GetOptionBoolean (options, "InitialRun"),
GetOptionString (options, "Template", "default"),
GetOptionString (options, "PageTitle", String.Empty),
GetOptionConfigName (options, "HostGraphPage", "HostGraphPage", true),
config.IndentLevel,
GetOptionString (options, "Template", "HostGraphPage", false, "default"),
GetOptionString (options, "PageTitle", "HostGraphPage", false, String.Empty),
hostPage,
GetOptionInteger (options, "LinkIndex"),
directories,
GetOptionString (options, "Link", "CONFIG ERROR: LINK")
GetOptionInteger (options, "LinkIndex", "HostGraphPage", true),
DirectoryCollection.Create (server, config),
GetOptionString (options, "Link", "HostGraphPage", true)
);
}
}
}
}
+104 -82
View File
@@ -2,9 +2,9 @@
// HostPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -24,12 +24,13 @@
// 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 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
{
@@ -38,53 +39,60 @@ namespace Ntp.Analyzer.Config.Page
/// </summary>
public sealed class HostPageConfiguration : PageConfigurationBase, ILinkable
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.Page.HostPageConfiguration"/> class.
/// </summary>
/// <param name="server">Server.</param>
/// <param name="configName">Config name.</param>
/// <param name="frequency">Frequency.</param>
/// <param name="initialRun">If set to <c>true</c> initial run.</param>
/// <param name="poolMember">If set to <c>true</c> pool member.</param>
/// <param name="theme">Theme.</param>
/// <param name="title">Title.</param>
/// <param name="peerPage">Peer page.</param>
/// <param name="graphs">Graphs.</param>
/// <param name="peerSummeries">Peer summeries.</param>
/// <param name="destinations">Destinations.</param>
/// <param name="link">Link.</param>
private HostPageConfiguration (
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
bool poolMember,
int indentLevel,
string theme,
string title,
bool poolMember,
PeerPageConfiguration peerPage,
IEnumerable<GraphSetConfiguration> graphs,
IEnumerable<PeerSummeryPageConfiguration> peerSummeries,
IEnumerable<StreamDestination> destinations,
SummeryCollection summeries,
FileCollection destinations,
string link)
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
: base (
server,
configName,
indentLevel,
theme,
title,
destinations,
link)
{
this.poolMember = poolMember;
this.peerPage = peerPage;
this.graphs = new List<GraphSetConfiguration>(graphs);
this.peerSummeries = new List<PeerSummeryPageConfiguration>(peerSummeries);
this.graphs = new List<GraphSetConfiguration> (graphs);
this.summeries = summeries;
graphPages = new List<HostGraphPageConfiguration> ();
}
private readonly bool poolMember;
private readonly PeerPageConfiguration peerPage;
private readonly List<GraphSetConfiguration> graphs;
private readonly List<PeerSummeryPageConfiguration> peerSummeries;
/// <summary>
/// The parameters used in configuration files.
/// </summary>
private static readonly String[] Params = new[] {
"HostPage",
"Template",
"PageTitle",
"PoolMember",
"PeerPages",
GraphSetConfiguration.Identifier,
SummeryCollection.Identifier,
FileCollection.Identifier,
"Link"
};
private readonly List<HostGraphPageConfiguration> graphPages;
private readonly List<GraphSetConfiguration> graphs;
private readonly PeerPageConfiguration peerPage;
private readonly bool poolMember;
private readonly SummeryCollection summeries;
/// <summary>
/// Gets a value indicating whether there should be shown a link to pool.ntp.org.
/// </summary>
/// <value><c>true</c> if pool member; otherwise, <c>false</c>.</value>
/// <value>
/// <c>true</c> if pool member; otherwise, <c>false</c>.
/// </value>
public bool PoolMember {
get { return poolMember; }
}
@@ -109,8 +117,8 @@ namespace Ntp.Analyzer.Config.Page
/// Gets the peer summeries to be linked from this page.
/// </summary>
/// <value>The peer summeries.</value>
public IEnumerable<PeerSummeryPageConfiguration> PeerSummeries {
get { return peerSummeries; }
public SummeryCollection PeerSummeries {
get { return summeries; }
}
/// <summary>
@@ -122,17 +130,53 @@ namespace Ntp.Analyzer.Config.Page
}
/// <summary>
/// Attachs the host graph pages.
/// Gets the values of settings in this configuration.
/// </summary>
/// <remarks>Only use from <see cref="HostGraphPageConfiguration"/></remarks>
/// <value>The items.</value>
protected override IEnumerable<Object> Items {
get {
return new object[] {
ConfigName,
Theme,
Title,
PoolMember ? 1 : 0,
PeerPage.ConfigName,
Graphs,
PeerSummeries,
Destinations,
Link
};
}
}
/// <summary>
/// Attachs the host graph pages to this page.
/// </summary>
/// <remarks>
/// Only use from <see cref="HostGraphPageConfiguration" />
/// </remarks>
/// <param name="page">Page.</param>
internal void AttachGraphPages(HostGraphPageConfiguration page)
internal void AttachGraphPages (HostGraphPageConfiguration page)
{
graphPages.Add (page);
}
/// <summary>
/// Create a new instance from the specified configuration lines.
/// Returns a <see cref="System.String" /> that represents the current
/// <see
/// cref="Ntp.Analyzer.Config.Page.HostPageConfiguration" />
/// .
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents the current <see cref="Ntp.Analyzer.Config.Page.HostPageConfiguration" />.
/// </returns>
public override string ToString ()
{
return ConfigText (Params, Items);
}
/// <summary>
/// Factory method.
/// </summary>
/// <param name="server">Server.</param>
/// <param name="config">Config.</param>
@@ -143,57 +187,35 @@ namespace Ntp.Analyzer.Config.Page
ServerConfiguration server,
ConfigurationBlock config,
IEnumerable<PeerPageConfiguration> peerPages,
IEnumerable<HostGraphConfiguration> hostGraphs,
IEnumerable<PeerSummeryPageConfiguration> peerSummeries
)
IEnumerable<GraphBaseConfiguration> hostGraphs,
IEnumerable<PeerSummeryPageConfiguration> peerSummeries)
{
Dictionary<String, String> options = GetOptions (new String[] {
"HostPage",
"Frequency",
"InitialRun",
"Template",
"PageTitle",
"PoolMember",
"PeerPages",
"Link"
}, config.Lines);
OptionSet options = GetOptions (Params, config);
// Find peer page
string peerPageName = options ["PeerPages"];
PeerPageConfiguration peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName);
string peerPageName = GetOptionString (options, Params [4], Params [0], false);
PeerPageConfiguration peerPage = null;
if (peerPage == null) {
// TODO: Make config log error.
;
if (peerPageName != String.Empty) {
peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName);
if (peerPage == null) {
ConfigError ("Cannot find PeerPages " + peerPageName + " specified in HostPage");
}
}
// Find peer summeries
List<PeerSummeryPageConfiguration> summeries = new List<PeerSummeryPageConfiguration> ();
foreach (string name in GetMultiOption ("PeerSummeryPage", FindSingleBlock ("Summeries", config.Lines).Lines)) {
summeries.Add (peerSummeries.Single (ps => ps.ConfigName == name));
}
// Get destinations
List<StreamDestination> files = new List<StreamDestination> ();
foreach (string destination in GetMultiOption ("File", FindSingleBlock ("Destinations", config.Lines).Lines))
files.Add (new FileStreamDestination (server.FilePath, destination));
// Create
return new HostPageConfiguration (
server,
GetOptionConfigName (options, "HostPage"),
GetOptionInteger (options, "Frequency"),
GetOptionBoolean (options, "InitialRun"),
GetOptionBoolean (options, "PoolMember"),
GetOptionString (options, "Template", "default"),
GetOptionString (options, "PageTitle", String.Empty),
GetOptionConfigName (options, Params [0], Params [0], true),
config.IndentLevel,
GetOptionString (options, Params [1], Params [0], false, "default"),
GetOptionString (options, Params [2], Params [0], false, String.Empty),
GetOptionBoolean (options, Params [3], Params [0], false),
peerPage,
GraphSetConfiguration.Create (server, hostGraphs, config),
peerSummeries,
files,
GetOptionString (options, "Link", String.Empty)
GraphSetConfiguration.Create (server, hostGraphs, config, Params [0]),
SummeryCollection.Create (server, peerSummeries, config, Params [0]),
FileCollection.Create (server, config),
GetOptionString (options, Params [8], Params [0], false, String.Empty)
);
}
}
}
}
@@ -2,9 +2,9 @@
// HostSummeryPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -23,37 +23,30 @@
// 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 Ntp.Config;
using Ntp.Analyzer.Export;
using System.Collections.Generic;
using Ntp.Analyzer.Config.Destination;
namespace Ntp.Analyzer.Config.Page
{
public sealed class HostSummeryPageConfiguration : PageConfigurationBase
public abstract class HostSummeryPageConfiguration : PageConfigurationBase
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.Page.HostSummeryPageConfiguration"/> class.
/// </summary>
/// <param name="server">Server.</param>
/// <param name="configName">Config name.</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="destinations">Destinations.</param>
/// <param name="link">Link.</param>
private HostSummeryPageConfiguration (
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
int indentLevel,
string theme,
string title,
IEnumerable<StreamDestination> destinations,
DestinationCollection destinations,
string link)
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
: base (
server,
configName,
indentLevel,
theme,
title,
destinations,
link)
{
}
}
}
}
@@ -2,9 +2,9 @@
// PageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -23,52 +23,40 @@
// 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 Ntp.Analyzer.Export;
using Ntp.Analyzer.Config.Destination;
namespace Ntp.Analyzer.Config.Page
{
public abstract class PageConfigurationBase : ServerSubConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.Page.PageConfigurationBase"/> class.
/// </summary>
/// <param name="server">Server.</param>
/// <param name="configName">Config name.</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="destinations">Destinations.</param>
/// <param name="link">Link.</param>
protected PageConfigurationBase (
{
protected PageConfigurationBase(
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
int indentLevel,
string theme,
string title,
IEnumerable<StreamDestination> destinations,
DestinationCollection destinations,
string link)
: base(server, configName, frequency, initialRun)
: base(server, configName, indentLevel)
{
this.theme = theme;
this.title = title;
this.destinations = new List<StreamDestination>(destinations);
this.destinations = destinations;
this.link = link;
}
protected readonly DestinationCollection destinations;
private readonly string link;
private readonly string theme;
private readonly string title;
private readonly string link;
protected readonly List<StreamDestination> destinations;
/// <summary>
/// Gets the name of this <see cref="Ntp.Analyzer.Config.Navigation.ILinkable"/>.
/// Gets the name of this <see cref="Ntp.Analyzer.Config.Navigation.ILinkable" />.
/// </summary>
/// <value>The name.</value>
public string Name {
public string Name
{
get { return ConfigName; }
}
@@ -76,15 +64,17 @@ namespace Ntp.Analyzer.Config.Page
/// Gets the theme/template to use for this page.
/// </summary>
/// <value>The theme.</value>
public string Theme {
get { return theme.ToLower (); }
public string Theme
{
get { return theme.ToLower(); }
}
/// <summary>
/// Gets the title of this page.
/// </summary>
/// <value>The title.</value>
public string Title {
public string Title
{
get { return title; }
}
@@ -92,7 +82,8 @@ namespace Ntp.Analyzer.Config.Page
/// Gets the destinations for output generated by this configuration.
/// </summary>
/// <value>The destinations.</value>
public IEnumerable<StreamDestination> Destinations {
public DestinationCollection Destinations
{
get { return destinations; }
}
@@ -100,8 +91,9 @@ namespace Ntp.Analyzer.Config.Page
/// Gets the link to this page.
/// </summary>
/// <value>The link.</value>
public string Link {
public string Link
{
get { return link; }
}
}
}
}
@@ -2,9 +2,9 @@
// PageGraphConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -24,37 +24,29 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using Ntp.Config;
using Ntp.Analyzer.Export;
using Ntp.Analyzer.Config.Destination;
namespace Ntp.Analyzer.Config.Page
{
public sealed class PageGraphConfiguration : PageConfigurationBase
public abstract class PageGraphConfiguration : PageConfigurationBase
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.Page.PageGraphConfiguration"/> class.
/// </summary>
/// <param name="server">Server.</param>
/// <param name="configName">Config name.</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="destinations">Destinations.</param>
/// <param name="link">Link.</param>
private PageGraphConfiguration (
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
int indentLevel,
string theme,
string title,
IEnumerable<StreamDestination> destinations,
DestinationCollection destinations,
string link)
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
: base (
server,
configName,
indentLevel,
theme,
title,
destinations,
link)
{
}
}
}
}
@@ -2,9 +2,9 @@
// PeerGraphPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -23,71 +23,94 @@
// 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 Ntp.Config;
using Ntp.Analyzer.Export;
using Ntp.Analyzer.Objects;
using Ntp.Analyzer.Config.Graph;
using System.Collections.Generic;
using System.Linq;
using Ntp.Analyzer.Config.Destination;
using Ntp.Analyzer.Config.Graph;
using Ntp.Analyzer.Objects;
using Ntp.Config;
namespace Ntp.Analyzer.Config.Page
{
public sealed class PeerGraphPageConfiguration : GraphPageConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.Page.PeerGraphPageConfiguration"/> class.
/// </summary>
/// <param name="server">Server.</param>
/// <param name="configName">Config name.</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="page">Page.</param>
/// <param name="linkIndex">Link index.</param>
/// <param name="destinations">Destinations.</param>
/// <param name="link">Link.</param>
private PeerGraphPageConfiguration (
ServerConfiguration server,
string configName,
int frequency,
bool initialRun,
int indentLevel,
string theme,
string title,
PeerPageConfiguration page,
int linkIndex,
IEnumerable<StreamDestination> destinations,
DestinationCollection destinations,
string link)
: base(server, configName, frequency, initialRun, theme, title, linkIndex, destinations, link)
: base (
server,
configName,
indentLevel,
theme,
title,
linkIndex,
destinations,
link)
{
this.page = page;
page.AttachGraphPages (this);
}
private static readonly String[] Params = new[] {
"PeerGraphPage",
"Template",
"PageTitle",
"GraphPage",
"LinkIndex",
DirectoryCollection.Identifier,
"Link"
};
private readonly PeerPageConfiguration 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 (Host host, TimeServer peer, GraphSetConfiguration graphSet, GraphBaseConfiguration graph)
{
return host.Name.Replace ('.', '-') + "_" +
graph.GetAltName (graphSet, peer.Name).
Replace (".png", String.Empty).
Replace ('.', '-')
+ ".html";
graph.GetAltName (graphSet, peer.Name).
Replace (".png", String.Empty).
Replace ('.', '-')
+ ".html";
}
public string GetLink (Host host, TimeServer peer, GraphSetConfiguration graphSet, GraphBaseConfiguration graph)
{
return WebPath + Link +
host.Name.Replace ('.', '-') + "_" +
graph.GetAltName (graphSet, peer.Name).
Replace (".png", String.Empty).
Replace ('.', '-')
+ ".html";
host.Name.Replace ('.', '-') + "_" +
graph.GetAltName (graphSet, peer.Name).
Replace (".png", String.Empty).
Replace ('.', '-')
+ ".html";
}
public override string ToString ()
{
return ConfigText (Params, Items);
}
public static PeerGraphPageConfiguration Create (
@@ -95,45 +118,25 @@ namespace Ntp.Analyzer.Config.Page
ConfigurationBlock config,
IEnumerable<PeerPageConfiguration> peerPages)
{
Dictionary<String, String> options = GetOptions (new String[] {
"PeerGraphPage",
"Frequency",
"InitialRun",
"GraphPage",
"Template",
"PageTitle",
"LinkIndex",
"Link"
}, config.Lines);
OptionSet options = GetOptions (Params, config);
// Find peer page
string peerPageName = options ["GraphPage"];
string peerPageName = GetOptionString (options, "GraphPage", "PeerGraphPage", true);
PeerPageConfiguration peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName);
if (peerPage == null) {
// TODO: Implement logging
;
ConfigError ("Cannot find GraphPage " + peerPageName + " specified in " + Params [0]);
}
// 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));
return new PeerGraphPageConfiguration (
server,
GetOptionConfigName (options, "PeerGraphPage"),
GetOptionInteger (options, "Frequency"),
GetOptionBoolean (options, "InitialRun"),
GetOptionString (options, "Template", "default"),
GetOptionString (options, "PageTitle", String.Empty),
GetOptionConfigName (options, Params [0], Params [0], true),
config.IndentLevel,
GetOptionString (options, "Template", Params [0], false, "default"),
GetOptionString (options, "PageTitle", Params [0], false, String.Empty),
peerPage,
GetOptionInteger (options, "LinkIndex"),
directories,
GetOptionString (options, "Link", "CONFIG ERROR: LINK")
GetOptionInteger (options, "LinkIndex", Params [0], true),
DirectoryCollection.Create (server, config),
GetOptionString (options, "Link", Params [0], true)
);
}
}
@@ -2,9 +2,9 @@
// PeerPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -24,47 +24,49 @@
// 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 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
{
/// <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 configName,
int indentLevel,
string theme,
string title,
IEnumerable<GraphSetConfiguration> graphs,
IEnumerable<StreamDestination> destinations,
DestinationCollection destinations,
string link)
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
: base (
server,
configName,
indentLevel,
theme,
title,
destinations,
link)
{
this.graphs = new List<GraphSetConfiguration>(graphs);
this.graphs = new List<GraphSetConfiguration> (graphs);
graphPages = new List<PeerGraphPageConfiguration> ();
}
private readonly List<GraphSetConfiguration> graphs;
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.
@@ -82,6 +84,19 @@ namespace Ntp.Analyzer.Config.Page
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>
@@ -89,58 +104,42 @@ namespace Ntp.Analyzer.Config.Page
/// <param name="peerId">Peer identifier.</param>
public string GetLink (int peerId)
{
return WebPath + Link + peerId.ToString () + ".html";
return WebPath + Link + peerId.ToString (CultureInfo.InvariantCulture) + ".html";
}
/// <summary>
/// Attachs the graph pages.
/// </summary>
/// <remarks>Only use from <see cref="PeerGraphPageConfiguration"/></remarks>
/// <remarks>
/// Only use from <see cref="PeerGraphPageConfiguration" />
/// </remarks>
/// <param name="page">Page.</param>
internal void AttachGraphPages(PeerGraphPageConfiguration page)
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 override string ToString ()
{
return ConfigText (Params, Items);
}
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"];
OptionSet options = GetOptions (Params, config);
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"));
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));
}
}
}
}
@@ -2,9 +2,9 @@
// PeerSummeryPageConfiguration.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
// Carsten Sonne Larsen <cs@innolan.net>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// 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
@@ -23,52 +23,52 @@
// 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 System.Linq;
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 PeerSummeryPageConfiguration : PageConfigurationBase, ILinkable
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.Page.PeerSummeryPageConfiguration"/> 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="peerPage">Peer page.</param>
/// <param name="graphs">Graphs.</param>
/// <param name="destinations">Destinations.</param>
/// <param name="link">Link.</param>
private PeerSummeryPageConfiguration (
string configName,
ServerConfiguration server,
int frequency,
bool initialRun,
string configName,
int indentLevel,
string theme,
string title,
PeerPageConfiguration peerPage,
IEnumerable<GraphSetConfiguration> graphs,
IEnumerable<StreamDestination> destinations,
string link
)
: base(server, configName, frequency, initialRun, theme, title, destinations, link)
DestinationCollection destinations,
string link)
: base (
server,
configName,
indentLevel,
theme,
title,
destinations,
link)
{
this.peerPage = peerPage;
this.graphs = new List<GraphSetConfiguration>(graphs);
this.graphs = new List<GraphSetConfiguration> (graphs);
}
private readonly PeerPageConfiguration peerPage;
private static readonly String[] Params = new[] {
"PeerSummeryPage",
"Template",
"PageTitle",
"PeerPages",
GraphSetConfiguration.Identifier,
DirectoryCollection.Identifier,
"Link"
};
private readonly List<GraphSetConfiguration> graphs;
private readonly PeerPageConfiguration peerPage;
/// <summary>
/// Gets the graphs to show on this page.
@@ -78,6 +78,20 @@ namespace Ntp.Analyzer.Config.Page
get { return graphs; }
}
protected override IEnumerable<Object> Items {
get {
return new object[] {
ConfigName,
Theme,
Title,
peerPage != null ? peerPage.ConfigName : null,
Graphs,
Destinations,
Link
};
}
}
/// <summary>
/// Gets the link related to specified peer.
/// </summary>
@@ -88,51 +102,41 @@ namespace Ntp.Analyzer.Config.Page
return peerPage.GetLink (peerId);
}
/// <summary>
/// Create a new instance from the specified configuration lines.
/// </summary>
/// <param name="server">Server.</param>
/// <param name="config">Config.</param>
/// <param name="peerPages">Peer pages.</param>
/// <param name="peerGraphs">Peer graphs.</param>
public override string ToString ()
{
return ConfigText (Params, Items);
}
public static PeerSummeryPageConfiguration Create (
ServerConfiguration server,
ConfigurationBlock config,
IEnumerable<PeerPageConfiguration> peerPages,
IEnumerable<PeerGraphConfiguration> peerGraphs)
{
Dictionary<String, String> options = GetOptions (new String[] {
"PeerSummeryPage",
"Frequency",
"InitialRun",
"Template",
"PageTitle",
"PeerPages",
"Link"
}, config.Lines);
OptionSet options = GetOptions (Params, config);
// Find peer page
string peerPageName = options ["PeerPages"];
PeerPageConfiguration peerPage = peerPages.Single (pp => pp.ConfigName == peerPageName);
PeerPageConfiguration peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName);
if (peerPage == null) {
ConfigError ("Cannot find PeerPages " + peerPageName + " specified in " + Params [0]);
ConfigError ("Known peer pages: ");
foreach (PeerPageConfiguration peerPageConfig in peerPages)
ConfigError (peerPageConfig.ConfigName);
}
// Find destinations
List<StreamDestination> files = new List<StreamDestination> ();
foreach (string destination in GetMultiOption ("File", FindSingleBlock ("Destinations", config.Lines).Lines))
files.Add (new FileStreamDestination (server.FilePath, destination));
// Create
return new PeerSummeryPageConfiguration (
GetOptionConfigName(options, "PeerSummeryPage"),
server,
GetOptionInteger (options, "Frequency"),
GetOptionBoolean (options, "InitialRun"),
GetOptionString (options, "Template", "default"),
GetOptionString (options, "PageTitle", String.Empty),
GetOptionConfigName (options, Params [0], Params [0], true),
config.IndentLevel,
GetOptionString (options, "Template", Params [0], false, "default"),
GetOptionString (options, "PageTitle", Params [0], false, String.Empty),
peerPage,
GraphSetConfiguration.Create (server, peerGraphs, config),
files,
GetOptionString (options, "Link", "CONFIG ERROR: Link")
GraphSetConfiguration.Create (server, peerGraphs, config, Params [0]),
FileCollection.Create (server, config),
GetOptionString (options, "Link", Params [0], true)
);
}
}
}
}