mirror of
https://bitbucket.org/anguist/ntpa
synced 2026-10-05 11:28:28 +00:00
126 lines
4.7 KiB
C#
126 lines
4.7 KiB
C#
//
|
|
// HostGrapPageConfiguration.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 Ntp.Analyzer.Export;
|
|
using Ntp.Config;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Ntp.Analyzer.Config.Graph;
|
|
using Ntp.Analyzer.Objects;
|
|
|
|
namespace Ntp.Analyzer.Config.Page
|
|
{
|
|
public sealed class HostGraphPageConfiguration : GraphPageConfiguration
|
|
{
|
|
public HostGraphPageConfiguration (
|
|
ServerConfiguration server,
|
|
string configName,
|
|
int frequency,
|
|
bool initialRun,
|
|
string theme,
|
|
string title,
|
|
HostPageConfiguration page,
|
|
int linkIndex,
|
|
IEnumerable<StreamDestination> destinations,
|
|
string link)
|
|
: base(server, configName, frequency, initialRun, theme, title, linkIndex, destinations, link)
|
|
{
|
|
this.page = page;
|
|
page.AttachGraphPages (this);
|
|
}
|
|
|
|
private readonly HostPageConfiguration page;
|
|
|
|
public override IEnumerable<GraphSetConfiguration> GraphSets {
|
|
get { return page.Graphs; }
|
|
}
|
|
|
|
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 static HostGraphPageConfiguration Create (
|
|
ServerConfiguration server,
|
|
ConfigurationBlock config,
|
|
IEnumerable<HostPageConfiguration> hostPages)
|
|
{
|
|
Dictionary<String, String> options = GetOptions (new String[] {
|
|
"HostGraphPage",
|
|
"Frequency",
|
|
"InitialRun",
|
|
"GraphPage",
|
|
"Template",
|
|
"PageTitle",
|
|
"LinkIndex",
|
|
"Link"
|
|
}, config.Lines);
|
|
|
|
// Find peer page
|
|
string hostPagesName = options ["GraphPage"];
|
|
HostPageConfiguration hostPage = hostPages.SingleOrDefault (pp => pp.ConfigName == hostPagesName);
|
|
|
|
if (hostPage == null) {
|
|
// TODO: Implement logging
|
|
;
|
|
}
|
|
|
|
// 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),
|
|
hostPage,
|
|
GetOptionInteger (options, "LinkIndex"),
|
|
directories,
|
|
GetOptionString (options, "Link", "CONFIG ERROR: LINK")
|
|
);
|
|
}
|
|
}
|
|
}
|