Files
ntpa/Ntp.Analyzer/Config/Configuration.cs
T

115 lines
4.0 KiB
C#
Raw Normal View History

2016-03-05 14:06:38 +01:00
//
// WebConfiguration.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.Collections.Generic;
using Ntp.Analyzer.Log;
using Ntp.Config;
namespace Ntp.Analyzer.Config
{
public sealed class Configuration : ConfigurationBase
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Config.WebConfiguration"/> class.
/// </summary>
/// <param name="configName">Config name.</param>
/// <param name="database">Database.</param>
/// <param name="logs">Logs.</param>
/// <param name="notify">Notify.</param>
/// <param name="bulk">Bulk.</param>
/// <param name="servers">Servers.</param>
public Configuration (
string configName,
DatabaseConfiguration database,
LogConfiguration[] logs,
NotifyConfiguration notify,
ReadingBulkConfiguration bulk,
ServerConfiguration[] servers)
: base(configName)
{
this.database = database;
this.logs = logs;
this.notify = notify;
this.bulk = bulk;
this.servers = new List<ServerConfiguration> (servers);
}
private readonly DatabaseConfiguration database;
private readonly LogConfiguration[] logs;
private readonly NotifyConfiguration notify;
private readonly ReadingBulkConfiguration bulk;
private readonly List<ServerConfiguration> servers;
public DatabaseConfiguration Database {
get { return database; }
}
public LogConfiguration[] Log {
get { return logs; }
}
public NotifyConfiguration Notify {
get { return notify; }
}
public ReadingBulkConfiguration Bulk {
get { return bulk; }
}
public List<ServerConfiguration> Servers {
get { return servers; }
}
public static Configuration Create (String[] lines)
{
ConfigurationBlock databaseBlock = FindSingleBlock ("Database", lines);
DatabaseConfiguration database = DatabaseConfiguration.Create (databaseBlock);
List<LogConfiguration> logs = new List<LogConfiguration>();
ConfigurationBlock[] logBlocks = FindBlocks ("Log", lines);
foreach (ConfigurationBlock logBlock in logBlocks) {
logs.Add (LogConfiguration.Create (logBlock));
}
ConfigurationBlock notifyBlock = FindSingleBlock ("Notify", lines);
NotifyConfiguration notify = NotifyConfiguration.Create (notifyBlock);
ConfigurationBlock bulkBlock = FindSingleBlock ("Reading", lines);
ReadingBulkConfiguration bulk = ReadingBulkConfiguration.Create (bulkBlock);
ConfigurationBlock[] serverBlocks = FindBlocks ("Server", lines);
List<ServerConfiguration> servers = new List<ServerConfiguration> ();
foreach (ConfigurationBlock block in serverBlocks) {
servers.Add (ServerConfiguration.Create (bulk, block.Lines));
}
return new Configuration ("BASE", database, logs.ToArray(), notify, bulk, servers.ToArray ());
}
}
}