From cb3937da99451981ed8e47e23cf2e84f5fd942fe Mon Sep 17 00:00:00 2001 From: llsth Date: Sun, 10 Apr 2016 11:50:35 +0200 Subject: [PATCH] Config cleanup & bugfixes --- INSTALL | 35 +- MySql/Source/MySql.Data/MySql.Data.csproj | 11 +- NPlot/NPlot.csproj | 5 + Ntp.Analyzer.Cli/Ntp.Analyzer.Cli.csproj | 25 +- Ntp.Analyzer.Cli/Program.cs | 3 +- Ntp.Analyzer.Data/DataFace.cs | 84 +--- Ntp.Analyzer.Data/DataInitializer.cs | 10 +- Ntp.Analyzer.Data/File/NtpConfMapper.cs | 173 -------- Ntp.Analyzer.Data/Live/IOStatsMapper.cs | 2 +- Ntp.Analyzer.Data/Live/NtpdcImporter.cs | 2 +- Ntp.Analyzer.Data/Live/NtpqHostImporter.cs | 2 +- Ntp.Analyzer.Data/Live/NtpqPeerMapper.cs | 2 +- Ntp.Analyzer.Data/Ntp.Analyzer.Data.csproj | 16 +- Ntp.Analyzer.Data/Static/DatabaseMapper.cs | 12 +- .../Static/HostDatabaseMapper.cs | 49 ++- .../Static/PeerActivityDatabaseMapper.cs | 157 +++++++ .../Static/PeerDatabaseMapper.cs | 48 +-- Ntp.Analyzer.Gui/Ntp.Analyzer.Gui.csproj | 5 + Ntp.Analyzer.Localize/ConfigurationKeyword.cs | 158 +++++++ Ntp.Analyzer.Localize/ConfigurationMessage.cs | 52 +++ Ntp.Analyzer.Localize/LogMessage.cs | 38 ++ .../Ntp.Analyzer.Localize.csproj | 51 +++ Ntp.Analyzer.Localize/PageText.cs | 49 +++ .../Properties/AssemblyInfo.cs | 52 +++ .../VersionInfo.cs | 7 +- Ntp.Analyzer.Log/Ntp.Analyzer.Log.csproj | 5 + .../Ntp.Analyzer.Objects.csproj | 6 + Ntp.Analyzer.Objects/PeerActivity.cs | 78 ++++ Ntp.Analyzer.Objects/PersistentObject.cs | 17 + Ntp.Analyzer.Objects/StatusLine.cs | 57 +-- .../Description/BulkStatJob.cs | 3 +- .../Description/HostGraphJob.cs | 5 +- .../Description/HostGraphPageJob.cs | 5 +- .../Description/HostIOStatJob.cs | 6 +- .../Description/HostPageJob.cs | 18 +- .../Description/HostStatJob.cs | 10 +- Ntp.Analyzer.Process/Description/NotifyJob.cs | 1 + .../Description/PeerGraphJob.cs | 31 +- .../Description/PeerGraphPageJob.cs | 37 +- .../Description/PeerPageJob.cs | 38 +- .../Description/PeerStatJob.cs | 41 +- Ntp.Analyzer.Process/Description/StreamJob.cs | 1 + .../Description/TrafficGraphJob.cs | 5 +- Ntp.Analyzer.Process/Initializer.cs | 16 +- .../Ntp.Analyzer.Process.csproj | 13 +- .../Ntp.Analyzer.Validate.Cli.csproj | 20 +- Ntp.Analyzer.Validate.Cli/Program.cs | 57 ++- Ntp.Analyzer.sln | 58 ++- Ntp.Analyzer/Config/Configuration.cs | 9 +- .../Destination/DestinationCollection.cs | 1 + .../Config/Destination/DirectoryCollection.cs | 22 +- .../Config/Destination/FileCollection.cs | 35 +- .../Destination/GraphSetConfiguration.cs | 91 ++-- .../Config/Destination/WebLinkCollection.cs | 17 +- .../Graph/DispersionGraphConfiguration.cs | 7 +- .../Config/Graph/GraphBaseConfiguration.cs | 3 +- .../Config/Graph/HostGraphConfiguration.cs | 65 +-- .../Config/Graph/PeerGraphConfiguration.cs | 62 +-- .../Config/Graph/TrafficGraphConfiguration.cs | 96 +++-- .../Navigation/DropdownItemConfiguration.cs | 31 +- .../Navigation/HeadMenuItemConfiguration.cs | 4 +- .../Navigation/HeaderMenuItemConfiguration.cs | 4 +- .../Navigation/LinkMenuItemConfiguration.cs | 4 +- .../Config/Navigation/MenuConfiguration.cs | 32 +- .../Navigation/MenuItemConfiguration.cs | 128 +++--- .../Config/Navigation/MenuItemType.cs | 34 +- .../Navigation/PageMenuItemConfiguration.cs | 7 +- .../Navigation/SpacerMenuItemConfiguration.cs | 4 +- .../Config/Page/AboutPageConfiguration.cs | 70 +-- .../Page/Collection/SummaryCollection.cs | 37 +- .../Config/Page/GraphPageConfiguration.cs | 6 +- .../Config/Page/HostGraphPageConfiguration.cs | 57 ++- .../Config/Page/HostPageConfiguration.cs | 59 +-- .../Config/Page/PeerGraphPageConfiguration.cs | 79 ++-- .../Config/Page/PeerPageConfiguration.cs | 38 +- .../Page/PeerSummaryPageConfiguration.cs | 50 ++- .../Config/Root/ClusterConfiguration.cs | 25 +- .../Config/Root/DatabaseConfiguration.cs | 53 ++- .../Config/Root/ListenerConfiguration.cs | 20 +- Ntp.Analyzer/Config/Root/NodeConfiguration.cs | 24 +- .../Config/Root/NotifyConfiguration.cs | 58 +-- .../Config/Root/ReadingBulkConfiguration.cs | 29 +- Ntp.Analyzer/Config/ServerConfiguration.cs | 119 +++--- Ntp.Analyzer/Config/ServerSubConfiguration.cs | 8 - .../Config/Stats/HostIOStatConfiguration.cs | 39 +- .../Config/Stats/HostStatConfiguration.cs | 37 +- .../Config/Stats/PeerStatConfiguration.cs | 37 +- .../Config/Stats/StatsConfiguration.cs | 1 + .../Export/DirectoryStreamDestination.cs | 2 +- Ntp.Analyzer/Export/FileStreamDestination.cs | 2 +- Ntp.Analyzer/Graph/GraphBase.cs | 7 +- Ntp.Analyzer/Ntp.Analyzer.csproj | 15 +- Ntp.Analyzer/Page/BootstrapPeerPageBuilder.cs | 17 +- .../Page/BootstrapPeerSummaryPageBuilder.cs | 2 +- .../Page/DefaultPeerSummaryPageBuilder.cs | 2 +- Ntp.Analyzer/Render/Host/HostLineRender.cs | 56 ++- .../Render/Peer/BootstrapPeerGraphRender.cs | 127 +++--- .../Render/Peer/BootstrapPeerInfoRender.cs | 403 +++++++++++------- .../Render/Peer/DefaultPeerInfoRender.cs | 2 +- .../Summary/BootstrapSummaryGraphRender.cs | 112 +++-- .../Summary/DefaultPeerSummaryGraphRender.cs | 58 +-- Ntp.Analyzer/Statistics/StatusBuilder.cs | 42 +- Ntp.Analyzer/Statistics/SummaryBuilder.cs | 83 ---- Ntp.Config/ConfigurationBase.cs | 8 +- Ntp.Config/Ntp.Config.csproj | 5 + Ntp.Data/Ntp.Data.csproj | 5 + .../DirectoryCommand.cs | 5 +- {Ntp.System => Ntp.Interop}/InterProcess.cs | 2 +- .../Ntp.Interop.csproj | 10 +- {Ntp.System => Ntp.Interop}/Options.cs | 2 +- {Ntp.System => Ntp.Interop}/ProcessInfo.cs | 2 +- .../Properties/AssemblyInfo.cs | 0 {Ntp.System => Ntp.Interop}/ShellCommand.cs | 3 +- Ntp.Monitor.Cli/Ntp.Monitor.Cli.csproj | 10 +- Ntp.Monitor.Client/Ntp.Monitor.Client.csproj | 5 + Ntp.Monitor.Server/Ntp.Monitor.Server.csproj | 5 + Ntp.Monitor/Ntp.Monitor.csproj | 5 + Ntp.Process/Cluster.cs | 2 +- Ntp.Process/Ntp.Process.csproj | 9 +- example/ntp.conf | 9 - example/ntpa.graph.conf | 3 - example/ntpa.web.conf | 5 +- example/ntpa.web.small.conf | 3 - sql/create_tables.sql | 10 + 124 files changed, 2388 insertions(+), 1728 deletions(-) delete mode 100644 Ntp.Analyzer.Data/File/NtpConfMapper.cs create mode 100644 Ntp.Analyzer.Data/Static/PeerActivityDatabaseMapper.cs create mode 100644 Ntp.Analyzer.Localize/ConfigurationKeyword.cs create mode 100644 Ntp.Analyzer.Localize/ConfigurationMessage.cs create mode 100644 Ntp.Analyzer.Localize/LogMessage.cs create mode 100644 Ntp.Analyzer.Localize/Ntp.Analyzer.Localize.csproj create mode 100644 Ntp.Analyzer.Localize/PageText.cs create mode 100644 Ntp.Analyzer.Localize/Properties/AssemblyInfo.cs rename {Ntp.System => Ntp.Analyzer.Localize}/VersionInfo.cs (93%) create mode 100644 Ntp.Analyzer.Objects/PeerActivity.cs rename Ntp.Analyzer.Data/Cache/NtpConfCache.cs => Ntp.Analyzer/Config/Navigation/MenuItemType.cs (68%) delete mode 100644 Ntp.Analyzer/Statistics/SummaryBuilder.cs rename {Ntp.System => Ntp.Interop}/DirectoryCommand.cs (99%) rename {Ntp.System => Ntp.Interop}/InterProcess.cs (99%) rename Ntp.System/Ntp.System.csproj => Ntp.Interop/Ntp.Interop.csproj (88%) rename {Ntp.System => Ntp.Interop}/Options.cs (99%) rename {Ntp.System => Ntp.Interop}/ProcessInfo.cs (98%) rename {Ntp.System => Ntp.Interop}/Properties/AssemblyInfo.cs (100%) rename {Ntp.System => Ntp.Interop}/ShellCommand.cs (99%) delete mode 100644 example/ntp.conf diff --git a/INSTALL b/INSTALL index 6dfe3f8d..0a1e8dd5 100644 --- a/INSTALL +++ b/INSTALL @@ -32,13 +32,12 @@ Build the solution with: Build a pure server version (no GTK) with: # make server -Copy the output files in the bin folder to /opt/ntpa or any other -suitable location and copy ntpa.stat.conf from example to -/etc/ntpa.conf +Copy content of bin folder to /opt/ntpa and copy ntpa.stat.conf from +example to /etc/ntpa.conf. On FreeBSD copy content of bin to /usr/local/ntpa/ -Copy example/ntpa.stat.conf to /usr/local/etc/ntpa/ntpa.conf -Copy script/ntpa.rc to /usr/local/etc/rc.d/ntpa +Copy ntpa.stat.conf from example to /usr/local/etc/ntpa/ntpa.conf +Copy script/ntpa.rc to /usr/local/etc/rc.d/ntpa/ntpa Touch /var/log/ntpa.log and adjust pid file location if needed. @@ -46,18 +45,15 @@ Configuration Set database user name and password in the top of ntpa.conf. Leave the Create setting to 1 if you want all tables and data created automatically. -Then later you can use phpMyAdmin, MySQL Workbench or similar to adjust -the auto generated values. - -Set Hostname to point at a name or an IP address reachable by ntpq. If -you want to generate graphs and pages also copy ntp.conf from the NTP host -to the machine running ntpa and set ConfigFile to point at this file. +Later you can use phpMyAdmin, MySQL Workbench or similar to adjust the +auto generated values. Set Hostname to point at a name or an IP address +reachable by ntpq. Configuration can be validated with the validation tool: -# mono ntpav.exe /etc/ntpa.conf +# mono ntpav.exe --validate /etc/ntpa.conf To start ntpa use: -# mono ntpa.exe +# mono ntpa.exe --config /etc/ntpa.conf Look in the log file for errors and other clues when debugging. @@ -65,17 +61,18 @@ To stop ntpa use kill. Find the process id in the log file. # kill 72354 To start ntpa in daemon mode: -# mono ntpa.exe & +# mono ntpa.exe --config /etc/ntpa.conf & On FreeBSD use the rc.d script to start and stop the daemon. -GTK GUI -Run Ntp.Analyzer.Gui.exe and connect to ntpa with the a port specified -in the listener section. The GTK GUI is experimental as does not support -SQL configuration and error handling. Use it at your own risk. - Connect to ntpa and get a list of available commands: # ntpac 127.0.0.1 9070 help Ask ntpa how long time it has been running: # ntpac 127.0.0.1 9070 uptime + +GTK GUI +Run Ntp.Analyzer.Gui.exe and connect to ntpa with the a port specified +in the listener section. The GTK GUI is experimental as does not support +SQL configuration and error handling. Use it at your own risk. + diff --git a/MySql/Source/MySql.Data/MySql.Data.csproj b/MySql/Source/MySql.Data/MySql.Data.csproj index 64691dc8..a03e3edb 100644 --- a/MySql/Source/MySql.Data/MySql.Data.csproj +++ b/MySql/Source/MySql.Data/MySql.Data.csproj @@ -6,7 +6,6 @@ 8.0.30703 2.0 4.0 - v4.0 NET_40_OR_GREATER 0.4.2b @@ -48,6 +47,7 @@ AllRules.ruleset true false + v4.0 true @@ -61,6 +61,7 @@ 4 AllRules.ruleset false + v4.0 true @@ -73,6 +74,7 @@ prompt 1 false + v4.0 @@ -265,4 +267,11 @@ + + false + bin\Develop + $(DefineConstants);DEBUG;TRACE + 4 + true + diff --git a/NPlot/NPlot.csproj b/NPlot/NPlot.csproj index acb312ce..b833fe66 100644 --- a/NPlot/NPlot.csproj +++ b/NPlot/NPlot.csproj @@ -33,6 +33,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.Analyzer.Cli/Ntp.Analyzer.Cli.csproj b/Ntp.Analyzer.Cli/Ntp.Analyzer.Cli.csproj index 708b6343..def6dccd 100644 --- a/Ntp.Analyzer.Cli/Ntp.Analyzer.Cli.csproj +++ b/Ntp.Analyzer.Cli/Ntp.Analyzer.Cli.csproj @@ -10,12 +10,12 @@ Ntp.Analyzer.Cli Ntp.Analyzer.Cli.Program 0.4.2b - ntpa true ..\bin\ 4 + ntpa false @@ -23,12 +23,21 @@ 4 true true - --config ~/code/ntpa/example/ntpa.stat.conf --temp /tmp/ + --config ~/code/ntpa/ntpa.web.conf --temp /tmp/ + ntpa true ..\bin\ 4 + ntpa + + + false + bin\Develop + 4 + Ntp.Analyzer.Cli + --config ~/code/ntpa/example/ntpa.web.conf --temp /tmp/ @@ -51,10 +60,6 @@ {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F} Ntp.Process - - {A98DB601-2993-4181-A573-5FCCC5E954C1} - Ntp.System - {909C8729-ED63-4603-85EA-34A1FC4D63D9} Ntp.Analyzer.Log @@ -63,6 +68,14 @@ {43A1A769-6ED9-4AE1-821A-43F97814968C} Ntp.Config + + {A98DB601-2993-4181-A573-5FCCC5E954C1} + Ntp.Interop + + + {6F200007-52DB-4861-A565-124270C07F67} + Ntp.Analyzer.Localize + diff --git a/Ntp.Analyzer.Cli/Program.cs b/Ntp.Analyzer.Cli/Program.cs index 67720609..3d2d0368 100644 --- a/Ntp.Analyzer.Cli/Program.cs +++ b/Ntp.Analyzer.Cli/Program.cs @@ -27,9 +27,10 @@ using System; using System.Globalization; using System.IO; using System.Threading; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Process; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Analyzer.Cli { diff --git a/Ntp.Analyzer.Data/DataFace.cs b/Ntp.Analyzer.Data/DataFace.cs index cc08d608..93e4ac74 100644 --- a/Ntp.Analyzer.Data/DataFace.cs +++ b/Ntp.Analyzer.Data/DataFace.cs @@ -35,13 +35,12 @@ namespace Ntp.Analyzer.Data /// public sealed class DataFace { - private static DataFace instance = new DataFace (); - private readonly Object locker = new Object (); + private static DataFace instance; private readonly LogBase log; - private NtpConfCache ntpConfigCache; private NtpqCache ntpqCache; private HostDatabaseMapper hostMapper; private PeerDatabaseMapper peerMapper; + private PeerActivityDatabaseMapper peerActivityMapper; private TimeServerDatabaseMapper serverMapper; /// @@ -50,19 +49,16 @@ namespace Ntp.Analyzer.Data private DataFace () { log = DataConnection.Log; + hostMapper = new HostDatabaseMapper (log); + serverMapper = new TimeServerDatabaseMapper (log); + peerMapper = new PeerDatabaseMapper (serverMapper, log); + peerActivityMapper = new PeerActivityDatabaseMapper (hostMapper, peerMapper, log); + ntpqCache = new NtpqCache (log); } public static void Reset() { - if (instance != null) { - if (instance.ntpConfigCache != null) { - instance.ntpConfigCache.Clear (); - } - if (instance.ntpqCache != null) { - instance.ntpqCache.Clear (); - } - } - + // Not thread-safe. Use reset to initialize. instance = new DataFace (); } @@ -74,36 +70,12 @@ namespace Ntp.Analyzer.Data get { return instance; } } - /// - /// Gets the ntp config cache. - /// - /// The ntp config cache. - public NtpConfCache NtpConfigCache { - get { - lock (locker) { - if (ntpConfigCache == null) { - ntpConfigCache = new NtpConfCache (log); - } - } - - return ntpConfigCache; - } - } - /// /// Gets the ntpq cache. /// /// The ntpq cache. public NtpqCache NtpqCache { - get { - lock (locker) { - if (ntpqCache == null) { - ntpqCache = new NtpqCache (log); - } - } - - return ntpqCache; - } + get { return ntpqCache; } } /// @@ -111,15 +83,7 @@ namespace Ntp.Analyzer.Data /// /// The hosts. public HostDatabaseMapper Hosts { - get { - lock (locker) { - if (hostMapper == null) { - hostMapper = new HostDatabaseMapper (log); - } - } - - return hostMapper; - } + get { return hostMapper; } } /// @@ -127,15 +91,7 @@ namespace Ntp.Analyzer.Data /// /// The peers. public PeerDatabaseMapper Peers { - get { - lock (locker) { - if (peerMapper == null) { - peerMapper = new PeerDatabaseMapper (Servers, log); - } - } - - return peerMapper; - } + get { return peerMapper; } } /// @@ -143,15 +99,7 @@ namespace Ntp.Analyzer.Data /// /// The servers. public TimeServerDatabaseMapper Servers { - get { - lock (locker) { - if (serverMapper == null) { - serverMapper = new TimeServerDatabaseMapper (log); - } - } - - return serverMapper; - } + get { return serverMapper; } } /// @@ -177,5 +125,13 @@ namespace Ntp.Analyzer.Data public PeerReadingDatabaseMapper PeerReadings { get { return new PeerReadingDatabaseMapper (Hosts, Peers, log); } } + + /// + /// Gets the peer activity mapper. + /// + /// The peer activity mapper. + public PeerActivityDatabaseMapper PeerActivity { + get { return peerActivityMapper; } + } } } \ No newline at end of file diff --git a/Ntp.Analyzer.Data/DataInitializer.cs b/Ntp.Analyzer.Data/DataInitializer.cs index ed09927d..71f0794c 100644 --- a/Ntp.Analyzer.Data/DataInitializer.cs +++ b/Ntp.Analyzer.Data/DataInitializer.cs @@ -23,13 +23,14 @@ // 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.Log; -using MySql.Data.MySqlClient; -using Ntp.Analyzer.Data.Static; using System.Collections.Generic; -using Ntp.Analyzer.Data; using System.Data; +using MySql.Data.MySqlClient; +using Ntp.Analyzer.Log; +using Ntp.Analyzer.Data; +using Ntp.Analyzer.Data.Static; namespace Ntp.Analyzer.Data { @@ -85,6 +86,7 @@ namespace Ntp.Analyzer.Data initializers.Add (new HostReadingDatabaseMapper (hostMapper, peerMapper, log)); initializers.Add (new PeerReadingDatabaseMapper (hostMapper, peerMapper, log)); initializers.Add (new HostIOReadingDatabaseMapper (hostMapper, log)); + initializers.Add (new PeerActivityDatabaseMapper (hostMapper, peerMapper, log)); foreach (ITableInitializer initializer in initializers) { try { diff --git a/Ntp.Analyzer.Data/File/NtpConfMapper.cs b/Ntp.Analyzer.Data/File/NtpConfMapper.cs deleted file mode 100644 index 3816e363..00000000 --- a/Ntp.Analyzer.Data/File/NtpConfMapper.cs +++ /dev/null @@ -1,173 +0,0 @@ -// -// NtpConfMapper.cs -// -// Author: -// Carsten Sonne Larsen -// -// Copyright (c) 2013-2016 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.Diagnostics; -using System.IO; -using System.Net; -using Ntp.Analyzer.Log; -using Ntp.Analyzer.Objects; -using Ntp.Data; - -namespace Ntp.Analyzer.Data.File -{ - public sealed class NtpConfMapper : DataMapper - { - public NtpConfMapper (string file, LogBase log) - : base (log) - { - this.file = file; - } - - private readonly string file; - private readonly Object locker = new Object (); - private List entries; - private TextReader reader; - - /// - /// Read all data from file in a sequential manner. - /// - /// The enumerator. - public override IEnumerator GetEnumerator () - { - lock (locker) { - Import (); - - return entries.GetEnumerator (); - } - } - - private void Import () - { - if (entries != null) - return; - - entries = new List (); - - lock (entries) { - if (file == null) - throw new ArgumentException ("No filename specified for import file."); - - try { - reader = new StreamReader (file); - - while (reader.Peek () != -1) { - string line = reader.ReadLine () ?? String.Empty; - line = line.Trim(); - - if (line.Length == 0) - continue; - - if (line[0] == '#') - continue; - - NtpConfEntry entry = ParseLine (line); - - if (entry != null) - entries.Add (entry); - } - } finally { - if (reader != null) - reader.Close (); - } - } - } - - private NtpConfEntry ParseLine (string line) - { - string l = line + String.Empty.PadLeft (10); - - // Find server role - TimeServerRole role; - if (l.Substring (0, 4) == "peer") { - role = TimeServerRole.Peer; - l = l.Remove (0, 4); - } else if (l.Substring (0, 6) == "server") { - role = TimeServerRole.Server; - l = l.Remove (0, 6); - } else - return null; - - // Find address - l = l.Trim () + " "; - int addressPos = l.IndexOf (" ", StringComparison.Ordinal); - - // Erroneous config - if (addressPos < 0) - return null; - - string name = String.Empty; - string address = l.Substring (0, addressPos); - - IPAddress ip; - if (!IPAddress.TryParse (address, out ip)) { - // Its was not an IP - try { - name = address; - ip = Dns.GetHostAddresses (address) [0]; - } catch { - ip = IPAddress.IPv6None; - } - } else { - // Its was an IP so try to look up name - try { - IPHostEntry hostEntry = Dns.GetHostEntry (ip); - name = hostEntry.HostName; - } catch { - name = ip.ToString (); - } - } - - int? orgId = null; - int orgPos = l.IndexOf ("#", StringComparison.Ordinal); - - if (orgPos != -1) { - try { - string org = l.Substring (orgPos + 1).Trim () + " "; - orgPos = org.IndexOf (" ", StringComparison.Ordinal); - org = org.Substring (0, orgPos).Trim (); - - int realOrgId; - if (Int32.TryParse (org, out realOrgId)) { - orgId = realOrgId; - } - } catch (Exception e) { - Log.WriteLine (e, Severity.Trace); - orgId = null; - } - } - - if (!orgId.HasValue) { - Log.WriteLine (String.Format ( - "Consider adding an orginization ID to {0} in {1}", - address, file), - Severity.Debug); - } - - return new NtpConfEntry (role, ip, name, orgId); - } - } -} \ No newline at end of file diff --git a/Ntp.Analyzer.Data/Live/IOStatsMapper.cs b/Ntp.Analyzer.Data/Live/IOStatsMapper.cs index 91421a7e..e3301722 100644 --- a/Ntp.Analyzer.Data/Live/IOStatsMapper.cs +++ b/Ntp.Analyzer.Data/Live/IOStatsMapper.cs @@ -30,7 +30,7 @@ using System.IO; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects.Live; using Ntp.Data; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Analyzer.Data.Live { diff --git a/Ntp.Analyzer.Data/Live/NtpdcImporter.cs b/Ntp.Analyzer.Data/Live/NtpdcImporter.cs index faf66efb..4cc10bd0 100644 --- a/Ntp.Analyzer.Data/Live/NtpdcImporter.cs +++ b/Ntp.Analyzer.Data/Live/NtpdcImporter.cs @@ -31,7 +31,7 @@ using System.Linq; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Analyzer.Data; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Analyzer.Data.Live { diff --git a/Ntp.Analyzer.Data/Live/NtpqHostImporter.cs b/Ntp.Analyzer.Data/Live/NtpqHostImporter.cs index 08b183c3..f7abbaaf 100644 --- a/Ntp.Analyzer.Data/Live/NtpqHostImporter.cs +++ b/Ntp.Analyzer.Data/Live/NtpqHostImporter.cs @@ -30,7 +30,7 @@ using System.IO; using System.Linq; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; -using Ntp.System; +using Ntp.Interop; using Ntp.Analyzer.Data; namespace Ntp.Analyzer.Data.Live diff --git a/Ntp.Analyzer.Data/Live/NtpqPeerMapper.cs b/Ntp.Analyzer.Data/Live/NtpqPeerMapper.cs index 1a7c276c..634c2d4e 100644 --- a/Ntp.Analyzer.Data/Live/NtpqPeerMapper.cs +++ b/Ntp.Analyzer.Data/Live/NtpqPeerMapper.cs @@ -30,7 +30,7 @@ using System.IO; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects.Live; using Ntp.Data; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Analyzer.Data.Live { diff --git a/Ntp.Analyzer.Data/Ntp.Analyzer.Data.csproj b/Ntp.Analyzer.Data/Ntp.Analyzer.Data.csproj index 0b53646a..045070ec 100644 --- a/Ntp.Analyzer.Data/Ntp.Analyzer.Data.csproj +++ b/Ntp.Analyzer.Data/Ntp.Analyzer.Data.csproj @@ -33,6 +33,11 @@ ..\bin\ 1 + + false + bin\Develop + 4 + @@ -46,7 +51,6 @@ - @@ -55,7 +59,6 @@ - @@ -66,6 +69,7 @@ + @@ -88,13 +92,13 @@ {909C8729-ED63-4603-85EA-34A1FC4D63D9} Ntp.Analyzer.Log - - {A98DB601-2993-4181-A573-5FCCC5E954C1} - Ntp.System - {E9DF5ED1-4CBD-4226-B931-9A51610AC14D} MySql.Data + + {A98DB601-2993-4181-A573-5FCCC5E954C1} + Ntp.Interop + \ No newline at end of file diff --git a/Ntp.Analyzer.Data/Static/DatabaseMapper.cs b/Ntp.Analyzer.Data/Static/DatabaseMapper.cs index 8bb9930c..befd8c02 100644 --- a/Ntp.Analyzer.Data/Static/DatabaseMapper.cs +++ b/Ntp.Analyzer.Data/Static/DatabaseMapper.cs @@ -23,6 +23,7 @@ // 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.Data; @@ -72,7 +73,16 @@ namespace Ntp.Analyzer.Data.Static if (!HasContent) ReadContent (); - return items.ContainsKey (id) ? items [id] : FetchExternal (id); + T item = null; + + lock (Locker) { + item = items.ContainsKey (id) ? items [id] : null; + } + + if (item == null) + item = FetchExternal (id); + + return item; } } diff --git a/Ntp.Analyzer.Data/Static/HostDatabaseMapper.cs b/Ntp.Analyzer.Data/Static/HostDatabaseMapper.cs index fe4dd96c..8e2bd3e0 100644 --- a/Ntp.Analyzer.Data/Static/HostDatabaseMapper.cs +++ b/Ntp.Analyzer.Data/Static/HostDatabaseMapper.cs @@ -23,6 +23,7 @@ // 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 MySql.Data.MySqlClient; @@ -113,36 +114,34 @@ namespace Ntp.Analyzer.Data.Static /// The enumerator. public override IEnumerator GetEnumerator () { + IEnumerator result = null; + lock (Locker) { + if (HasContent) + result = Content.GetEnumerator (); + else { + try { + Open (); + Command.CommandText = selectSql; + Reader = Command.ExecuteReader (); - if (HasContent) { - foreach (Host host in Content) - yield return host; - - yield break; - } - - try { - Open (); - Command.CommandText = selectSql; - Reader = Command.ExecuteReader (); - - while (Reader.Read ()) { - int id = Convert.ToInt32 (Reader ["id"]); - string name = Reader ["name"].ToString (); - string ip = Reader ["ip"].ToString (); - int? orgId = Reader ["orgId"] != DBNull.Value ? + while (Reader.Read ()) { + int id = Convert.ToInt32 (Reader ["id"]); + string name = Reader ["name"].ToString (); + string ip = Reader ["ip"].ToString (); + int? orgId = Reader ["orgId"] != DBNull.Value ? (int?)Convert.ToInt32 (Reader ["orgId"]) : (int?)null; - - Host host = new Host (id, name, ip, orgId, false); - AddItem (host); - - yield return host; + Host host = new Host (id, name, ip, orgId, false); + AddItem (host); + } + } finally { + Close (); } - } finally { - Close (); + result = Content.GetEnumerator (); } } + + return result; } } -} +} \ No newline at end of file diff --git a/Ntp.Analyzer.Data/Static/PeerActivityDatabaseMapper.cs b/Ntp.Analyzer.Data/Static/PeerActivityDatabaseMapper.cs new file mode 100644 index 00000000..ca5b0b97 --- /dev/null +++ b/Ntp.Analyzer.Data/Static/PeerActivityDatabaseMapper.cs @@ -0,0 +1,157 @@ +// +// PeerActivityDatabaseMapper.cs +// +// Author: +// Carsten Sonne Larsen +// +// Copyright (c) 2013-2016 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.Log; +using Ntp.Analyzer.Objects; +using System.Collections.Generic; + +namespace Ntp.Analyzer.Data.Static +{ + public class PeerActivityDatabaseMapper : DatabaseMapper + { + internal PeerActivityDatabaseMapper ( + HostDatabaseMapper hostMapper, + PeerDatabaseMapper peerMapper, + LogBase log + ) + : base(log) + { + this.hostMapper = hostMapper; + this.peerMapper = peerMapper; + } + + private readonly HostDatabaseMapper hostMapper; + private readonly PeerDatabaseMapper peerMapper; + + protected override bool UseCache { + get { return true; } + } + + protected override string TableName { + get { return "peerActivity"; } + } + + protected override string CreateSql { + get { + return + "CREATE TABLE peerActivity ( " + + " id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " + + " lastActive TIMESTAMP NOT NULL, " + + " hostId INT NOT NULL, " + + " peerId INT NOT NULL, " + + " FOREIGN KEY (hostId) REFERENCES host(id), " + + " FOREIGN KEY (peerId) REFERENCES peer(id) " + + ") ENGINE=INNODB;"; + } + } + + private const string selectSql = + "SELECT id, lastActive, hostId, peerId FROM peerActivity"; + private const string insertSql = + "INSERT INTO peerActivity(lastActive, hostId, peerId) " + + "VALUES(@lastActive, @hostId, @peerId);" + + "SELECT LAST_INSERT_ID();"; + private const string updateSql = + "UPDATE peerActivity SET lastActive = @lastActive WHERE id=@id"; + + protected override void Insert (PeerActivity item) + { + lock (Locker) { + try { + Open (); + + Command.CommandText = insertSql; + Command.Prepare (); + + Command.Parameters.AddWithValue ("@lastActive", item.LastActive); + Command.Parameters.AddWithValue ("@hostId", item.Host.Id); + Command.Parameters.AddWithValue ("@peerId", item.Peer.Id); + + object idObject = Command.ExecuteScalar (); + item.SetId (Convert.ToInt32 (idObject)); + } finally { + Close (); + } + } + } + + protected override void Update (PeerActivity item) + { + lock (Locker) { + try { + Open (); + + Command.CommandText = updateSql; + Command.Prepare (); + + Command.Parameters.AddWithValue ("@lastActive", item.LastActive); + Command.Parameters.AddWithValue ("@id", item.Id); + Command.ExecuteNonQuery (); + } finally { + Close (); + } + } + } + + /// + /// Read all data from table in a sequential manner. + /// + /// The enumerator. + public override IEnumerator GetEnumerator () + { + IEnumerator result = null; + + lock (Locker) { + if (HasContent) + result = Content.GetEnumerator (); + else { + try { + Open (); + Command.CommandText = selectSql; + Reader = Command.ExecuteReader (); + + while (Reader.Read ()) { + int id = Convert.ToInt32 (Reader ["id"]); + DateTime time = Convert.ToDateTime (Reader ["lastActive"]); + int hostId = Convert.ToInt32 (Reader ["hostId"]); + Host host = hostMapper [hostId]; + int peerId = Convert.ToInt32 (Reader ["peerId"]); + Peer peer = peerMapper [peerId]; + PeerActivity item = new PeerActivity (id, peer, host, time); + AddItem (item); + } + } finally { + Close (); + } + result = Content.GetEnumerator (); + } + } + + return result; + } + } +} \ No newline at end of file diff --git a/Ntp.Analyzer.Data/Static/PeerDatabaseMapper.cs b/Ntp.Analyzer.Data/Static/PeerDatabaseMapper.cs index a24f2610..3e1c4ef6 100644 --- a/Ntp.Analyzer.Data/Static/PeerDatabaseMapper.cs +++ b/Ntp.Analyzer.Data/Static/PeerDatabaseMapper.cs @@ -23,6 +23,7 @@ // 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 MySql.Data.MySqlClient; @@ -123,39 +124,38 @@ namespace Ntp.Analyzer.Data.Static /// The enumerator. public override IEnumerator GetEnumerator () { + IEnumerator result = null; + lock (Locker) { + if (HasContent) + result = Content.GetEnumerator (); + else { + try { + Open (); + Command.CommandText = selectSql; + Reader = Command.ExecuteReader (); - if (HasContent) { - foreach (Peer item in Content) - yield return item; - - yield break; - } - - try { - Open (); - Command.CommandText = selectSql; - Reader = Command.ExecuteReader (); - - while (Reader.Read ()) { - int id = Convert.ToInt32 (Reader ["id"]); - string name = Reader ["name"].ToString (); - string ip = Reader ["ip"].ToString (); - int? orgId = Reader ["orgId"] != DBNull.Value ? + while (Reader.Read ()) { + int id = Convert.ToInt32 (Reader ["id"]); + string name = Reader ["name"].ToString (); + string ip = Reader ["ip"].ToString (); + int? orgId = Reader ["orgId"] != DBNull.Value ? (int?)Convert.ToInt32 (Reader ["orgId"]) : (int?)null; - TimeServer server = orgId.HasValue ? + TimeServer server = orgId.HasValue ? timeServerMapper [orgId.Value] : null; - Peer peer = new Peer (id, name, ip, server); - AddItem (peer); - - yield return peer; + Peer peer = new Peer (id, name, ip, server); + AddItem (peer); + } + } finally { + Close (); } - } finally { - Close (); + result = Content.GetEnumerator (); } } + + return result; } } } \ No newline at end of file diff --git a/Ntp.Analyzer.Gui/Ntp.Analyzer.Gui.csproj b/Ntp.Analyzer.Gui/Ntp.Analyzer.Gui.csproj index d567e130..c8feec84 100644 --- a/Ntp.Analyzer.Gui/Ntp.Analyzer.Gui.csproj +++ b/Ntp.Analyzer.Gui/Ntp.Analyzer.Gui.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.Analyzer.Localize/ConfigurationKeyword.cs b/Ntp.Analyzer.Localize/ConfigurationKeyword.cs new file mode 100644 index 00000000..74c211ba --- /dev/null +++ b/Ntp.Analyzer.Localize/ConfigurationKeyword.cs @@ -0,0 +1,158 @@ +// +// ConfigurationKeyword.cs +// +// Author: +// Carsten Sonne Larsen +// +// Copyright (c) 2016 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. + +namespace Ntp.Analyzer.Localize +{ + public class ConfigurationKeyword + { + public const string Server = "Server"; + public const string ServerHostId = "HostID"; + public const string ServerHostAddress = "HostAddress"; + public const string ServerHostType = "HostType"; + public const string ServerFilePath = "FilePath"; + public const string ServerWebPath = "WebPath"; + + public const string ServerTypeNtpdc = "ntpdc"; + public const string ServerTypeNtpq = "ntpq"; + public const string ServerTypeUnknown = "unknown"; + + public const string Database = "Database"; + public const string DatabaseHost = "Host"; + public const string DatabaseName = "Name"; + public const string DatabaseUser = "User"; + public const string DatabasePass = "Pass"; + public const string DatabaseCreate = "Create"; + + public const string Listener = "Listener"; + public const string ListenerIp = "IP"; + public const string ListenerPort = "Port"; + + public const string Cluster = "Cluster"; + public const string ClusterNode = "Node"; + public const string ClusterNodeIp = "IP"; + public const string ClusterNodePort = "Port"; + + public const string HostStats = "HostStats"; + public const string HostIOStats = "HostIOStats"; + public const string PeerStats = "PeerStats"; + + public const string Reading = "Reading"; + public const string ReadingName = "Name"; + public const string InitialRun = "InitialRun"; + public const string FixedRun = "FixedRun"; + public const string Frequency = "Frequency"; + + public const string Notify = "Notify"; + public const string NotifyRecipient = "Mail"; + public const string NotifySubject = "Subject"; + public const string NotifySender = "Sender"; + public const string NotifySmtpHost = "SmtpHost"; + public const string NotifySmtpPort = "SmtpPort"; + public const string NotifySmtpUser = "SmtpUser"; + public const string NotifySmtpPass = "SmtpPass"; + public const string NotifyEnableSsl = "EnableSsl"; + + public const string GraphTitle = "Title"; + public const string GraphWidth = "Width"; + public const string GraphHeight = "Height"; + public const string GraphTimespan = "Timespan"; + public const string GraphFilterFactor = "FilterFactor"; + public const string GraphJitter = "Jitter"; + public const string GraphOffset = "Offset"; + + public const string HostGraph = "HostGraph"; + public const string HostGraphGFrequency = "GFrequency"; + public const string HostGraphStability = "Stability"; + + public const string PeerGraph = "PeerGraphs"; + public const string PeerGraphBalance = "Balance"; + public const string PeerGraphDelay = "Delay"; + + public const string TrafficGraph = "TrafficGraph"; + public const string TrafficGraphReceived = "Received"; + public const string TrafficGraphIgnored = "Ignored"; + public const string TrafficGraphDropped = "Dropped"; + public const string TrafficGraphSent = "Sent"; + public const string TrafficGraphNotSent = "NotSent"; + public const string TrafficGraphAvgReceived = "AvgReceived"; + public const string TrafficGraphAvgIgnored = "AvgIgnored"; + public const string TrafficGraphAvgDropped = "AvgDropped"; + public const string TrafficGraphAvgSent = "AvgSent"; + public const string TrafficGraphAvgNotSent = "AvgNotSent"; + public const string TrafficGraphPlotInterval = "PlotInterval"; + public const string TrafficGraphPacketRate = "PacketRate"; + + public const string PageTitle = "PageTitle"; + public const string PageTemplate = "Template"; + public const string PageLink = "Link"; + + public const string GraphPage = "GraphPage"; + public const string LinkIndex = "LinkIndex"; + + public const string AboutPage = "AboutPage"; + public const string AboutPageServerId ="ServerID"; + public const string AboutPageContentTitle ="ContentTitle"; + public const string AboutPageContent = "Content"; + + public const string HostPage = "HostPage"; + public const string HostPagePoolMember = "PoolMember"; + + public const string HostGraphPage = "HostGraphPage"; + public const string PeerGraphPage = "PeerGraphPage"; + public const string PeerPages = "PeerPages"; + public const string PeerSummaryPage = "PeerSummaryPage"; + public const string Summaries = "Summaries"; + + public const string Menu = "Menu"; + public const string MenuItem = "Item"; + public const string MenuItemType = "Type"; + public const string MenuItemCaption = "Caption"; + public const string MenuItemLink = "Link"; + public const string MenuItemPage = "Page"; + public const string MenuItemDropdown = "Dropdown"; + public const string MenuItemDropdownContent = "Content"; + + public const string MenuItemTypeSpacer = "Spacer"; + public const string MenuItemTypeHeader = "Header"; + public const string MenuItemTypeName = "Name"; + + public const string GraphSet = "Images"; + public const string GraphSetTitle = "Title"; + public const string GraphSetItem = "Graph"; + + public const string DirectoryDestinations = "Destinations"; + public const string DirectoryPrefix = "Prefix"; + public const string DirectoryItem = "Directory"; + + public const string FileDestinations = "Destinations"; + public const string FileItem = "File"; + + public const string WebLinks = "Links"; + public const string WebLinkItem = "Link"; + + public const string NtpAccessPolicyOpen = "OpenAccess"; + } +} \ No newline at end of file diff --git a/Ntp.Analyzer.Localize/ConfigurationMessage.cs b/Ntp.Analyzer.Localize/ConfigurationMessage.cs new file mode 100644 index 00000000..0aca1392 --- /dev/null +++ b/Ntp.Analyzer.Localize/ConfigurationMessage.cs @@ -0,0 +1,52 @@ +// +// ConfigurationMessage.cs +// +// Author: +// Carsten Sonne Larsen +// +// Copyright (c) 2016 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. + +namespace Ntp.Analyzer.Localize +{ + public static class ConfigurationMessage + { + public const string DatabaseMissing = "Database section is missing."; + public const string NoValueForSetting = "No value for setting {0} in section {1} was specified."; + public const string InvalidValue = "Invalid value for setting {0} in section {1}. Specify either ntpq or ntpdc."; + public const string UnknownMenuItem = "Unknown menu item type {0}"; + + public const string HostGraphLinkIndex1 = "LinkIndex out of range while getting host graph link [{0}]."; + public const string HostGraphLinkIndex2 = "LinkIndex out of range while getting host graph alt name [{0}]."; + public const string PeerGraphLinkIndex = "LinkIndex out of range while getting peer graph link [{0}]."; + public const string TrafficGraphLinkIndex1 = "LinkIndex out of range while getting traffic graph link [{0}]."; + public const string TrafficGraphLinkIndex2 = "LinkIndex out of range while getting traffic graph alt name [{0}]."; + + public const string MissingReference = "Cannot find {0} {1} specified in {2}"; + public const string WrongReference = "{0} in {1} {2} is not defined correctly."; + public const string ConfiguredGraphs = "Known graphs:"; + public const string ConfiguredPeerPages = "Known peer pages:"; + public const string ConfiguredGraphPages = "Known graph pages:"; + public const string ConfiguredPeerSummaryPages = "Known peer summary pages:"; + public const string ConfiguredPages = "Known pages:"; + + public const string AboutPageContentMissing = "About page does not contain a Content section."; + } +} \ No newline at end of file diff --git a/Ntp.Analyzer.Localize/LogMessage.cs b/Ntp.Analyzer.Localize/LogMessage.cs new file mode 100644 index 00000000..46cce31a --- /dev/null +++ b/Ntp.Analyzer.Localize/LogMessage.cs @@ -0,0 +1,38 @@ +// +// LogMessage.cs +// +// Author: +// Carsten Sonne Larsen +// +// Copyright (c) 2016 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. + +namespace Ntp.Analyzer.Localize +{ + public static class LogMessage + { + public const string HostNotFound = "Host with ID {0} does not exists in database."; + public const string PeerIpNotFound = "Peer with IP {0} does not exists in database."; + public const string PeerIpAmbiguous = "Ambiguous peer IP {0}. Multiple occurrences found in database."; + + public const string HostImportError = "Could not import host data {0}"; + public const string PeerImportError = "Could not import peer data {0}"; + } +} \ No newline at end of file diff --git a/Ntp.Analyzer.Localize/Ntp.Analyzer.Localize.csproj b/Ntp.Analyzer.Localize/Ntp.Analyzer.Localize.csproj new file mode 100644 index 00000000..10fcf2a6 --- /dev/null +++ b/Ntp.Analyzer.Localize/Ntp.Analyzer.Localize.csproj @@ -0,0 +1,51 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {6F200007-52DB-4861-A565-124270C07F67} + Library + Ntp.Analyzer.Localize + Ntp.Analyzer.Localize + 0.4.2b + + + true + full + false + ..\bin\ + DEBUG; + prompt + 4 + false + + + full + true + ..\bin\ + prompt + 4 + false + + + true + ..\bin\ + 4 + + + false + bin\Develop + 4 + + + + + + + + + + + \ No newline at end of file diff --git a/Ntp.Analyzer.Localize/PageText.cs b/Ntp.Analyzer.Localize/PageText.cs new file mode 100644 index 00000000..e77fe88c --- /dev/null +++ b/Ntp.Analyzer.Localize/PageText.cs @@ -0,0 +1,49 @@ +// +// PageText.cs +// +// Author: +// Carsten Sonne Larsen +// +// Copyright (c) 2016 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. + +namespace Ntp.Analyzer.Localize +{ + public static class PageText + { + public const string HtmlBlank = " "; + public const string UnknownLocation = "Unknown"; + + public const string Stratum1 = "one"; + public const string Stratum2 = "two"; + public const string Stratum3 = "three"; + public const string Stratum4 = "four"; + public const string Stratum5 = "five"; + public const string Stratum6 = "six"; + public const string Stratum7 = "seven"; + + public const string AccessPolicyOpen = "Open access"; + public const string AccessPolicyUnknown = "Unknown"; + + public const string PoolMemberYes = "Server is pool member"; + public const string PoolMemberNo = "Server is not a pool member"; + public const string PoolMemberLink = "http://www.pool.ntp.org/scores/"; + } +} \ No newline at end of file diff --git a/Ntp.Analyzer.Localize/Properties/AssemblyInfo.cs b/Ntp.Analyzer.Localize/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..c6d321b0 --- /dev/null +++ b/Ntp.Analyzer.Localize/Properties/AssemblyInfo.cs @@ -0,0 +1,52 @@ +// +// AssemblyInfo.cs +// +// Author: +// Carsten Sonne Larsen +// +// Copyright (c) 2016 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.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("Ntp.Localize")] +[assembly: AssemblyDescription ("Localization library used with NTP Analyzer")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany("Innolan IT")] +[assembly: AssemblyProduct("NTP Analyzer Localization Library")] +[assembly: AssemblyCopyright("Carsten Sonne Larsen ")] +[assembly: AssemblyTrademark("NTP Analyzer")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Ntp.System/VersionInfo.cs b/Ntp.Analyzer.Localize/VersionInfo.cs similarity index 93% rename from Ntp.System/VersionInfo.cs rename to Ntp.Analyzer.Localize/VersionInfo.cs index 6c982469..e8388061 100644 --- a/Ntp.System/VersionInfo.cs +++ b/Ntp.Analyzer.Localize/VersionInfo.cs @@ -23,14 +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; -namespace Ntp.System +namespace Ntp.Analyzer.Localize { public static class VersionInfo { - public static readonly string Number = "0.4.2b"; + public static readonly string Number = "0.4.3b"; public static readonly string Text = "v" + Number; } -} +} \ No newline at end of file diff --git a/Ntp.Analyzer.Log/Ntp.Analyzer.Log.csproj b/Ntp.Analyzer.Log/Ntp.Analyzer.Log.csproj index b1e812c0..3b2cf61c 100644 --- a/Ntp.Analyzer.Log/Ntp.Analyzer.Log.csproj +++ b/Ntp.Analyzer.Log/Ntp.Analyzer.Log.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.Analyzer.Objects/Ntp.Analyzer.Objects.csproj b/Ntp.Analyzer.Objects/Ntp.Analyzer.Objects.csproj index 73b3c118..df857d97 100644 --- a/Ntp.Analyzer.Objects/Ntp.Analyzer.Objects.csproj +++ b/Ntp.Analyzer.Objects/Ntp.Analyzer.Objects.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + @@ -63,6 +68,7 @@ + diff --git a/Ntp.Analyzer.Objects/PeerActivity.cs b/Ntp.Analyzer.Objects/PeerActivity.cs new file mode 100644 index 00000000..5e37da84 --- /dev/null +++ b/Ntp.Analyzer.Objects/PeerActivity.cs @@ -0,0 +1,78 @@ +// +// PeerActivity.cs +// +// Author: +// Carsten Sonne Larsen +// +// Copyright (c) 2013-2016 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; + +namespace Ntp.Analyzer.Objects +{ + public sealed class PeerActivity : PersistentObject + { + public PeerActivity(int id, Peer peer, Host host, DateTime lastActive) + : base(id) + { + this.peer = peer; + this.host = host; + this.lastActive = lastActive; + } + + public PeerActivity(Peer peer, Host host, DateTime lastActive) + { + this.peer = peer; + this.host = host; + this.lastActive = lastActive; + } + + private readonly Peer peer; + private readonly Host host; + private DateTime lastActive; + + public string Name { + get { + return Id.ToString (); + } + } + + public Peer Peer { + get { return peer; } + } + + public Host Host { + get { return host; } + } + + public DateTime LastActive { + get { return lastActive; } + set { lastActive = value; } + } + + public bool IsActive { + get { + // TODO + return true; //Math.Abs(DateTime.Now.Subtract (lastActive).TotalHours) <= 1.0; + } + } + } +} \ No newline at end of file diff --git a/Ntp.Analyzer.Objects/PersistentObject.cs b/Ntp.Analyzer.Objects/PersistentObject.cs index 3b61d59d..ae602aa1 100644 --- a/Ntp.Analyzer.Objects/PersistentObject.cs +++ b/Ntp.Analyzer.Objects/PersistentObject.cs @@ -23,6 +23,7 @@ // 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; namespace Ntp.Analyzer.Objects { @@ -88,6 +89,22 @@ namespace Ntp.Analyzer.Objects newObject = false; } + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + if (obj.GetType () != GetType ()) + return false; + + return id == ((PersistentObject)obj).Id; + } + + public override int GetHashCode() + { + return (int)(id * 2654435761 % 2 ^ 32); + } + /// /// Returns a that represents the current . /// diff --git a/Ntp.Analyzer.Objects/StatusLine.cs b/Ntp.Analyzer.Objects/StatusLine.cs index 8889554c..2556190d 100644 --- a/Ntp.Analyzer.Objects/StatusLine.cs +++ b/Ntp.Analyzer.Objects/StatusLine.cs @@ -23,69 +23,34 @@ // 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 Ntp.Analyzer.Objects.Live; namespace Ntp.Analyzer.Objects { /// - /// A status line for an NTP Server containing information about configuration, peer and server details. + /// A status line for an NTP Server containing information about configuration, + /// peer and server details. /// public sealed class StatusLine { - private readonly NtpConfEntry conf; - private readonly AssociationEntry peer; - private readonly TimeServer server; - private readonly int? id; - - /// - /// Initializes a new instance of the class. - /// - /// Peer. - /// Conf. - /// Server. - /// Peer ID. - public StatusLine(AssociationEntry peer, NtpConfEntry conf, TimeServer server, int? id) + public StatusLine(AssociationEntry peer, PeerActivity peerActivity) { this.peer = peer; - this.conf = conf; - this.server = server; - this.id = id; + this.peerActivity = peerActivity; } - /// - /// Gets the peer for this line. - /// - /// The peer. + private readonly AssociationEntry peer; + private readonly PeerActivity peerActivity; + public AssociationEntry Peer { get { return peer; } } - - /// - /// Gets the local configuration for this line - /// - /// The conf. - public NtpConfEntry Conf + + public PeerActivity PeerActivity { - get { return conf; } - } - - /// - /// Gets the peer server descriptor for this line. - /// - /// The server. - public TimeServer Server - { - get { return server; } - } - - /// - /// Gets the optional peer ID for this line. - /// - /// The peer ID. - public int? PeerId - { - get { return id; } + get { return peerActivity; } } } } \ No newline at end of file diff --git a/Ntp.Analyzer.Process/Description/BulkStatJob.cs b/Ntp.Analyzer.Process/Description/BulkStatJob.cs index 05488139..a9f242c9 100644 --- a/Ntp.Analyzer.Process/Description/BulkStatJob.cs +++ b/Ntp.Analyzer.Process/Description/BulkStatJob.cs @@ -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 Ntp.Analyzer.Config; +using Ntp.Analyzer.Config.Root; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Process; -using Ntp.Analyzer.Config.Root; namespace Ntp.Analyzer.Process.Description { diff --git a/Ntp.Analyzer.Process/Description/HostGraphJob.cs b/Ntp.Analyzer.Process/Description/HostGraphJob.cs index 4bab1171..8bfee501 100644 --- a/Ntp.Analyzer.Process/Description/HostGraphJob.cs +++ b/Ntp.Analyzer.Process/Description/HostGraphJob.cs @@ -29,6 +29,7 @@ using System.Linq; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Data; using Ntp.Analyzer.Graph; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; @@ -63,9 +64,7 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); return; } diff --git a/Ntp.Analyzer.Process/Description/HostGraphPageJob.cs b/Ntp.Analyzer.Process/Description/HostGraphPageJob.cs index d8fed90a..6f0d5360 100644 --- a/Ntp.Analyzer.Process/Description/HostGraphPageJob.cs +++ b/Ntp.Analyzer.Process/Description/HostGraphPageJob.cs @@ -30,6 +30,7 @@ using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Page; using Ntp.Analyzer.Data; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Analyzer.Page; @@ -65,9 +66,7 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); return; } diff --git a/Ntp.Analyzer.Process/Description/HostIOStatJob.cs b/Ntp.Analyzer.Process/Description/HostIOStatJob.cs index 5d39632d..24d10863 100644 --- a/Ntp.Analyzer.Process/Description/HostIOStatJob.cs +++ b/Ntp.Analyzer.Process/Description/HostIOStatJob.cs @@ -23,12 +23,14 @@ // 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.Net; using Ntp.Analyzer.Config.Stats; using Ntp.Analyzer.Data; using Ntp.Analyzer.Data.Live; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Analyzer.Objects.Live; @@ -63,9 +65,7 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); return; } diff --git a/Ntp.Analyzer.Process/Description/HostPageJob.cs b/Ntp.Analyzer.Process/Description/HostPageJob.cs index 44b60034..39789303 100644 --- a/Ntp.Analyzer.Process/Description/HostPageJob.cs +++ b/Ntp.Analyzer.Process/Description/HostPageJob.cs @@ -24,10 +24,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; using System.IO; +using System.Linq; using Ntp.Analyzer.Config.Navigation; using Ntp.Analyzer.Config.Page; +using Ntp.Analyzer.Data; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; +using Ntp.Analyzer.Objects; using Ntp.Analyzer.Page; using Ntp.Analyzer.Statistics; @@ -61,14 +66,17 @@ namespace Ntp.Analyzer.Process.Description protected override void InternalExecute() { - // Build status objects - StatusBuilder builder = new StatusBuilder( - new ServerName(page.ServerName), - new FileInfo(page.ConfigFile)); + Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == page.HostId); + + if (host == null) { + Log.WriteLine (String.Format (LogMessage.HostNotFound, page.HostId), Severity.Warn); + return; + } + + StatusBuilder builder = new StatusBuilder (new ServerName (page.ServerName), host); builder.Build(); PageBuilderBase pageBuilder; - if (page.Theme == "bootstrap") pageBuilder = new BootstrapHostPageBuilder(menu, page, builder.Entries.ToArray()); else diff --git a/Ntp.Analyzer.Process/Description/HostStatJob.cs b/Ntp.Analyzer.Process/Description/HostStatJob.cs index 369d78e0..dc5c2e79 100644 --- a/Ntp.Analyzer.Process/Description/HostStatJob.cs +++ b/Ntp.Analyzer.Process/Description/HostStatJob.cs @@ -23,12 +23,14 @@ // 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.Net; using Ntp.Analyzer.Config.Stats; using Ntp.Analyzer.Data; using Ntp.Analyzer.Data.Live; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Process; @@ -65,21 +67,19 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); return; } + // Import from NTP daemon HostValueImporter imp; try { - // Import from NTP daemon imp = config.ServerType == ServerType.Ntpdc ? (HostValueImporter)(new NtpdcImporter (config.ServerName, host, ReadingBulk.Current, Log)) : (HostValueImporter)(new NtpqHostImporter (config.ServerName, host, ReadingBulk.Current, Log)); imp.Import (); } catch (Exception e) { - Log.WriteLine ("Could not get data from NTP daemon: " + e.Message, Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostImportError, e.Message), Severity.Warn); Log.WriteLine (e, Severity.Trace); return; } diff --git a/Ntp.Analyzer.Process/Description/NotifyJob.cs b/Ntp.Analyzer.Process/Description/NotifyJob.cs index 2ee7de98..f1de5b82 100644 --- a/Ntp.Analyzer.Process/Description/NotifyJob.cs +++ b/Ntp.Analyzer.Process/Description/NotifyJob.cs @@ -23,6 +23,7 @@ // 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.Collections.Generic; using System.Globalization; using System.Net; diff --git a/Ntp.Analyzer.Process/Description/PeerGraphJob.cs b/Ntp.Analyzer.Process/Description/PeerGraphJob.cs index e9a32302..42d12347 100644 --- a/Ntp.Analyzer.Process/Description/PeerGraphJob.cs +++ b/Ntp.Analyzer.Process/Description/PeerGraphJob.cs @@ -30,6 +30,7 @@ using System.Linq; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Data; using Ntp.Analyzer.Graph; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; @@ -64,34 +65,16 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); return; } - foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[config.ConfigFile]) - { - IEnumerable peers = DataFace.Instance.Peers.Where(p => p.Ip == entry.Address.ToString()); - if (peers.Count() == 0) - { - Log.WriteLine("Peer not found in database: " + entry.Name, Severity.Warn); - continue; - } - else if (peers.Count() > 1) - { - Log.WriteLine("Ambiguous peer IP. Multiple occurrences found in database: " + entry.Name, Severity.Warn); - continue; - } + var peers = DataFace.Instance.PeerActivity. + Where (p => p.Host == host && p.IsActive); - Peer peer = peers.Single(); - - PeerGraph graph = new PeerGraph(config, host, peer); - - string name = peer.Server != null ? peer.Server.Name : peer.Name; - string file = name.Replace('.', '-') + ".png"; - - SaveStream(graph, file); + foreach (PeerActivity entry in peers) { + PeerGraph graph = new PeerGraph (config, host, entry.Peer); + SaveStream (graph, String.Concat (entry.Name, ".", graph.ImageFileExtension)); } } } diff --git a/Ntp.Analyzer.Process/Description/PeerGraphPageJob.cs b/Ntp.Analyzer.Process/Description/PeerGraphPageJob.cs index edf2bc7e..0bd0da0a 100644 --- a/Ntp.Analyzer.Process/Description/PeerGraphPageJob.cs +++ b/Ntp.Analyzer.Process/Description/PeerGraphPageJob.cs @@ -31,6 +31,7 @@ using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Page; using Ntp.Analyzer.Data; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Analyzer.Page; @@ -66,37 +67,19 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); return; } - foreach (GraphSetConfiguration graphSet in config.GraphSets) - { - foreach (GraphBaseConfiguration graph in graphSet.Graphs) - { - foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[config.ConfigFile]) - { - IEnumerable peers = DataFace.Instance.Peers.Where(p => p.Ip == entry.Address.ToString()); - if (peers.Count() == 0) - { - Log.WriteLine("Peer not found in database: " + entry.Name, Severity.Warn); - continue; - } - else if (peers.Count() > 1) - { - Log.WriteLine("Ambiguous peer IP. Multiple occurrences found in database: " + entry.Name, Severity.Warn); - continue; - } + var peers = DataFace.Instance.PeerActivity. + Where (p => p.Host == host && p.IsActive); - Peer peer = peers.Single(); - - string name = peer.Server != null ? peer.Server.Name : peer.Name; - GraphPageBuilder builder = new GraphPageBuilder(config, peer, name, graphSet, graph); - string file = config.GetFileName(host, name, graphSet, graph); - - SaveStream(builder, file); + foreach (PeerActivity entry in peers) { + foreach (GraphSetConfiguration graphSet in config.GraphSets) { + foreach (GraphBaseConfiguration graph in graphSet.Graphs) { + GraphPageBuilder builder = new GraphPageBuilder (config, entry.Peer, entry.Name, graphSet, graph); + string file = config.GetFileName (host, entry.Name, graphSet, graph); + SaveStream (builder, file); } } } diff --git a/Ntp.Analyzer.Process/Description/PeerPageJob.cs b/Ntp.Analyzer.Process/Description/PeerPageJob.cs index 7f5f2a60..0ff9e0ea 100644 --- a/Ntp.Analyzer.Process/Description/PeerPageJob.cs +++ b/Ntp.Analyzer.Process/Description/PeerPageJob.cs @@ -31,6 +31,7 @@ using System.Linq; using Ntp.Analyzer.Config.Navigation; using Ntp.Analyzer.Config.Page; using Ntp.Analyzer.Data; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Analyzer.Page; @@ -71,43 +72,22 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == page.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", page.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, page.HostId), Severity.Warn); return; } - foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[page.ConfigFile]) - { - IEnumerable peers = DataFace.Instance.Peers.Where(p => p.Ip == entry.Address.ToString()); - if (peers.Count() == 0) - { - Log.WriteLine("Peer not found in database. Creating peer: " + entry.Name, Severity.Warn); - - TimeServer server = DataFace.Instance.Servers[entry.OrgId.Value]; - Peer newPeer = new Peer(entry.Name, entry.Address.ToString(), server); - DataFace.Instance.Peers.Save(newPeer); - - peers = (new List {newPeer}).ToList(); - } - else if (peers.Count() > 1) - { - Log.WriteLine("Ambiguous peer IP. Multiple occurrences found in database: " + entry.Name, Severity.Warn); - continue; - } - - Peer peer = peers.Single(); + var peers = DataFace.Instance.PeerActivity. + Where (p => p.Host == host && p.IsActive); + foreach (PeerActivity entry in peers) { PageBuilderBase peerPageBuilder; if (page.Theme == "bootstrap") - peerPageBuilder = new BootstrapPeerPageBuilder(host, peer, menu, page); + peerPageBuilder = new BootstrapPeerPageBuilder (host, entry.Peer, menu, page); else - peerPageBuilder = new DefaultPeerPageBuilder(peer, page); - - string name = peer.OrgId.HasValue ? - peer.OrgId.Value.ToString (CultureInfo.InvariantCulture) : peer.Name; - SaveStream(peerPageBuilder, name + ".html"); + peerPageBuilder = new DefaultPeerPageBuilder (entry.Peer, page); + + SaveStream (peerPageBuilder, entry.Name + ".html"); } } } diff --git a/Ntp.Analyzer.Process/Description/PeerStatJob.cs b/Ntp.Analyzer.Process/Description/PeerStatJob.cs index ac16ca0b..30d473d3 100644 --- a/Ntp.Analyzer.Process/Description/PeerStatJob.cs +++ b/Ntp.Analyzer.Process/Description/PeerStatJob.cs @@ -23,12 +23,14 @@ // 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 System.Net; using Ntp.Analyzer.Config.Stats; using Ntp.Analyzer.Data; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; using Ntp.Analyzer.Objects.Live; @@ -46,10 +48,12 @@ namespace Ntp.Analyzer.Process.Description { this.config = config; this.readings = new List (); + this.activities = new List (); } private readonly PeerStatConfiguration config; private readonly List readings; + private readonly List activities; private Host host; private List peers; @@ -72,7 +76,7 @@ namespace Ntp.Analyzer.Process.Description Import (); SaveResult (); } catch (Exception e) { - Log.WriteLine ("Could not import peer data: " + e.Message, Severity.Warn); + Log.WriteLine (String.Format (LogMessage.PeerImportError, e.Message), Severity.Warn); Log.WriteLine (e, Severity.Trace); } } @@ -83,18 +87,14 @@ namespace Ntp.Analyzer.Process.Description private void Initalize () { // Clear any previouse readings - readings.Clear(); + readings.Clear (); + activities.Clear (); - // Get peers from database. peers = DataFace.Instance.Peers.ToList (); - - // Find host in database. host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); - if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + if (host == null) { + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); } } @@ -112,14 +112,10 @@ namespace Ntp.Analyzer.Process.Description if (peerList.Count () == 1) { peer = peerList.Single (); } else if (peerList.Count () == 0) { - Log.WriteLine (String.Format ( - "Peer with IP {0} was not found in database.", entry.Remote), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.PeerIpNotFound, entry.Remote), Severity.Warn); continue; } else { - Log.WriteLine (String.Format ( - "Found more than on peer with IP {0} in database.", entry.Remote), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.PeerIpAmbiguous, entry.Remote), Severity.Warn); continue; } @@ -134,6 +130,17 @@ namespace Ntp.Analyzer.Process.Description entry.Jitter); readings.Add (reading); + + PeerActivity activity = DataFace.Instance.PeerActivity. + SingleOrDefault (a => a.Host == reading.Host && a.Peer == reading.Peer); + + if (activity != null) { + activity.LastActive = ReadingBulk.Current.Time; + } else { + activity = new PeerActivity (reading.Peer, host, ReadingBulk.Current.Time); + } + + activities.Add (activity); } } @@ -145,6 +152,10 @@ namespace Ntp.Analyzer.Process.Description foreach (PeerReading reading in readings) { DataFace.Instance.PeerReadings.Save (reading); } + + foreach (PeerActivity activity in activities) { + DataFace.Instance.PeerActivity.Save (activity); + } } } } \ No newline at end of file diff --git a/Ntp.Analyzer.Process/Description/StreamJob.cs b/Ntp.Analyzer.Process/Description/StreamJob.cs index f0a415a4..6b375e62 100644 --- a/Ntp.Analyzer.Process/Description/StreamJob.cs +++ b/Ntp.Analyzer.Process/Description/StreamJob.cs @@ -23,6 +23,7 @@ // 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.IO; using Ntp.Analyzer.Config; using Ntp.Analyzer.Export; diff --git a/Ntp.Analyzer.Process/Description/TrafficGraphJob.cs b/Ntp.Analyzer.Process/Description/TrafficGraphJob.cs index d7ec7a67..cf314e81 100644 --- a/Ntp.Analyzer.Process/Description/TrafficGraphJob.cs +++ b/Ntp.Analyzer.Process/Description/TrafficGraphJob.cs @@ -29,6 +29,7 @@ using System.Linq; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Data; using Ntp.Analyzer.Graph; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; using Ntp.Analyzer.Objects; @@ -63,9 +64,7 @@ namespace Ntp.Analyzer.Process.Description Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId); if (host == null) { - Log.WriteLine (String.Format ( - "Host with ID {0} was not found in database. ", config.HostId), - Severity.Warn); + Log.WriteLine (String.Format (LogMessage.HostNotFound, config.HostId), Severity.Warn); return; } diff --git a/Ntp.Analyzer.Process/Initializer.cs b/Ntp.Analyzer.Process/Initializer.cs index 9c4fd811..95c4f182 100644 --- a/Ntp.Analyzer.Process/Initializer.cs +++ b/Ntp.Analyzer.Process/Initializer.cs @@ -23,27 +23,29 @@ // 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 System.IO; +using System.Linq; +using System.Net; using System.Threading; using Ntp.Analyzer.Config; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Page; +using Ntp.Analyzer.Config.Root; using Ntp.Analyzer.Data; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Log; +using Ntp.Analyzer.Objects; +using Ntp.Analyzer.Objects.Live; using Ntp.Config; +using Ntp.Interop; +using Ntp.Monitor.Client; using Ntp.Monitor.Server; using Ntp.Process; using Ntp.Analyzer.Process.Description; -using Ntp.Analyzer.Config.Root; -using Ntp.Monitor.Client; -using System.Net; -using Ntp.System; -using Ntp.Analyzer.Objects; -using System.Linq; -using Ntp.Analyzer.Objects.Live; namespace Ntp.Analyzer.Process { diff --git a/Ntp.Analyzer.Process/Ntp.Analyzer.Process.csproj b/Ntp.Analyzer.Process/Ntp.Analyzer.Process.csproj index 57a4d2e1..73dd3f79 100644 --- a/Ntp.Analyzer.Process/Ntp.Analyzer.Process.csproj +++ b/Ntp.Analyzer.Process/Ntp.Analyzer.Process.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + @@ -99,9 +104,13 @@ {44D739DA-4CD4-4214-88EE-A9A293BB32B5} Ntp.Monitor.Client - + {A98DB601-2993-4181-A573-5FCCC5E954C1} - Ntp.System + Ntp.Interop + + + {6F200007-52DB-4861-A565-124270C07F67} + Ntp.Analyzer.Localize \ No newline at end of file diff --git a/Ntp.Analyzer.Validate.Cli/Ntp.Analyzer.Validate.Cli.csproj b/Ntp.Analyzer.Validate.Cli/Ntp.Analyzer.Validate.Cli.csproj index a7debf26..15fe5285 100644 --- a/Ntp.Analyzer.Validate.Cli/Ntp.Analyzer.Validate.Cli.csproj +++ b/Ntp.Analyzer.Validate.Cli/Ntp.Analyzer.Validate.Cli.csproj @@ -10,7 +10,6 @@ Ntp.Analyzer.Validate.Cli 0.4.2b Ntp.Analyzer.Validate.Cli.Program - ntpav true @@ -21,7 +20,8 @@ prompt 4 true - --verbose ~/code/ntpa/example/ntpa.web.small.conf + --show ~/code/ntpa/example/ntpa.web.conf + ntpav full @@ -30,11 +30,19 @@ prompt 4 true + ntpav true ..\bin\ 4 + ntpav + + + false + bin\Develop + 4 + Ntp.Analyzer.Validate.Cli @@ -53,9 +61,13 @@ {43A1A769-6ED9-4AE1-821A-43F97814968C} Ntp.Config - + {A98DB601-2993-4181-A573-5FCCC5E954C1} - Ntp.System + Ntp.Interop + + + {6F200007-52DB-4861-A565-124270C07F67} + Ntp.Analyzer.Localize diff --git a/Ntp.Analyzer.Validate.Cli/Program.cs b/Ntp.Analyzer.Validate.Cli/Program.cs index d13f57c1..2311a339 100644 --- a/Ntp.Analyzer.Validate.Cli/Program.cs +++ b/Ntp.Analyzer.Validate.Cli/Program.cs @@ -30,8 +30,9 @@ using System.IO; using System.Threading; using Ntp.Analyzer.Config; using Ntp.Analyzer.Export; +using Ntp.Analyzer.Localize; using Ntp.Config; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Analyzer.Validate.Cli { @@ -44,18 +45,23 @@ namespace Ntp.Analyzer.Validate.Cli // Neutralize. Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; bool exit = false; - bool verbose = false; + bool show = false; + bool validate = false; + bool filesystem = false; - Ntp.System.OptionSet p = - new Ntp.System.OptionSet () { { "h|?|help", v => { + Ntp.Interop.OptionSet p = + new Ntp.Interop.OptionSet () { { "h|?|help", v => { ShowUsage (); exit = true; } - }, { "v|verbose", v => { - verbose = true; - } }, { "s|show", v => { - // TODO: Implement new option to show configuration + show = true; + } + }, { "v|validate", v => { + validate = true; + } + }, { "f|filesystem", v => { + filesystem = true; } } }; @@ -65,13 +71,18 @@ namespace Ntp.Analyzer.Validate.Cli if (exit) { return; } else if (rem.Length > 1) { - Console.WriteLine ("Unknown option: " + rem [1]); + Console.WriteLine ("Unknown option."); return; } else if (rem.Length == 0) { Console.WriteLine ("Please specify configuration file"); return; } + if (!show && !validate && !filesystem) { + ShowUsage (); + return; + } + Configuration config = null; try { config = LoadConfig (rem [0]); @@ -83,20 +94,24 @@ namespace Ntp.Analyzer.Validate.Cli if (config == null) return; - Console.WriteLine ("Configuration is valid."); - if (verbose) + if (show) { Console.WriteLine (config); - - try { - TestFilesystem (config); - } catch (Exception e) { - Console.WriteLine ("Unexpected error while testing filesystem: " + e.Message); - return; + } else if (validate) { + Console.WriteLine ("Configuration is valid."); } - if (!anyErrors) { - Console.WriteLine ("Filesystem options seems valid."); - Console.WriteLine (); + if (filesystem) { + try { + TestFilesystem (config); + } catch (Exception e) { + Console.WriteLine ("Unexpected error while testing filesystem: " + e.Message); + return; + } + + if (!anyErrors) { + Console.WriteLine ("Filesystem options seems valid."); + Console.WriteLine (); + } } } @@ -159,7 +174,7 @@ namespace Ntp.Analyzer.Validate.Cli private static void ShowUsage() { Console.WriteLine ("NTP Analyzer validator tool " + VersionInfo.Text); - Console.WriteLine ("Usage: ntpav [--verbose] configuration"); + Console.WriteLine ("Usage: ntpav [--show | --validate] [--filesystem] configuration"); } } } \ No newline at end of file diff --git a/Ntp.Analyzer.sln b/Ntp.Analyzer.sln index 7992c203..8b3a2866 100644 --- a/Ntp.Analyzer.sln +++ b/Ntp.Analyzer.sln @@ -35,126 +35,172 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NPlot", "NPlot\NPlot.csproj EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySql.Data", "MySql\Source\MySql.Data\MySql.Data.csproj", "{E9DF5ED1-4CBD-4226-B931-9A51610AC14D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntp.System", "Ntp.System\Ntp.System.csproj", "{A98DB601-2993-4181-A573-5FCCC5E954C1}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{8232668F-1BAA-4328-9E55-317263BFA2DC}" ProjectSection(SolutionItems) = preProject - example\ntp.conf = example\ntp.conf example\ntpa.graph.conf = example\ntpa.graph.conf example\ntpa.stat.conf = example\ntpa.stat.conf example\ntpa.web.conf = example\ntpa.web.conf example\ntpa.web.small.conf = example\ntpa.web.small.conf EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntp.Analyzer.Localize", "Ntp.Analyzer.Localize\Ntp.Analyzer.Localize.csproj", "{6F200007-52DB-4861-A565-124270C07F67}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntp.Interop", "Ntp.Interop\Ntp.Interop.csproj", "{A98DB601-2993-4181-A573-5FCCC5E954C1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU Server|Any CPU = Server|Any CPU + Develop|Any CPU = Develop|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Develop|Any CPU.Build.0 = Develop|Any CPU {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Release|Any CPU.ActiveCfg = Release|Any CPU {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Release|Any CPU.Build.0 = Release|Any CPU {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Server|Any CPU.ActiveCfg = Server|Any CPU {02912378-E62D-4445-BA30-F56D3ABE9DA2}.Server|Any CPU.Build.0 = Server|Any CPU {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Develop|Any CPU.Build.0 = Develop|Any CPU {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Release|Any CPU.ActiveCfg = Release|Any CPU {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Release|Any CPU.Build.0 = Release|Any CPU {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Server|Any CPU.ActiveCfg = Server|Any CPU {0349CF56-C07C-46B5-B9CD-2BCB2709EE0A}.Server|Any CPU.Build.0 = Server|Any CPU {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Develop|Any CPU.Build.0 = Develop|Any CPU {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Release|Any CPU.ActiveCfg = Release|Any CPU {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Release|Any CPU.Build.0 = Release|Any CPU {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Server|Any CPU.ActiveCfg = Server|Any CPU {03F3B0D9-AC35-43E3-9303-87A71FB73CD1}.Server|Any CPU.Build.0 = Server|Any CPU {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Develop|Any CPU.Build.0 = Develop|Any CPU {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Release|Any CPU.ActiveCfg = Release|Any CPU {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Release|Any CPU.Build.0 = Release|Any CPU {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Server|Any CPU.ActiveCfg = Server|Any CPU {13FA10AB-D656-4D72-BC69-2525D484C9DE}.Server|Any CPU.Build.0 = Server|Any CPU {2324E69A-396F-467A-9582-8853687E9064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2324E69A-396F-467A-9582-8853687E9064}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2324E69A-396F-467A-9582-8853687E9064}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {2324E69A-396F-467A-9582-8853687E9064}.Develop|Any CPU.Build.0 = Develop|Any CPU {2324E69A-396F-467A-9582-8853687E9064}.Release|Any CPU.ActiveCfg = Release|Any CPU {2324E69A-396F-467A-9582-8853687E9064}.Release|Any CPU.Build.0 = Release|Any CPU {2324E69A-396F-467A-9582-8853687E9064}.Server|Any CPU.ActiveCfg = Server|Any CPU {2324E69A-396F-467A-9582-8853687E9064}.Server|Any CPU.Build.0 = Server|Any CPU {266A828E-05CA-4FEB-8B78-0BC066760C26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {266A828E-05CA-4FEB-8B78-0BC066760C26}.Debug|Any CPU.Build.0 = Debug|Any CPU + {266A828E-05CA-4FEB-8B78-0BC066760C26}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {266A828E-05CA-4FEB-8B78-0BC066760C26}.Develop|Any CPU.Build.0 = Develop|Any CPU {266A828E-05CA-4FEB-8B78-0BC066760C26}.Release|Any CPU.ActiveCfg = Release|Any CPU {266A828E-05CA-4FEB-8B78-0BC066760C26}.Release|Any CPU.Build.0 = Release|Any CPU {266A828E-05CA-4FEB-8B78-0BC066760C26}.Server|Any CPU.ActiveCfg = Server|Any CPU {266A828E-05CA-4FEB-8B78-0BC066760C26}.Server|Any CPU.Build.0 = Server|Any CPU {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Develop|Any CPU.Build.0 = Develop|Any CPU {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Release|Any CPU.ActiveCfg = Release|Any CPU {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Release|Any CPU.Build.0 = Release|Any CPU {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Server|Any CPU.ActiveCfg = Server|Any CPU {28444C86-1B41-4558-BA27-DCF32B2B1E0F}.Server|Any CPU.Build.0 = Server|Any CPU {43A1A769-6ED9-4AE1-821A-43F97814968C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {43A1A769-6ED9-4AE1-821A-43F97814968C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43A1A769-6ED9-4AE1-821A-43F97814968C}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {43A1A769-6ED9-4AE1-821A-43F97814968C}.Develop|Any CPU.Build.0 = Develop|Any CPU {43A1A769-6ED9-4AE1-821A-43F97814968C}.Release|Any CPU.ActiveCfg = Release|Any CPU {43A1A769-6ED9-4AE1-821A-43F97814968C}.Release|Any CPU.Build.0 = Release|Any CPU {43A1A769-6ED9-4AE1-821A-43F97814968C}.Server|Any CPU.ActiveCfg = Server|Any CPU {43A1A769-6ED9-4AE1-821A-43F97814968C}.Server|Any CPU.Build.0 = Server|Any CPU {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Develop|Any CPU.Build.0 = Develop|Any CPU {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Release|Any CPU.ActiveCfg = Release|Any CPU {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Release|Any CPU.Build.0 = Release|Any CPU {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Server|Any CPU.ActiveCfg = Server|Any CPU {44D739DA-4CD4-4214-88EE-A9A293BB32B5}.Server|Any CPU.Build.0 = Server|Any CPU {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Develop|Any CPU.Build.0 = Develop|Any CPU {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Release|Any CPU.ActiveCfg = Release|Any CPU {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Release|Any CPU.Build.0 = Release|Any CPU {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Server|Any CPU.ActiveCfg = Server|Any CPU {6A635537-E5E9-493E-8B89-E0E5EBB64E72}.Server|Any CPU.Build.0 = Server|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Develop|Any CPU.Build.0 = Develop|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Release|Any CPU.Build.0 = Release|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Server|Any CPU.ActiveCfg = Server|Any CPU + {6F200007-52DB-4861-A565-124270C07F67}.Server|Any CPU.Build.0 = Server|Any CPU {74985534-474F-4191-971F-FCC791006FF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74985534-474F-4191-971F-FCC791006FF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74985534-474F-4191-971F-FCC791006FF3}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {74985534-474F-4191-971F-FCC791006FF3}.Develop|Any CPU.Build.0 = Develop|Any CPU {74985534-474F-4191-971F-FCC791006FF3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {74985534-474F-4191-971F-FCC791006FF3}.Server|Any CPU.ActiveCfg = Debug|Any CPU + {74985534-474F-4191-971F-FCC791006FF3}.Release|Any CPU.Build.0 = Release|Any CPU + {74985534-474F-4191-971F-FCC791006FF3}.Server|Any CPU.ActiveCfg = Server|Any CPU {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Develop|Any CPU.Build.0 = Develop|Any CPU {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Release|Any CPU.ActiveCfg = Release|Any CPU {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Release|Any CPU.Build.0 = Release|Any CPU {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Server|Any CPU.ActiveCfg = Server|Any CPU {8263BEAB-1610-4F82-9FC0-84421E5AB6B0}.Server|Any CPU.Build.0 = Server|Any CPU {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Develop|Any CPU.Build.0 = Develop|Any CPU {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Release|Any CPU.ActiveCfg = Release|Any CPU {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Release|Any CPU.Build.0 = Release|Any CPU {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Server|Any CPU.ActiveCfg = Server|Any CPU {909C8729-ED63-4603-85EA-34A1FC4D63D9}.Server|Any CPU.Build.0 = Server|Any CPU {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Develop|Any CPU.Build.0 = Develop|Any CPU {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Release|Any CPU.ActiveCfg = Release|Any CPU {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Release|Any CPU.Build.0 = Release|Any CPU {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Server|Any CPU.ActiveCfg = Server|Any CPU {9790FACF-170E-43C7-889A-D4445FC7E7A1}.Server|Any CPU.Build.0 = Server|Any CPU {A98DB601-2993-4181-A573-5FCCC5E954C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A98DB601-2993-4181-A573-5FCCC5E954C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A98DB601-2993-4181-A573-5FCCC5E954C1}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {A98DB601-2993-4181-A573-5FCCC5E954C1}.Develop|Any CPU.Build.0 = Develop|Any CPU {A98DB601-2993-4181-A573-5FCCC5E954C1}.Release|Any CPU.ActiveCfg = Release|Any CPU {A98DB601-2993-4181-A573-5FCCC5E954C1}.Release|Any CPU.Build.0 = Release|Any CPU {A98DB601-2993-4181-A573-5FCCC5E954C1}.Server|Any CPU.ActiveCfg = Server|Any CPU {A98DB601-2993-4181-A573-5FCCC5E954C1}.Server|Any CPU.Build.0 = Server|Any CPU {C2DEBED1-FE91-4929-B686-8E920731E88C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C2DEBED1-FE91-4929-B686-8E920731E88C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2DEBED1-FE91-4929-B686-8E920731E88C}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {C2DEBED1-FE91-4929-B686-8E920731E88C}.Develop|Any CPU.Build.0 = Develop|Any CPU {C2DEBED1-FE91-4929-B686-8E920731E88C}.Release|Any CPU.ActiveCfg = Release|Any CPU {C2DEBED1-FE91-4929-B686-8E920731E88C}.Release|Any CPU.Build.0 = Release|Any CPU {C2DEBED1-FE91-4929-B686-8E920731E88C}.Server|Any CPU.ActiveCfg = Server|Any CPU {C2DEBED1-FE91-4929-B686-8E920731E88C}.Server|Any CPU.Build.0 = Server|Any CPU {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Develop|Any CPU.Build.0 = Develop|Any CPU {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Release|Any CPU.ActiveCfg = Release|Any CPU {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Release|Any CPU.Build.0 = Release|Any CPU {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Server|Any CPU.ActiveCfg = Server|Any CPU {CCF0EE0C-E3E4-4A75-AFEB-C709ED51E90F}.Server|Any CPU.Build.0 = Server|Any CPU {E9DF5ED1-4CBD-4226-B931-9A51610AC14D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E9DF5ED1-4CBD-4226-B931-9A51610AC14D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9DF5ED1-4CBD-4226-B931-9A51610AC14D}.Develop|Any CPU.ActiveCfg = Develop|Any CPU + {E9DF5ED1-4CBD-4226-B931-9A51610AC14D}.Develop|Any CPU.Build.0 = Develop|Any CPU {E9DF5ED1-4CBD-4226-B931-9A51610AC14D}.Release|Any CPU.ActiveCfg = Release|Any CPU {E9DF5ED1-4CBD-4226-B931-9A51610AC14D}.Release|Any CPU.Build.0 = Release|Any CPU {E9DF5ED1-4CBD-4226-B931-9A51610AC14D}.Server|Any CPU.ActiveCfg = Server|Any CPU @@ -163,7 +209,7 @@ Global GlobalSection(NestedProjects) = preSolution EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = Ntp.Analyzer.Validate.Cli\Ntp.Analyzer.Validate.Cli.csproj + StartupItem = Ntp.Analyzer.Cli\Ntp.Analyzer.Cli.csproj Policies = $0 $0.DotNetNamingPolicy = $1 $1.DirectoryNamespaceAssociation = PrefixedHierarchical diff --git a/Ntp.Analyzer/Config/Configuration.cs b/Ntp.Analyzer/Config/Configuration.cs index 059a9e18..01ce0227 100644 --- a/Ntp.Analyzer/Config/Configuration.cs +++ b/Ntp.Analyzer/Config/Configuration.cs @@ -23,13 +23,15 @@ // 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; using System.Collections.Generic; using System.Text; -using Ntp.Analyzer.Log; using Ntp.Config; +using Ntp.Analyzer.Log; using Ntp.Analyzer.Config.Root; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config { @@ -147,9 +149,8 @@ namespace Ntp.Analyzer.Config { ConfigurationBlock databaseBlock = FindSingleBlock (DatabaseConfiguration.Identifier, block); DatabaseConfiguration database = DatabaseConfiguration.Create (databaseBlock); - if (database == null) { - ConfigError ("Database section is missing."); - } + if (database == null) + ConfigError (ConfigurationMessage.DatabaseMissing); ConfigurationBlock clusterBlock = FindSingleBlock (ClusterConfiguration.Identifier, block); ClusterConfiguration cluster = ClusterConfiguration.Create (clusterBlock); diff --git a/Ntp.Analyzer/Config/Destination/DestinationCollection.cs b/Ntp.Analyzer/Config/Destination/DestinationCollection.cs index cb5fffb0..b29eab1f 100644 --- a/Ntp.Analyzer/Config/Destination/DestinationCollection.cs +++ b/Ntp.Analyzer/Config/Destination/DestinationCollection.cs @@ -23,6 +23,7 @@ // 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.Collections.Generic; using Ntp.Analyzer.Export; using Ntp.Config; diff --git a/Ntp.Analyzer/Config/Destination/DirectoryCollection.cs b/Ntp.Analyzer/Config/Destination/DirectoryCollection.cs index d9c36188..6221e6a2 100644 --- a/Ntp.Analyzer/Config/Destination/DirectoryCollection.cs +++ b/Ntp.Analyzer/Config/Destination/DirectoryCollection.cs @@ -23,21 +23,19 @@ // 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.Analyzer.Export; +using Ntp.Analyzer.Localize; using Ntp.Config; namespace Ntp.Analyzer.Config.Destination { public sealed class DirectoryCollection : DestinationCollection { - public const string Identifier = "Destinations"; - private readonly IEnumerable destinations; - private readonly string prefix; - - public DirectoryCollection ( + private DirectoryCollection ( string configName, int indentLevel, IEnumerable destinations, @@ -48,6 +46,10 @@ namespace Ntp.Analyzer.Config.Destination this.prefix = prefix; } + private readonly IEnumerable destinations; + private readonly string prefix; + + public const string Identifier = ConfigurationKeyword.DirectoryDestinations; public override IEnumerable Destinations { get { return destinations; } } @@ -63,12 +65,12 @@ namespace Ntp.Analyzer.Config.Destination List settings = new List (); settings.Add (Identifier); - settings.Add ("Prefix"); + settings.Add (ConfigurationKeyword.DirectoryPrefix); int num = destinations.Count (); for (int i = 0; i < num; i++) - settings.Add ("File"); + settings.Add (ConfigurationKeyword.DirectoryItem); return ConfigText (settings.ToArray (), values.ToArray ()); } @@ -84,9 +86,11 @@ namespace Ntp.Analyzer.Config.Destination if (block != null) { String[] destinationLines = block.Lines; - prefix = GetOptions (new[] { "Prefix" }, destinationLines) ["Prefix"]; + prefix = GetOptions ( + new[] { ConfigurationKeyword.DirectoryPrefix }, + destinationLines) [ConfigurationKeyword.DirectoryPrefix]; - foreach (string destination in GetMultiOption("Directory", destinationLines)) + foreach (string destination in GetMultiOption(ConfigurationKeyword.DirectoryItem, destinationLines)) directories.Add (new DirectoryStreamDestination (server.FilePath, destination, prefix)); } diff --git a/Ntp.Analyzer/Config/Destination/FileCollection.cs b/Ntp.Analyzer/Config/Destination/FileCollection.cs index 97b6225c..9a2e5295 100644 --- a/Ntp.Analyzer/Config/Destination/FileCollection.cs +++ b/Ntp.Analyzer/Config/Destination/FileCollection.cs @@ -28,16 +28,14 @@ using System; using System.Collections.Generic; using System.Linq; using Ntp.Analyzer.Export; +using Ntp.Analyzer.Localize; using Ntp.Config; namespace Ntp.Analyzer.Config.Destination { public sealed class FileCollection : DestinationCollection { - public const string Identifier = "Destinations"; - private readonly IEnumerable destinations; - - public FileCollection( + private FileCollection( string configName, int indentLevel, IEnumerable destinations) @@ -46,6 +44,9 @@ namespace Ntp.Analyzer.Config.Destination this.destinations = destinations; } + private readonly IEnumerable destinations; + + public const string Identifier = ConfigurationKeyword.FileDestinations; public override IEnumerable Destinations { get { return destinations; } @@ -53,36 +54,36 @@ namespace Ntp.Analyzer.Config.Destination public override string ToString() { - List values = new List(); - values.Add(null); + List values = new List (); + values.Add (null); - IEnumerable names = Destinations.Select(f => f.Location); - values.AddRange(names); + IEnumerable names = Destinations.Select (f => f.Location); + values.AddRange (names); - List settings = new List(); - settings.Add(Identifier); + List settings = new List (); + settings.Add (Identifier); - int num = destinations.Count(); + int num = destinations.Count (); for (int i = 0; i < num; i++) - settings.Add("File"); + settings.Add (ConfigurationKeyword.FileItem); - return ConfigText(settings.ToArray(), values.ToArray()); + return ConfigText (settings.ToArray (), values.ToArray ()); } public static FileCollection Create( ServerConfiguration server, ConfigurationBlock config) { - List files = new List(); + List files = new List (); ConfigurationBlock block = FindSingleBlock (Identifier, config); if (block != null) { - foreach (string destination in GetMultiOption("File", block)) - files.Add(new FileStreamDestination(server.FilePath, destination)); + foreach (string destination in GetMultiOption(ConfigurationKeyword.FileItem, block)) + files.Add (new FileStreamDestination (server.FilePath, destination)); } - return new FileCollection(String.Empty, config.IndentLevel + 1, files); + return new FileCollection (String.Empty, config.IndentLevel + 1, files); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Destination/GraphSetConfiguration.cs b/Ntp.Analyzer/Config/Destination/GraphSetConfiguration.cs index f3659e8a..8548894a 100644 --- a/Ntp.Analyzer/Config/Destination/GraphSetConfiguration.cs +++ b/Ntp.Analyzer/Config/Destination/GraphSetConfiguration.cs @@ -1,5 +1,5 @@ // -// GraphSet.cs +// GraphSetConfiguration.cs // // Author: // Carsten Sonne Larsen @@ -28,25 +28,13 @@ using System; using System.Collections.Generic; using System.Linq; using Ntp.Analyzer.Config.Graph; +using Ntp.Analyzer.Localize; using Ntp.Config; namespace Ntp.Analyzer.Config.Destination { public sealed class GraphSetConfiguration : ConfigurationBase { - public const string Identifier = "Images"; - - private static readonly String[] Params = new[] - { - Identifier, - "Title", - "LinkIndex" - }; - - private readonly List graphs; - private readonly int linkIndex; - private readonly string title; - public GraphSetConfiguration( string configName, int indentLevel, @@ -60,6 +48,18 @@ namespace Ntp.Analyzer.Config.Destination this.graphs = new List(graphs); } + public const string Identifier = ConfigurationKeyword.GraphSet; + private static readonly String[] Params = new[] + { + ConfigurationKeyword.GraphSet, + ConfigurationKeyword.GraphSetTitle, + ConfigurationKeyword.LinkIndex + }; + + private readonly List graphs; + private readonly int linkIndex; + private readonly string title; + public string Title { get { return title; } @@ -75,34 +75,29 @@ namespace Ntp.Analyzer.Config.Destination get { return graphs; } } - protected override IEnumerable Items - { - get - { - return new object[] - { - ConfigName, - Title, - LinkIndex - }; + protected override IEnumerable Items { + get { + return new object[] { + ConfigName, + Title, + LinkIndex + }; } } public override string ToString() { - List values = new List(Items); + List values = new List (Items); + IEnumerable names = Graphs.Select (g => g.ConfigName); + values.AddRange (names); - IEnumerable names = Graphs.Select(g => g.ConfigName); - values.AddRange(names); - - List settings = new List(Params); - - int num = names.Count(); + List settings = new List (Params); + int num = names.Count (); for (int i = 0; i < num; i++) - settings.Add("Graph"); + settings.Add (ConfigurationKeyword.GraphSetItem); - return ConfigText(settings.ToArray(), values.ToArray()); + return ConfigText (settings.ToArray (), values.ToArray ()); } public static IEnumerable Create( @@ -111,21 +106,29 @@ namespace Ntp.Analyzer.Config.Destination ConfigurationBlock config, string configPath) { - List sets = new List(); + List sets = new List (); - foreach (ConfigurationBlock imageBlock in FindBlocks("Images", config)) - { - Dictionary options = GetOptions(Params, imageBlock); - string title = GetOptionString(options, "Title", configPath, false); - int linkIndex = GetOptionInteger(options, "LinkIndex", configPath, true); + foreach (ConfigurationBlock imageBlock in FindBlocks(Identifier, config)) { + Dictionary options = GetOptions (Params, imageBlock); + string title = GetOptionString (options, ConfigurationKeyword.GraphSetTitle, configPath, false); + int linkIndex = GetOptionInteger (options, ConfigurationKeyword.LinkIndex, configPath, true); - List selectedGraphs = new List(); - foreach (string name in GetMultiOption("Graph", imageBlock)) - { - selectedGraphs.Add(graphs.Single(p => p.GraphName == name)); + List selectedGraphs = new List (); + foreach (string name in GetMultiOption(ConfigurationKeyword.GraphSetItem, imageBlock)) { + GraphBaseConfiguration graph = graphs.SingleOrDefault (p => p.GraphName == name); + if (graph != null) { + selectedGraphs.Add (graph); + } else { + ConfigError (String.Format ( + ConfigurationMessage.MissingReference, + ConfigurationKeyword.GraphSetItem, name, Identifier)); + ConfigError (ConfigurationMessage.ConfiguredGraphs); + foreach (GraphBaseConfiguration graphConfig in graphs) + ConfigError (graphConfig.ConfigName); + } } - sets.Add(new GraphSetConfiguration(String.Empty, config.IndentLevel + 1, title, linkIndex, selectedGraphs)); + sets.Add (new GraphSetConfiguration (String.Empty, config.IndentLevel + 1, title, linkIndex, selectedGraphs)); } return sets; diff --git a/Ntp.Analyzer/Config/Destination/WebLinkCollection.cs b/Ntp.Analyzer/Config/Destination/WebLinkCollection.cs index 76e0f8b9..20bbc982 100644 --- a/Ntp.Analyzer/Config/Destination/WebLinkCollection.cs +++ b/Ntp.Analyzer/Config/Destination/WebLinkCollection.cs @@ -23,20 +23,19 @@ // 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.Analyzer.Export; +using Ntp.Analyzer.Localize; using Ntp.Config; namespace Ntp.Analyzer.Config.Destination { public sealed class WebLinkCollection : ConfigurationBase { - public const string Identifier = "Links"; - private readonly IList links; - - public WebLinkCollection ( + private WebLinkCollection ( string configName, int indentLevel, IList links) @@ -45,6 +44,9 @@ namespace Ntp.Analyzer.Config.Destination this.links = links; } + private readonly IList links; + + public const string Identifier = ConfigurationKeyword.WebLinks; protected override IEnumerable Items { get { return Destinations.Cast (); } } @@ -61,13 +63,12 @@ namespace Ntp.Analyzer.Config.Destination IEnumerable names = Destinations.Select (l => l.Link); values.AddRange (names); - List settings = new List (); + List settings = new List (); settings.Add (Identifier); int num = links.Count (); - for (int i = 0; i < num; i++) - settings.Add ("Link"); + settings.Add (ConfigurationKeyword.WebLinkItem); return ConfigText (settings.ToArray (), values.ToArray ()); } @@ -79,7 +80,7 @@ namespace Ntp.Analyzer.Config.Destination List links = new List (); ConfigurationBlock linkBlock = FindSingleBlock (Identifier, config); if (linkBlock != null) { - foreach (string link in GetMultiOption("Link", linkBlock)) + foreach (string link in GetMultiOption(ConfigurationKeyword.WebLinkItem, linkBlock)) links.Add (new WebLink (link)); } diff --git a/Ntp.Analyzer/Config/Graph/DispersionGraphConfiguration.cs b/Ntp.Analyzer/Config/Graph/DispersionGraphConfiguration.cs index 6600ca17..3782257c 100644 --- a/Ntp.Analyzer/Config/Graph/DispersionGraphConfiguration.cs +++ b/Ntp.Analyzer/Config/Graph/DispersionGraphConfiguration.cs @@ -23,6 +23,7 @@ // 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 Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Graph.Interface; @@ -33,9 +34,6 @@ namespace Ntp.Analyzer.Config.Graph /// public abstract class DispersionGraphConfiguration : GraphBaseConfiguration, IDispersionGraphConfiguration { - private readonly double jitter; - private readonly double offset; - protected DispersionGraphConfiguration ( ServerConfiguration server, string configName, @@ -71,6 +69,9 @@ namespace Ntp.Analyzer.Config.Graph this.offset = offset; } + private readonly double jitter; + private readonly double offset; + /// /// Gets the jitter multiplication factor. /// diff --git a/Ntp.Analyzer/Config/Graph/GraphBaseConfiguration.cs b/Ntp.Analyzer/Config/Graph/GraphBaseConfiguration.cs index 8fff4586..11ac2d87 100644 --- a/Ntp.Analyzer/Config/Graph/GraphBaseConfiguration.cs +++ b/Ntp.Analyzer/Config/Graph/GraphBaseConfiguration.cs @@ -23,12 +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.Collections.Generic; +using System.Drawing.Imaging; using Ntp.Analyzer.Objects; using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Export; using Ntp.Analyzer.Graph.Interface; -using System.Drawing.Imaging; namespace Ntp.Analyzer.Config.Graph { diff --git a/Ntp.Analyzer/Config/Graph/HostGraphConfiguration.cs b/Ntp.Analyzer/Config/Graph/HostGraphConfiguration.cs index f2207b60..b0dd1694 100644 --- a/Ntp.Analyzer/Config/Graph/HostGraphConfiguration.cs +++ b/Ntp.Analyzer/Config/Graph/HostGraphConfiguration.cs @@ -23,6 +23,7 @@ // 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; @@ -30,6 +31,7 @@ using Ntp.Analyzer.Objects; using Ntp.Config; using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Graph.Interface; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Graph { @@ -77,26 +79,28 @@ namespace Ntp.Analyzer.Config.Graph this.gfrequency = gfrequency; } + public const string Identifier = ConfigurationKeyword.HostGraph; private static readonly String[] Params = new[] { - "HostGraph", - "Frequency", - "InitialRun", - "FixedRun", - "Title", - "Width", - "Height", - "Timespan", - "FilterFactor", - "GFrequency", - "Stability", - "Jitter", - "Offset", + ConfigurationKeyword.HostGraph, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.GraphTitle, + ConfigurationKeyword.GraphWidth, + ConfigurationKeyword.GraphHeight, + ConfigurationKeyword.GraphTimespan, + ConfigurationKeyword.GraphFilterFactor, + ConfigurationKeyword.HostGraphGFrequency, + ConfigurationKeyword.HostGraphStability, + ConfigurationKeyword.GraphJitter, + ConfigurationKeyword.GraphOffset, FileCollection.Identifier, WebLinkCollection.Identifier }; private readonly double gfrequency; private readonly double stability; + /// /// Gets the stability multiplication factor. /// @@ -121,8 +125,8 @@ namespace Ntp.Analyzer.Config.Graph return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Title, Width, Height, @@ -155,7 +159,7 @@ namespace Ntp.Analyzer.Config.Graph if (index <= 0 || index > links.Destinations.Count ()) throw new ConfigurationException ( - String.Format ("Index out of range while getting host graph link [{0}].", index)); + String.Format (ConfigurationMessage.HostGraphLinkIndex1, index)); return WebPath + links.Destinations [index - 1].Link; } @@ -172,7 +176,7 @@ namespace Ntp.Analyzer.Config.Graph if (index <= 0 || index > links.Destinations.Count ()) throw new ConfigurationException ( - String.Format ("Index out of range while getting host graph alt name [{0}].", index)); + String.Format (ConfigurationMessage.HostGraphLinkIndex2, index)); string name = links.Destinations [index - 1].Link; @@ -199,23 +203,22 @@ namespace Ntp.Analyzer.Config.Graph { Dictionary options = GetOptions (Params, config); - // Create return new HostGraphConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.HostGraph, Identifier, true), config.IndentLevel, - GetOptionInteger (options, Params [1], Params [0], true), - GetOptionBoolean (options, Params [2], Params [0], false, false), - GetOptionBoolean (options, Params [3], Params [0], false, false), - GetOptionString (options, Params [4], Params [0], false, String.Empty), - GetOptionInteger (options, Params [5], Params [0], false, 1024), - GetOptionInteger (options, Params [6], Params [0], false, 800), - GetOptionInteger (options, Params [7], Params [0], false, 60 * 12), - GetOptionDouble (options, Params [8], Params [0], false), - GetOptionDouble (options, Params [9], Params [0], false), - GetOptionDouble (options, Params [10], Params [0], false), - GetOptionDouble (options, Params [11], Params [0], false), - GetOptionDouble (options, Params [12], Params [0], false), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, false), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, false), + GetOptionString (options, ConfigurationKeyword.GraphTitle, Identifier, false, String.Empty), + GetOptionInteger (options, ConfigurationKeyword.GraphWidth, Identifier, false, 1024), + GetOptionInteger (options, ConfigurationKeyword.GraphHeight, Identifier, false, 800), + GetOptionInteger (options, ConfigurationKeyword.GraphTimespan, Identifier, false, 60 * 12), + GetOptionDouble (options, ConfigurationKeyword.GraphFilterFactor, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.HostGraphGFrequency, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.HostGraphStability, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.GraphJitter, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.GraphOffset, Identifier, false), FileCollection.Create (server, config), WebLinkCollection.Create (server, config)); } diff --git a/Ntp.Analyzer/Config/Graph/PeerGraphConfiguration.cs b/Ntp.Analyzer/Config/Graph/PeerGraphConfiguration.cs index 10f20a4f..1fcbc293 100644 --- a/Ntp.Analyzer/Config/Graph/PeerGraphConfiguration.cs +++ b/Ntp.Analyzer/Config/Graph/PeerGraphConfiguration.cs @@ -23,12 +23,14 @@ // 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.Objects; using Ntp.Config; using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Graph.Interface; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Graph { @@ -76,26 +78,28 @@ namespace Ntp.Analyzer.Config.Graph this.delay = delay; } + public const string Identifier = ConfigurationKeyword.PeerGraph; private static readonly String[] Params = new[] { - "PeerGraph", - "Frequency", - "InitialRun", - "FixedRun", - "Title", - "Width", - "Height", - "Timespan", - "FilterFactor", - "Jitter", - "Offset", - "Balance", - "Delay", + ConfigurationKeyword.PeerGraph, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.GraphTitle, + ConfigurationKeyword.GraphWidth, + ConfigurationKeyword.GraphHeight, + ConfigurationKeyword.GraphTimespan, + ConfigurationKeyword.GraphFilterFactor, + ConfigurationKeyword.GraphJitter, + ConfigurationKeyword.GraphOffset, + ConfigurationKeyword.PeerGraphBalance, + ConfigurationKeyword.PeerGraphDelay, DirectoryCollection.Identifier, WebLinkCollection.Identifier }; private readonly double balance; private readonly double delay; + /// /// Gets the balance multiplication factor. /// @@ -117,8 +121,8 @@ namespace Ntp.Analyzer.Config.Graph return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Title, Width, Height, @@ -146,7 +150,7 @@ namespace Ntp.Analyzer.Config.Graph if (linkIndex <= 0 || linkIndex > links.Destinations.Count) throw new ConfigurationException ( - String.Format ("Index out of range while getting peer graph link [{0}].", linkIndex)); + String.Format (ConfigurationMessage.PeerGraphLinkIndex, linkIndex)); return WebPath + links.Destinations [linkIndex - 1].Link + peerName.Replace ('.', '-') + ".png"; } @@ -176,20 +180,20 @@ namespace Ntp.Analyzer.Config.Graph return new PeerGraphConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.PeerGraph, Identifier, true), config.IndentLevel, - GetOptionInteger (options, Params [1], Params [0], true), - GetOptionBoolean (options, Params [2], Params [0], false, false), - GetOptionBoolean (options, Params [3], Params [0], false, false), - GetOptionString (options, Params [4], Params [0], false, String.Empty), - GetOptionInteger (options, Params [5], Params [0], false, 1024), - GetOptionInteger (options, Params [6], Params [0], false, 800), - GetOptionInteger (options, Params [7], Params [0], false, 60 * 12), - GetOptionDouble (options, Params [8], Params [0], false), - GetOptionDouble (options, Params [9], Params [0], false), - GetOptionDouble (options, Params [10], Params [0], false), - GetOptionDouble (options, Params [11], Params [0], false), - GetOptionDouble (options, Params [12], Params [0], false), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, false), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, false), + GetOptionString (options, ConfigurationKeyword.GraphTitle, Identifier, false, String.Empty), + GetOptionInteger (options, ConfigurationKeyword.GraphWidth, Identifier, false, 1024), + GetOptionInteger (options, ConfigurationKeyword.GraphHeight, Identifier, false, 800), + GetOptionInteger (options, ConfigurationKeyword.GraphTimespan, Identifier, false, 60 * 12), + GetOptionDouble (options, ConfigurationKeyword.GraphFilterFactor, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.GraphJitter, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.GraphOffset, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.PeerGraphBalance, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.PeerGraphDelay, Identifier, false), DirectoryCollection.Create (server, config), WebLinkCollection.Create (server, config)); } diff --git a/Ntp.Analyzer/Config/Graph/TrafficGraphConfiguration.cs b/Ntp.Analyzer/Config/Graph/TrafficGraphConfiguration.cs index d1f3ccae..41873af2 100644 --- a/Ntp.Analyzer/Config/Graph/TrafficGraphConfiguration.cs +++ b/Ntp.Analyzer/Config/Graph/TrafficGraphConfiguration.cs @@ -23,6 +23,7 @@ // 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; @@ -30,12 +31,13 @@ using Ntp.Analyzer.Objects; using Ntp.Config; using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Graph.Interface; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Graph { public sealed class TrafficGraphConfiguration : GraphBaseConfiguration, ITrafficGraphConfiguration { - public TrafficGraphConfiguration ( + private TrafficGraphConfiguration ( ServerConfiguration server, string configName, int indentLevel, @@ -89,27 +91,28 @@ namespace Ntp.Analyzer.Config.Graph this.packetRate = packetRate; } + public const string Identifier = ConfigurationKeyword.TrafficGraph; private static readonly String[] Params = new[] { - "TrafficGraph", - "Frequency", - "InitialRun", - "FixedRun", - "Title", - "Width", - "Height", - "Timespan", - "Received", - "Ignored", - "Dropped", - "Sent", - "NotSent", - "AvgReceived", - "AvgIgnored", - "AvgDropped", - "AvgSent", - "AvgNotSent", - "PlotInterval", - "PacketRate", + ConfigurationKeyword.TrafficGraph, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.GraphTitle, + ConfigurationKeyword.GraphWidth, + ConfigurationKeyword.GraphHeight, + ConfigurationKeyword.GraphTimespan, + ConfigurationKeyword.TrafficGraphReceived, + ConfigurationKeyword.TrafficGraphIgnored, + ConfigurationKeyword.TrafficGraphDropped, + ConfigurationKeyword.TrafficGraphSent, + ConfigurationKeyword.TrafficGraphNotSent, + ConfigurationKeyword.TrafficGraphAvgReceived, + ConfigurationKeyword.TrafficGraphAvgIgnored, + ConfigurationKeyword.TrafficGraphAvgDropped, + ConfigurationKeyword.TrafficGraphAvgSent, + ConfigurationKeyword.TrafficGraphAvgNotSent, + ConfigurationKeyword.TrafficGraphPlotInterval, + ConfigurationKeyword.TrafficGraphPacketRate, FileCollection.Identifier, WebLinkCollection.Identifier }; @@ -180,8 +183,8 @@ namespace Ntp.Analyzer.Config.Graph return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Title, Width, Height, @@ -221,7 +224,7 @@ namespace Ntp.Analyzer.Config.Graph if (index <= 0 || index > links.Destinations.Count ()) throw new ConfigurationException ( - String.Format ("Index out of range while getting traffic graph link [{0}].", index)); + String.Format (ConfigurationMessage.TrafficGraphLinkIndex1, index)); return WebPath + links.Destinations [index - 1].Link; } @@ -238,7 +241,7 @@ namespace Ntp.Analyzer.Config.Graph if (index <= 0 || index > links.Destinations.Count ()) throw new ConfigurationException ( - String.Format ("Index out of range while getting traffic graph alt name [{0}].", index)); + String.Format (ConfigurationMessage.TrafficGraphLinkIndex2, index)); string name = links.Destinations [index - 1].Link; @@ -265,32 +268,31 @@ namespace Ntp.Analyzer.Config.Graph { Dictionary options = GetOptions (Params, config); - // Create return new TrafficGraphConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.TrafficGraph, Identifier, true), config.IndentLevel, - GetOptionInteger (options, Params [1], Params [0], true), - GetOptionBoolean (options, Params [2], Params [0], false, false), - GetOptionBoolean (options, Params [3], Params [0], false, false), - GetOptionString (options, Params [4], Params [0], false, String.Empty), - GetOptionInteger (options, Params [5], Params [0], false, 1024), - GetOptionInteger (options, Params [6], Params [0], false, 800), - GetOptionInteger (options, Params [7], Params [0], false, 60 * 12), - GetOptionDouble (options, Params [8], Params [0], false), - GetOptionDouble (options, Params [9], Params [0], false), - GetOptionDouble (options, Params [10], Params [0], false), - GetOptionDouble (options, Params [11], Params [0], false), - GetOptionDouble (options, Params [12], Params [0], false), - GetOptionDouble (options, Params [13], Params [0], false), - GetOptionDouble (options, Params [14], Params [0], false), - GetOptionDouble (options, Params [15], Params [0], false), - GetOptionDouble (options, Params [16], Params [0], false), - GetOptionDouble (options, Params [17], Params [0], false), - GetOptionInteger (options, Params [18], Params [0], false, 15), - GetOptionInteger (options, Params [19], Params [0], false, 1), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, false), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, false), + GetOptionString (options, ConfigurationKeyword.GraphTitle, Identifier, false, String.Empty), + GetOptionInteger (options, ConfigurationKeyword.GraphWidth, Identifier, false, 1024), + GetOptionInteger (options, ConfigurationKeyword.GraphHeight, Identifier, false, 800), + GetOptionInteger (options, ConfigurationKeyword.GraphTimespan, Identifier, false, 60 * 12), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphReceived, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphIgnored, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphDropped, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphSent, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphNotSent, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphAvgReceived, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphAvgIgnored, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphAvgDropped, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphAvgSent, Identifier, false), + GetOptionDouble (options, ConfigurationKeyword.TrafficGraphAvgNotSent, Identifier, false), + GetOptionInteger (options, ConfigurationKeyword.TrafficGraphPlotInterval, Identifier, false, 15), + GetOptionInteger (options, ConfigurationKeyword.TrafficGraphPacketRate, Identifier, false, 1), FileCollection.Create (server, config), WebLinkCollection.Create (server, config)); } } -} +} \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Navigation/DropdownItemConfiguration.cs b/Ntp.Analyzer/Config/Navigation/DropdownItemConfiguration.cs index 5167ece5..8045eedb 100644 --- a/Ntp.Analyzer/Config/Navigation/DropdownItemConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/DropdownItemConfiguration.cs @@ -27,23 +27,12 @@ using System; using System.Collections.Generic; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Navigation { public sealed class DropdownItemConfiguration : MenuItemConfiguration { - private readonly String[] Params = new[] - { - "Item", - "Type", - "Caption", - "Link", - "Page", - "Dropdown" - }; - - private readonly MenuConfiguration menu; - private DropdownItemConfiguration( string configName, int indentLevel, @@ -55,9 +44,20 @@ namespace Ntp.Analyzer.Config.Navigation this.menu = menu; } + private readonly String[] Params = new[] { + ConfigurationKeyword.MenuItem, + ConfigurationKeyword.MenuItemType, + ConfigurationKeyword.MenuItemCaption, + ConfigurationKeyword.MenuItemLink, + ConfigurationKeyword.MenuItemPage, + ConfigurationKeyword.MenuItemDropdown + }; + + private readonly MenuConfiguration menu; + public override string TypeText { - get { return "Dropdown"; } + get { return ConfigurationKeyword.MenuItemDropdown; } } public IEnumerable MenuItems @@ -100,9 +100,8 @@ namespace Ntp.Analyzer.Config.Navigation if (config == null || linkables == null) return null; - MenuConfiguration menu = MenuConfiguration.Create(config, linkables); - - return new DropdownItemConfiguration(String.Empty, config.IndentLevel, itemName, caption, menu); + MenuConfiguration menu = MenuConfiguration.Create (config, linkables); + return new DropdownItemConfiguration (String.Empty, config.IndentLevel, itemName, caption, menu); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Navigation/HeadMenuItemConfiguration.cs b/Ntp.Analyzer/Config/Navigation/HeadMenuItemConfiguration.cs index caad4c8e..e9cb29c2 100644 --- a/Ntp.Analyzer/Config/Navigation/HeadMenuItemConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/HeadMenuItemConfiguration.cs @@ -24,6 +24,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using Ntp.Analyzer.Localize; + namespace Ntp.Analyzer.Config.Navigation { public sealed class HeadMenuItemConfiguration : MenuItemConfiguration @@ -44,7 +46,7 @@ namespace Ntp.Analyzer.Config.Navigation public override string TypeText { - get { return "Name"; } + get { return ConfigurationKeyword.MenuItemTypeName; } } public override ILinkable Page diff --git a/Ntp.Analyzer/Config/Navigation/HeaderMenuItemConfiguration.cs b/Ntp.Analyzer/Config/Navigation/HeaderMenuItemConfiguration.cs index aa7c1ba9..bf4226cb 100644 --- a/Ntp.Analyzer/Config/Navigation/HeaderMenuItemConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/HeaderMenuItemConfiguration.cs @@ -24,6 +24,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using Ntp.Analyzer.Localize; + namespace Ntp.Analyzer.Config.Navigation { public sealed class HeaderMenuItemConfiguration : MenuItemConfiguration @@ -43,7 +45,7 @@ namespace Ntp.Analyzer.Config.Navigation public override string TypeText { - get { return "Header"; } + get { return ConfigurationKeyword.MenuItemTypeHeader; } } public override ILinkable Page diff --git a/Ntp.Analyzer/Config/Navigation/LinkMenuItemConfiguration.cs b/Ntp.Analyzer/Config/Navigation/LinkMenuItemConfiguration.cs index 739ef685..a0789da4 100644 --- a/Ntp.Analyzer/Config/Navigation/LinkMenuItemConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/LinkMenuItemConfiguration.cs @@ -24,6 +24,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using Ntp.Analyzer.Localize; + namespace Ntp.Analyzer.Config.Navigation { public sealed class LinkMenuItemConfiguration : MenuItemConfiguration @@ -44,7 +46,7 @@ namespace Ntp.Analyzer.Config.Navigation public override string TypeText { - get { return "Link"; } + get { return ConfigurationKeyword.MenuItemLink; } } public override ILinkable Page diff --git a/Ntp.Analyzer/Config/Navigation/MenuConfiguration.cs b/Ntp.Analyzer/Config/Navigation/MenuConfiguration.cs index a152c44e..b93d9ef5 100644 --- a/Ntp.Analyzer/Config/Navigation/MenuConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/MenuConfiguration.cs @@ -28,19 +28,12 @@ using System; using System.Collections.Generic; using System.Linq; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Navigation { public sealed class MenuConfiguration : ConfigurationBase { - private static readonly String[] Params = new[] - { - "Menu", - "Item" - }; - - private readonly List menuItems; - private MenuConfiguration( string configName, int indentLevel, @@ -50,6 +43,15 @@ namespace Ntp.Analyzer.Config.Navigation this.menuItems = new List(menuItems); } + public const string Identifier = ConfigurationKeyword.Menu; + private static readonly String[] Params = new[] + { + ConfigurationKeyword.Menu, + MenuItemConfiguration.Identifier + }; + + private readonly List menuItems; + public IEnumerable MenuItems { get { return menuItems; } @@ -74,15 +76,17 @@ namespace Ntp.Analyzer.Config.Navigation public static MenuConfiguration Create(ConfigurationBlock config, IEnumerable linkables) { - Dictionary options = GetOptions(Params, config); + Dictionary options = GetOptions (Params, config); - string name = GetOptionConfigName(options, "Menu", "Menu", false, "Menu"); + string name = GetOptionConfigName ( + options, ConfigurationKeyword.Menu, Identifier, false, Identifier); - ConfigurationBlock[] itemBlocks = FindBlocks("Item", config); + ConfigurationBlock[] itemBlocks = FindBlocks (ConfigurationKeyword.MenuItem, config); + List items = itemBlocks. + Select (itemBlock => MenuItemConfiguration.Create (itemBlock, linkables)). + ToList (); - List items = itemBlocks.Select(itemBlock => MenuItemConfiguration.Create(itemBlock, linkables)).ToList(); - - return new MenuConfiguration(name, config.IndentLevel, items); + return new MenuConfiguration (name, config.IndentLevel, items); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Navigation/MenuItemConfiguration.cs b/Ntp.Analyzer/Config/Navigation/MenuItemConfiguration.cs index 49c842b3..fc4d51f9 100644 --- a/Ntp.Analyzer/Config/Navigation/MenuItemConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/MenuItemConfiguration.cs @@ -28,24 +28,12 @@ using System; using System.Collections.Generic; using System.Linq; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Navigation { public abstract class MenuItemConfiguration : ConfigurationBase { - private static readonly String[] Params = new[] - { - "Item", - "Type", - "Caption", - "Link", - "Page", - "Dropdown" - }; - - private readonly string caption; - private readonly string link; - protected MenuItemConfiguration( string configName, int indentLevel, @@ -57,6 +45,19 @@ namespace Ntp.Analyzer.Config.Navigation this.link = link; } + public const string Identifier = ConfigurationKeyword.MenuItem; + private static readonly String[] Params = new[] { + ConfigurationKeyword.MenuItem, + ConfigurationKeyword.MenuItemType, + ConfigurationKeyword.MenuItemCaption, + ConfigurationKeyword.MenuItemLink, + ConfigurationKeyword.MenuItemPage, + ConfigurationKeyword.MenuItemDropdown + }; + + private readonly string caption; + private readonly string link; + public string Caption { get { return caption; } @@ -94,54 +95,73 @@ namespace Ntp.Analyzer.Config.Navigation public static MenuItemConfiguration Create(ConfigurationBlock config, IEnumerable linkables) { - Dictionary options = GetOptions(Params, config); + Dictionary options = GetOptions (Params, config); - string itemName = GetOptionConfigName(options, "Item", "Item", true); - string type = GetOptionString(options, "Type", "Item", false, "Link").ToLower(); - string caption = GetOptionString(options, "Caption", "Item", false); - string link = GetOptionString(options, "Link", "Item", false); - string page = GetOptionString(options, "Page", "Item", false); - string dropdown = GetOptionString(options, "Dropdown", "Item", false); + string itemName = GetOptionConfigName (options, ConfigurationKeyword.MenuItem, Identifier, true); + string typeText = GetOptionString (options, ConfigurationKeyword.MenuItemType, Identifier, false, "Link").ToLower (); + string caption = GetOptionString (options, ConfigurationKeyword.MenuItemCaption, Identifier, false); + string link = GetOptionString (options, ConfigurationKeyword.MenuItemLink, Identifier, false); + string page = GetOptionString (options, ConfigurationKeyword.MenuItemPage, Identifier, false); + string dropdown = GetOptionString (options, ConfigurationKeyword.MenuItemDropdown, Identifier, false); ILinkable linkable = null; + MenuItemType type = MenuItemType.Unknown; + if (dropdown != String.Empty) - type = "dropdown"; + type = MenuItemType.Dropdown; else if (page != String.Empty) - type = "page"; - else if (type == String.Empty && link != String.Empty) - type = "link"; - - if (type == "page") - { - linkable = linkables.SingleOrDefault(l => l.Name == page); - if (linkable == null) { - ConfigError (String.Format ( - "Page {0} specified in {1} does not exist.", - page, "Menu")); - } - + type = MenuItemType.Page; + else if (typeText == String.Empty && link != String.Empty) + type = MenuItemType.Link; + else if (typeText.Trim ().ToLower () == ConfigurationKeyword.MenuItemTypeSpacer.ToLower ()) + type = MenuItemType.Spacer; + else if (typeText.Trim ().ToLower () == ConfigurationKeyword.MenuItemTypeHeader.ToLower ()) + type = MenuItemType.Header; + else if (typeText.Trim ().ToLower () == ConfigurationKeyword.MenuItemTypeName.ToLower ()) + type = MenuItemType.Name; + else if (typeText.Trim ().ToLower () == ConfigurationKeyword.MenuItemLink.ToLower ()) + type = MenuItemType.Link; + else if (typeText.Trim ().ToLower () == ConfigurationKeyword.MenuItemPage.ToLower ()) + type = MenuItemType.Page; + else if (typeText.Trim ().ToLower () == ConfigurationKeyword.MenuItemDropdown.ToLower ()) + type = MenuItemType.Dropdown; + else { + ConfigError (String.Format (ConfigurationMessage.UnknownMenuItem, typeText)); + type = MenuItemType.Unknown; } - switch (type) - { - case "spacer": - return new SpacerMenuItemConfiguration(String.Empty, config.IndentLevel); - case "header": - return new HeaderMenuItemConfiguration(String.Empty, config.IndentLevel, itemName, caption); - case "name": - return new HeadMenuItemConfiguration(String.Empty, config.IndentLevel, itemName, caption, link); - case "link": - return new LinkMenuItemConfiguration(String.Empty, config.IndentLevel, itemName, caption, link); - case "page": - return new PageMenuItemConfiguration(String.Empty, config.IndentLevel, caption, linkable); - case "dropdown": - return DropdownItemConfiguration.Create( - itemName, - dropdown, - FindSingleBlock("Content", config), - linkables); - default: - return null; + if (type == MenuItemType.Page) { + linkable = linkables.SingleOrDefault (l => l.Name == page); + if (linkable == null) { + ConfigError (String.Format ( + ConfigurationMessage.MissingReference, + ConfigurationKeyword.MenuItemPage, page, Identifier)); + + ConfigError (ConfigurationMessage.ConfiguredPages); + foreach (ILinkable l in linkables) + ConfigError (l.Name); + } + } + + switch (type) { + case MenuItemType.Spacer: + return new SpacerMenuItemConfiguration (String.Empty, config.IndentLevel); + case MenuItemType.Header: + return new HeaderMenuItemConfiguration (String.Empty, config.IndentLevel, itemName, caption); + case MenuItemType.Name: + return new HeadMenuItemConfiguration (String.Empty, config.IndentLevel, itemName, caption, link); + case MenuItemType.Link: + return new LinkMenuItemConfiguration (String.Empty, config.IndentLevel, itemName, caption, link); + case MenuItemType.Page: + return new PageMenuItemConfiguration (String.Empty, config.IndentLevel, caption, linkable); + case MenuItemType.Dropdown: + return DropdownItemConfiguration.Create ( + itemName, + dropdown, + FindSingleBlock (ConfigurationKeyword.MenuItemDropdownContent, config), + linkables); + default: + return null; } } } diff --git a/Ntp.Analyzer.Data/Cache/NtpConfCache.cs b/Ntp.Analyzer/Config/Navigation/MenuItemType.cs similarity index 68% rename from Ntp.Analyzer.Data/Cache/NtpConfCache.cs rename to Ntp.Analyzer/Config/Navigation/MenuItemType.cs index d7713959..53a70ae4 100644 --- a/Ntp.Analyzer.Data/Cache/NtpConfCache.cs +++ b/Ntp.Analyzer/Config/Navigation/MenuItemType.cs @@ -1,10 +1,10 @@ -// -// NtpConfCache.cs +// +// MenuItemType.cs // // Author: // Carsten Sonne Larsen // -// Copyright (c) 2013-2016 Carsten Sonne Larsen +// Copyright (c) 2016 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,26 +24,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using Ntp.Analyzer.Log; -using Ntp.Analyzer.Data.File; +using System; -namespace Ntp.Analyzer.Data.Cache +namespace Ntp.Analyzer.Config.Navigation { - public sealed class NtpConfCache : DataCache + public enum MenuItemType { - public NtpConfCache(LogBase log) - : base(log) - { - } - - protected override int ValidMinutes - { - get { return 180; } - } - - protected override NtpConfMapper Create(string name) - { - return new NtpConfMapper(name, Log); - } + Unknown, + Spacer, + Header, + Name, + Link, + Page, + Dropdown } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Navigation/PageMenuItemConfiguration.cs b/Ntp.Analyzer/Config/Navigation/PageMenuItemConfiguration.cs index 2e6c94b6..06efb4a7 100644 --- a/Ntp.Analyzer/Config/Navigation/PageMenuItemConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/PageMenuItemConfiguration.cs @@ -25,13 +25,12 @@ // THE SOFTWARE. using System; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Navigation { public sealed class PageMenuItemConfiguration : MenuItemConfiguration, ILinkable { - private readonly ILinkable page; - internal PageMenuItemConfiguration( string configName, int indentLevel, @@ -42,9 +41,11 @@ namespace Ntp.Analyzer.Config.Navigation this.page = page; } + private readonly ILinkable page; + public override string TypeText { - get { return "Page"; } + get { return ConfigurationKeyword.MenuItemPage; } } public override ILinkable Page diff --git a/Ntp.Analyzer/Config/Navigation/SpacerMenuItemConfiguration.cs b/Ntp.Analyzer/Config/Navigation/SpacerMenuItemConfiguration.cs index 58424808..460ecf95 100644 --- a/Ntp.Analyzer/Config/Navigation/SpacerMenuItemConfiguration.cs +++ b/Ntp.Analyzer/Config/Navigation/SpacerMenuItemConfiguration.cs @@ -24,6 +24,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using Ntp.Analyzer.Localize; + namespace Ntp.Analyzer.Config.Navigation { public sealed class SpacerMenuItemConfiguration : MenuItemConfiguration @@ -41,7 +43,7 @@ namespace Ntp.Analyzer.Config.Navigation public override string TypeText { - get { return "Spacer"; } + get { return ConfigurationKeyword.MenuItemTypeSpacer; } } public override ILinkable Page diff --git a/Ntp.Analyzer/Config/Page/AboutPageConfiguration.cs b/Ntp.Analyzer/Config/Page/AboutPageConfiguration.cs index d485f705..8d24a19c 100644 --- a/Ntp.Analyzer/Config/Page/AboutPageConfiguration.cs +++ b/Ntp.Analyzer/Config/Page/AboutPageConfiguration.cs @@ -23,11 +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 System.Collections.Generic; using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Navigation; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Page { @@ -64,19 +66,21 @@ namespace Ntp.Analyzer.Config.Page this.serverId = serverId; } + public const string Identifier = ConfigurationKeyword.AboutPage; private static readonly String[] Params = new[] { - "AboutPage", - "Frequency", - "InitialRun", - "FixedRun", - "Template", - "PageTitle", - "ServerID", - "ContentTitle", - "Content", + ConfigurationKeyword.AboutPage, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.PageTemplate, + ConfigurationKeyword.PageTitle, + ConfigurationKeyword.AboutPageServerId, + ConfigurationKeyword.AboutPageContentTitle, + ConfigurationKeyword.AboutPageContent, FileCollection.Identifier, - "Link" + ConfigurationKeyword.PageLink }; + private readonly string content; private readonly string header; private readonly int serverId; @@ -98,8 +102,8 @@ namespace Ntp.Analyzer.Config.Page return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Theme, Title, ServerId, @@ -113,7 +117,22 @@ namespace Ntp.Analyzer.Config.Page public override string ToString () { - return ConfigText (Params, Items); + return ConfigText ( + Params, + new object[] { + ConfigName, + Frequency, + InitialRun, + FixedRun, + Theme, + Title, + ServerId, + Header, + "{ " + Content + " }", + Destinations, + Link + } + ); } public static AboutPageConfiguration Create ( @@ -122,10 +141,9 @@ namespace Ntp.Analyzer.Config.Page { Dictionary options = GetOptions (Params, config); - ConfigurationBlock contentBlock = FindSingleBlock ("Content", config); - if (contentBlock == null) - { - ConfigError ("About page does not contain a Content section."); + ConfigurationBlock contentBlock = FindSingleBlock (ConfigurationKeyword.AboutPageContent, config); + if (contentBlock == null) { + ConfigError (ConfigurationMessage.AboutPageContentMissing); return null; } @@ -135,18 +153,18 @@ namespace Ntp.Analyzer.Config.Page return new AboutPageConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.AboutPage, Identifier, true), config.IndentLevel, - GetOptionInteger (options, "Frequency", Params [0], true), - GetOptionBoolean (options, "InitialRun", Params [0], false, true), - GetOptionBoolean (options, "FixedRun", Params [0], false, true), - 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"), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, true), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, true), + GetOptionString (options, ConfigurationKeyword.PageTemplate, Identifier, false, "default"), + GetOptionString (options, ConfigurationKeyword.PageTitle, Identifier, true), + GetOptionInteger (options, ConfigurationKeyword.AboutPageServerId, Identifier, false), + GetOptionString (options, ConfigurationKeyword.AboutPageContentTitle, Identifier, false, "ContentTitle"), content, FileCollection.Create (server, config), - GetOptionString (options, "Link", Params [0], true)); + GetOptionString (options, ConfigurationKeyword.PageLink, Identifier, true)); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Page/Collection/SummaryCollection.cs b/Ntp.Analyzer/Config/Page/Collection/SummaryCollection.cs index 42eaeb52..10f95db7 100644 --- a/Ntp.Analyzer/Config/Page/Collection/SummaryCollection.cs +++ b/Ntp.Analyzer/Config/Page/Collection/SummaryCollection.cs @@ -28,15 +28,13 @@ using System; using System.Collections.Generic; using System.Linq; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Page.Collection { public sealed class SummaryCollection : ConfigurationBase { - public const string Identifier = "Summaries"; - private readonly List pages; - - public SummaryCollection( + private SummaryCollection( string configName, int indentLevel, IEnumerable pages) @@ -45,6 +43,9 @@ namespace Ntp.Analyzer.Config.Page.Collection this.pages = new List(pages); } + public const string Identifier = ConfigurationKeyword.Summaries; + private readonly List pages; + protected override IEnumerable Items { get { return pages; } @@ -69,7 +70,7 @@ namespace Ntp.Analyzer.Config.Page.Collection int num = names.Count(); for (int i = 0; i < num; i++) - settings.Add("PeerSummaryPage"); + settings.Add(PeerSummaryPageConfiguration.Identifier); return ConfigText(settings.ToArray(), values.ToArray()); } @@ -80,24 +81,30 @@ namespace Ntp.Analyzer.Config.Page.Collection ConfigurationBlock config, string configPath) { - List summaries = new List(); + List summaries = new List (); ConfigurationBlock block = FindSingleBlock (Identifier, config); - if(block != null) { - foreach (string name in GetMultiOption(Identifier, block)) - { - PeerSummaryPageConfiguration summary = peerSummaries.SingleOrDefault(ps => ps.ConfigName == name); + if (block != null) { + foreach (string name in GetMultiOption(PeerSummaryPageConfiguration.Identifier, block)) { + PeerSummaryPageConfiguration summary = peerSummaries.SingleOrDefault ( + ps => ps.ConfigName == name); if (summary != null) - summaries.Add(summary); - else - { - ConfigError("Cannot find PeerSummaryPage " + name + " specified in HostPage"); + summaries.Add (summary); + else { + ConfigError (String.Format ( + ConfigurationMessage.MissingReference, + PeerSummaryPageConfiguration.Identifier, name, Identifier + )); + + ConfigError (ConfigurationMessage.ConfiguredPeerSummaryPages); + foreach (PeerSummaryPageConfiguration page in peerSummaries) + ConfigError (page.ConfigName); } } } - return new SummaryCollection(String.Empty, config.IndentLevel + 1, summaries); + return new SummaryCollection (String.Empty, config.IndentLevel + 1, summaries); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Page/GraphPageConfiguration.cs b/Ntp.Analyzer/Config/Page/GraphPageConfiguration.cs index c3be85d1..a2934852 100644 --- a/Ntp.Analyzer/Config/Page/GraphPageConfiguration.cs +++ b/Ntp.Analyzer/Config/Page/GraphPageConfiguration.cs @@ -32,8 +32,6 @@ namespace Ntp.Analyzer.Config.Page { public abstract class GraphPageConfiguration : PageConfigurationBase, ILinkable { - private readonly int linkIndex; - protected GraphPageConfiguration( ServerConfiguration server, string configName, @@ -61,11 +59,13 @@ namespace Ntp.Analyzer.Config.Page this.linkIndex = linkIndex; } - public abstract IEnumerable GraphSets { get; } + private readonly int linkIndex; public int LinkIndex { get { return linkIndex; } } + + public abstract IEnumerable GraphSets { get; } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Page/HostGraphPageConfiguration.cs b/Ntp.Analyzer/Config/Page/HostGraphPageConfiguration.cs index 75459bc9..c1c5e621 100644 --- a/Ntp.Analyzer/Config/Page/HostGraphPageConfiguration.cs +++ b/Ntp.Analyzer/Config/Page/HostGraphPageConfiguration.cs @@ -23,18 +23,20 @@ // 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.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; +using Ntp.Analyzer.Localize; using Ntp.Config; namespace Ntp.Analyzer.Config.Page { public sealed class HostGraphPageConfiguration : GraphPageConfiguration { - public HostGraphPageConfiguration ( + private HostGraphPageConfiguration ( ServerConfiguration server, string configName, int indentLevel, @@ -67,18 +69,20 @@ namespace Ntp.Analyzer.Config.Page } } + public const string Identifier = ConfigurationKeyword.HostGraphPage; private static readonly String[] Params = new[] { - "HostGraphPage", - "Frequency", - "InitialRun", - "FixedRun", - "Template", - "PageTitle", - "GraphPage", - "LinkIndex", + ConfigurationKeyword.HostGraphPage, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.PageTemplate, + ConfigurationKeyword.PageTitle, + ConfigurationKeyword.GraphPage, + ConfigurationKeyword.LinkIndex, DirectoryCollection.Identifier, - "Link" + ConfigurationKeyword.PageLink }; + private readonly HostPageConfiguration page; public override IEnumerable GraphSets { @@ -90,8 +94,8 @@ namespace Ntp.Analyzer.Config.Page return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Theme, Title, page != null ? page.ConfigName : null, @@ -131,30 +135,39 @@ namespace Ntp.Analyzer.Config.Page { Dictionary options = GetOptions (Params, config); - string hostPagesName = GetOptionString (options, "GraphPage", "HostGraphPage", false); + string hostPagesName = GetOptionString ( + options, ConfigurationKeyword.GraphPage, Identifier, false); HostPageConfiguration hostPage = null; if (hostPagesName != String.Empty) { hostPage = hostPages.SingleOrDefault (pp => pp.ConfigName == hostPagesName); if (hostPage == null) { - ConfigError ("Cannot find GraphPage " + hostPagesName + " specified in HostGraphPage"); + ConfigError (String.Format( + ConfigurationMessage.MissingReference, + ConfigurationKeyword.GraphPage, hostPagesName, Identifier + )); + + ConfigError (ConfigurationMessage.ConfiguredGraphPages); + foreach (HostPageConfiguration hostPageConfig in hostPages) + ConfigError (hostPageConfig.ConfigName); + } } return new HostGraphPageConfiguration ( server, - GetOptionConfigName (options, "HostGraphPage", "HostGraphPage", true), + GetOptionConfigName (options, ConfigurationKeyword.HostGraphPage, Identifier, true), config.IndentLevel, - GetOptionInteger (options, "Frequency", "HostGraphPage", true), - GetOptionBoolean (options, "InitialRun", "HostGraphPage", false, true), - GetOptionBoolean (options, "FixedRun", "HostGraphPage", false, true), - GetOptionString (options, "Template", "HostGraphPage", false, "default"), - GetOptionString (options, "PageTitle", "HostGraphPage", false, String.Empty), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, true), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, true), + GetOptionString (options, ConfigurationKeyword.PageTemplate, Identifier, false, "default"), + GetOptionString (options, ConfigurationKeyword.PageTitle, Identifier, false, String.Empty), hostPage, - GetOptionInteger (options, "LinkIndex", "HostGraphPage", true), + GetOptionInteger (options, ConfigurationKeyword.LinkIndex, Identifier, true), DirectoryCollection.Create (server, config), - GetOptionString (options, "Link", "HostGraphPage", true) + GetOptionString (options, ConfigurationKeyword.PageLink, Identifier, true) ); } } diff --git a/Ntp.Analyzer/Config/Page/HostPageConfiguration.cs b/Ntp.Analyzer/Config/Page/HostPageConfiguration.cs index c0c1e6f6..f04128f8 100644 --- a/Ntp.Analyzer/Config/Page/HostPageConfiguration.cs +++ b/Ntp.Analyzer/Config/Page/HostPageConfiguration.cs @@ -31,6 +31,7 @@ using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Navigation; using Ntp.Analyzer.Config.Page.Collection; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Page { @@ -73,22 +74,24 @@ namespace Ntp.Analyzer.Config.Page graphPages = new List (); } + public const string Identifier = ConfigurationKeyword.HostPage; + /// /// The parameters used in configuration files. /// private static readonly String[] Params = new[] { - "HostPage", - "Frequency", - "InitialRun", - "FixedRun", - "Template", - "PageTitle", - "PoolMember", - "PeerPages", + ConfigurationKeyword.HostPage, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.PageTemplate, + ConfigurationKeyword.PageTitle, + ConfigurationKeyword.HostPagePoolMember, + PeerPageConfiguration.Identifier, GraphSetConfiguration.Identifier, SummaryCollection.Identifier, FileCollection.Identifier, - "Link" + ConfigurationKeyword.PageLink }; private readonly List graphPages; @@ -148,11 +151,11 @@ namespace Ntp.Analyzer.Config.Page return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Theme, Title, - PoolMember ? 1 : 0, + PoolMember, PeerPage != null ? PeerPage.ConfigName : String.Empty, Graphs, PeerSummaries, @@ -205,32 +208,40 @@ namespace Ntp.Analyzer.Config.Page { OptionSet options = GetOptions (Params, config); - string peerPageName = GetOptionString (options, Params [7], Params [0], false); + string peerPageName = GetOptionString ( + options, PeerPageConfiguration.Identifier, Identifier, false); PeerPageConfiguration peerPage = null; if (peerPageName != String.Empty) { peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName); if (peerPage == null) { - ConfigError ("Cannot find PeerPages " + peerPageName + " specified in HostPage"); + ConfigError (String.Format( + ConfigurationMessage.MissingReference, + PeerPageConfiguration.Identifier, peerPageName, Identifier + )); + + ConfigError (ConfigurationMessage.ConfiguredPeerPages); + foreach (PeerPageConfiguration peerPageConfig in peerPages) + ConfigError (peerPageConfig.ConfigName); } } return new HostPageConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.HostPage, Identifier, true), config.IndentLevel, - GetOptionInteger (options, Params [1], Params [0], true), - GetOptionBoolean (options, Params [2], Params [0], false, true), - GetOptionBoolean (options, Params [3], Params [0], false, true), - GetOptionString (options, Params [4], Params [0], false, "default"), - GetOptionString (options, Params [5], Params [0], false, String.Empty), - GetOptionBoolean (options, Params [6], Params [0], false), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, true), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, true), + GetOptionString (options, ConfigurationKeyword.PageTemplate, Identifier, false, "default"), + GetOptionString (options, ConfigurationKeyword.PageTitle, Identifier, false, String.Empty), + GetOptionBoolean (options, ConfigurationKeyword.HostPagePoolMember, Identifier, false), peerPage, - GraphSetConfiguration.Create (server, hostGraphs, config, Params [0]), - SummaryCollection.Create (server, peerSummaries, config, Params [0]), + GraphSetConfiguration.Create (server, hostGraphs, config, Identifier), + SummaryCollection.Create (server, peerSummaries, config, Identifier), FileCollection.Create (server, config), - GetOptionString (options, Params [11], Params [0], false, String.Empty) + GetOptionString (options, ConfigurationKeyword.PageLink, Identifier, false, String.Empty) ); } } diff --git a/Ntp.Analyzer/Config/Page/PeerGraphPageConfiguration.cs b/Ntp.Analyzer/Config/Page/PeerGraphPageConfiguration.cs index f3b9ddee..e0fa6649 100644 --- a/Ntp.Analyzer/Config/Page/PeerGraphPageConfiguration.cs +++ b/Ntp.Analyzer/Config/Page/PeerGraphPageConfiguration.cs @@ -23,6 +23,7 @@ // 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; @@ -30,6 +31,7 @@ using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Objects; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Page { @@ -68,18 +70,20 @@ namespace Ntp.Analyzer.Config.Page } } + public const string Identifier = ConfigurationKeyword.PeerGraphPage; private static readonly String[] Params = new[] { - "PeerGraphPage", - "Frequency", - "InitialRun", - "FixedRun", - "Template", - "PageTitle", - "GraphPage", - "LinkIndex", + ConfigurationKeyword.PeerGraphPage, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.PageTemplate, + ConfigurationKeyword.PageTitle, + ConfigurationKeyword.GraphPage, + ConfigurationKeyword.LinkIndex, DirectoryCollection.Identifier, - "Link" + ConfigurationKeyword.PageLink }; + private readonly PeerPageConfiguration page; public override IEnumerable GraphSets { @@ -91,8 +95,8 @@ namespace Ntp.Analyzer.Config.Page return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Theme, Title, page != null ? page.ConfigName : null, @@ -105,21 +109,23 @@ namespace Ntp.Analyzer.Config.Page public string GetFileName (Host host, string name, GraphSetConfiguration graphSet, GraphBaseConfiguration graph) { - return host.Name.Replace ('.', '-') + "_" + - graph.GetAltName (graphSet, name). - Replace (".png", String.Empty). - Replace ('.', '-') - + ".html"; + return GetGraphFileName (host, name, graphSet, graph); } - public string GetLink (Host host, TimeServer peer, GraphSetConfiguration graphSet, GraphBaseConfiguration graph) + public string GetLink (Host host, string name, GraphSetConfiguration graphSet, GraphBaseConfiguration graph) { - return WebPath + Link + - host.Name.Replace ('.', '-') + "_" + - graph.GetAltName (graphSet, peer.Name). - Replace (".png", String.Empty). - Replace ('.', '-') - + ".html"; + // TODO: Sanitize link + return WebPath + Link + GetGraphFileName (host, name, graphSet, graph); + } + + private string GetGraphFileName(Host host, string name, GraphSetConfiguration graphSet, GraphBaseConfiguration graph) + { + return + host.Name.Replace ('.', '-') + "_" + + graph.GetAltName (graphSet, name). + Replace (".png", String.Empty). + Replace ('.', '-') + + ".html"; } public override string ToString () @@ -134,26 +140,33 @@ namespace Ntp.Analyzer.Config.Page { Dictionary options = GetOptions (Params, config); - string peerPageName = GetOptionString (options, "GraphPage", "PeerGraphPage", true); + string peerPageName = GetOptionString (options, ConfigurationKeyword.GraphPage, Identifier, true); PeerPageConfiguration peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName); if (peerPage == null) { - ConfigError ("Cannot find GraphPage " + peerPageName + " specified in " + Params [0]); + ConfigError (String.Format( + ConfigurationMessage.MissingReference, + ConfigurationKeyword.GraphPage, peerPageName, Identifier + )); + + ConfigError (ConfigurationMessage.ConfiguredGraphPages); + foreach (PeerPageConfiguration peerPageConfig in peerPages) + ConfigError (peerPageConfig.ConfigName); } return new PeerGraphPageConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.PeerGraphPage, Identifier, true), config.IndentLevel, - GetOptionInteger (options, "Frequency", Params [0], true), - GetOptionBoolean (options, "InitialRun", Params [0], false, true), - GetOptionBoolean (options, "FixedRun", Params [0], false, true), - GetOptionString (options, "Template", Params [0], false, "default"), - GetOptionString (options, "PageTitle", Params [0], false, String.Empty), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, true), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, true), + GetOptionString (options, ConfigurationKeyword.PageTemplate, Identifier, false, "default"), + GetOptionString (options, ConfigurationKeyword.PageTitle, Identifier, false, String.Empty), peerPage, - GetOptionInteger (options, "LinkIndex", Params [0], true), + GetOptionInteger (options, ConfigurationKeyword.LinkIndex, Identifier, true), DirectoryCollection.Create (server, config), - GetOptionString (options, "Link", Params [0], true) + GetOptionString (options, ConfigurationKeyword.PageLink, Identifier, true) ); } } diff --git a/Ntp.Analyzer/Config/Page/PeerPageConfiguration.cs b/Ntp.Analyzer/Config/Page/PeerPageConfiguration.cs index 062e2955..53959054 100644 --- a/Ntp.Analyzer/Config/Page/PeerPageConfiguration.cs +++ b/Ntp.Analyzer/Config/Page/PeerPageConfiguration.cs @@ -23,6 +23,7 @@ // 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; @@ -30,6 +31,7 @@ using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Navigation; using Ntp.Config; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Page { @@ -63,17 +65,19 @@ namespace Ntp.Analyzer.Config.Page graphPages = new List (); } + public const string Identifier = ConfigurationKeyword.PeerPages; private static readonly String[] Params = new[] { - "PeerPage", - "Frequency", - "InitialRun", - "FixedRun", - "Template", - "PageTitle", + ConfigurationKeyword.PeerPages, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.PageTemplate, + ConfigurationKeyword.PageTitle, GraphSetConfiguration.Identifier, DirectoryCollection.Identifier, - "Link" + ConfigurationKeyword.PageLink }; + private readonly List graphPages; private readonly List graphs; @@ -98,8 +102,8 @@ namespace Ntp.Analyzer.Config.Page return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Theme, Title, Graphs, @@ -145,16 +149,16 @@ namespace Ntp.Analyzer.Config.Page return new PeerPageConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.PeerPages, Identifier, true), config.IndentLevel, - GetOptionInteger (options, "Frequency", Params [0], true), - GetOptionBoolean (options, "InitialRun", Params [0], false, true), - GetOptionBoolean (options, "FixedRun", Params [0], false, true), - GetOptionString (options, "Template", Params [0], false, "default"), - GetOptionString (options, "PageTitle", Params [0], false, String.Empty), - GraphSetConfiguration.Create (server, peerGraphs, config, Params [0]), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, true), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, true), + GetOptionString (options, ConfigurationKeyword.PageTemplate, Identifier, false, "default"), + GetOptionString (options, ConfigurationKeyword.PageTitle, Identifier, false, String.Empty), + GraphSetConfiguration.Create (server, peerGraphs, config, Identifier), DirectoryCollection.Create (server, config), - GetOptionString (options, "Link", Params [0], true)); + GetOptionString (options, ConfigurationKeyword.PageLink, Identifier, true)); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Page/PeerSummaryPageConfiguration.cs b/Ntp.Analyzer/Config/Page/PeerSummaryPageConfiguration.cs index 811e04bc..23061bc0 100644 --- a/Ntp.Analyzer/Config/Page/PeerSummaryPageConfiguration.cs +++ b/Ntp.Analyzer/Config/Page/PeerSummaryPageConfiguration.cs @@ -23,12 +23,14 @@ // 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.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Navigation; +using Ntp.Analyzer.Localize; using Ntp.Config; namespace Ntp.Analyzer.Config.Page @@ -64,18 +66,20 @@ namespace Ntp.Analyzer.Config.Page this.graphs = new List (graphs); } + public const string Identifier = ConfigurationKeyword.PeerSummaryPage; private static readonly String[] Params = new[] { - "PeerSummaryPage", - "Frequency", - "InitialRun", - "FixedRun", - "Template", - "PageTitle", - "PeerPages", + ConfigurationKeyword.PeerSummaryPage, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.PageTemplate, + ConfigurationKeyword.PageTitle, + PeerPageConfiguration.Identifier, GraphSetConfiguration.Identifier, DirectoryCollection.Identifier, - "Link" + ConfigurationKeyword.PageLink }; + private readonly List graphs; private readonly PeerPageConfiguration peerPage; @@ -92,8 +96,8 @@ namespace Ntp.Analyzer.Config.Page return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, + InitialRun, + FixedRun, Theme, Title, peerPage != null ? peerPage.ConfigName : null, @@ -127,30 +131,32 @@ namespace Ntp.Analyzer.Config.Page { Dictionary options = GetOptions (Params, config); - string peerPageName = options ["PeerPages"]; + string peerPageName = options [PeerPageConfiguration.Identifier]; PeerPageConfiguration peerPage = peerPages.SingleOrDefault (pp => pp.ConfigName == peerPageName); if (peerPage == null) { - ConfigError ("Cannot find PeerPages " + peerPageName + " specified in " + Params [0]); - ConfigError ("Known peer pages: "); - + ConfigError (String.Format( + ConfigurationMessage.MissingReference, + PeerPageConfiguration.Identifier, peerPageName, Identifier)); + + ConfigError (ConfigurationMessage.ConfiguredPeerPages); foreach (PeerPageConfiguration peerPageConfig in peerPages) ConfigError (peerPageConfig.ConfigName); } return new PeerSummaryPageConfiguration ( server, - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, ConfigurationKeyword.PeerSummaryPage, Identifier, true), config.IndentLevel, - GetOptionInteger (options, "Frequency", Params [0], true), - GetOptionBoolean (options, "InitialRun", Params [0], false, true), - GetOptionBoolean (options, "FixedRun", Params [0], false, true), - GetOptionString (options, "Template", Params [0], false, "default"), - GetOptionString (options, "PageTitle", Params [0], false, String.Empty), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, true), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, true), + GetOptionString (options, ConfigurationKeyword.PageTemplate, Identifier, false, "default"), + GetOptionString (options, ConfigurationKeyword.PageTitle, Identifier, false, String.Empty), peerPage, - GraphSetConfiguration.Create (server, peerGraphs, config, Params [0]), + GraphSetConfiguration.Create (server, peerGraphs, config, Identifier), FileCollection.Create (server, config), - GetOptionString (options, "Link", Params [0], true) + GetOptionString (options, ConfigurationKeyword.PageLink, Identifier, true) ); } } diff --git a/Ntp.Analyzer/Config/Root/ClusterConfiguration.cs b/Ntp.Analyzer/Config/Root/ClusterConfiguration.cs index 75ff18b8..68043941 100644 --- a/Ntp.Analyzer/Config/Root/ClusterConfiguration.cs +++ b/Ntp.Analyzer/Config/Root/ClusterConfiguration.cs @@ -1,5 +1,5 @@ // -// NodeConfiguration.cs +// ClusterConfiguration.cs // // Author: // Carsten Sonne Larsen @@ -23,15 +23,17 @@ // 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 System.Collections.Generic; +using Ntp.Analyzer.Localize; +using Ntp.Config; namespace Ntp.Analyzer.Config.Root { public sealed class ClusterConfiguration : ConfigurationBase { - public ClusterConfiguration ( + private ClusterConfiguration ( string name, int indentLevel, IEnumerable nodes) @@ -40,18 +42,18 @@ namespace Ntp.Analyzer.Config.Root this.nodes = nodes; } + public const string Identifier = ConfigurationKeyword.Cluster; + private static readonly String[] Params = new[] { + ConfigurationKeyword.Cluster, + NodeConfiguration.Identifier + }; + private IEnumerable nodes; public IEnumerable Nodes { get { return nodes; } } - public const string Identifier = "Cluster"; - private static readonly String[] Params = new[] { - Identifier, - "Node" - }; - protected override IEnumerable Items { get { return new object[] { @@ -70,7 +72,8 @@ namespace Ntp.Analyzer.Config.Root List nodes = new List (); - foreach (ConfigurationBlock nodeBlock in FindBlocks(Params[1], config)) { + // TODO: Implement validation + foreach (ConfigurationBlock nodeBlock in FindBlocks(NodeConfiguration.Identifier, config)) { NodeConfiguration node = NodeConfiguration.Create (nodeBlock); if (node != null) { @@ -79,7 +82,7 @@ namespace Ntp.Analyzer.Config.Root } return new ClusterConfiguration ( - GetOptionConfigName (options, Params [0], Params [0], true), + GetOptionConfigName (options, Identifier, Identifier, true), config.IndentLevel, nodes); } diff --git a/Ntp.Analyzer/Config/Root/DatabaseConfiguration.cs b/Ntp.Analyzer/Config/Root/DatabaseConfiguration.cs index 75f27121..27e337dc 100644 --- a/Ntp.Analyzer/Config/Root/DatabaseConfiguration.cs +++ b/Ntp.Analyzer/Config/Root/DatabaseConfiguration.cs @@ -23,29 +23,16 @@ // 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.Localize; using Ntp.Config; namespace Ntp.Analyzer.Config.Root { public sealed class DatabaseConfiguration : ConfigurationBase { - public const string Identifier = "Database"; - private static readonly String[] Params = new[] { - Identifier, - "Host", - "Name", - "User", - "Pass", - "Create" - }; - private readonly string host; - private readonly string name; - private readonly string pass; - private readonly string user; - private readonly bool initialize; - private DatabaseConfiguration ( string configName, int indentLevel, @@ -64,6 +51,22 @@ namespace Ntp.Analyzer.Config.Root this.initialize = initialize; } + public const string Identifier = ConfigurationKeyword.Database; + private static readonly String[] Params = new[] { + ConfigurationKeyword.Database, + ConfigurationKeyword.DatabaseHost, + ConfigurationKeyword.DatabaseName, + ConfigurationKeyword.DatabaseUser, + ConfigurationKeyword.DatabasePass, + ConfigurationKeyword.DatabaseCreate + }; + + private readonly string host; + private readonly string name; + private readonly string pass; + private readonly string user; + private readonly bool initialize; + protected override IEnumerable Items { get { return new object[] { @@ -78,15 +81,11 @@ namespace Ntp.Analyzer.Config.Root } public string Name { - get { - return name; - } + get { return name; } } public bool Initialize { - get { - return initialize; - } + get { return initialize; } } /// @@ -126,13 +125,13 @@ namespace Ntp.Analyzer.Config.Root Dictionary options = GetOptions (Params, config); return new DatabaseConfiguration ( - GetOptionConfigName (options, Params [0], null, false, Params [0]), + GetOptionConfigName (options, Identifier, null, false, Identifier), config.IndentLevel, - GetOptionString (options, Params [1], Params [0], true), - GetOptionString (options, Params [2], Params [0], true), - GetOptionString (options, Params [3], Params [0], true), - GetOptionString (options, Params [4], Params [0], true), - GetOptionBoolean (options, Params [5], Params [0], false, false)); + GetOptionString (options, ConfigurationKeyword.DatabaseHost, Identifier, true), + GetOptionString (options, ConfigurationKeyword.DatabaseName, Identifier, true), + GetOptionString (options, ConfigurationKeyword.DatabaseUser, Identifier, true), + GetOptionString (options, ConfigurationKeyword.DatabasePass, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.DatabaseCreate, Identifier, false, false)); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Root/ListenerConfiguration.cs b/Ntp.Analyzer/Config/Root/ListenerConfiguration.cs index 2ee1ac3a..c2d57f9e 100644 --- a/Ntp.Analyzer/Config/Root/ListenerConfiguration.cs +++ b/Ntp.Analyzer/Config/Root/ListenerConfiguration.cs @@ -23,25 +23,27 @@ // 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.Config; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Config.Net; +using Ntp.Config; namespace Ntp.Analyzer.Config.Root { public sealed class ListenerConfiguration : EndPointConfiguration { - public ListenerConfiguration (string name, int indentLevel, string ip, int port) + private ListenerConfiguration (string name, int indentLevel, string ip, int port) : base(name, indentLevel, ip, port) { } - public const string Identifier = "Listener"; + public const string Identifier = ConfigurationKeyword.Listener; private static readonly String[] Params = new[] { - Identifier, - "IP", - "Port" + ConfigurationKeyword.Listener, + ConfigurationKeyword.ListenerIp, + ConfigurationKeyword.ListenerPort }; protected override IEnumerable Items { @@ -64,10 +66,10 @@ namespace Ntp.Analyzer.Config.Root Dictionary options = GetOptions (Params, config); return new ListenerConfiguration ( - GetOptionConfigName (options, Params [0], String.Empty, false), + GetOptionConfigName (options, Identifier, String.Empty, false), config.IndentLevel, - GetOptionString (options, "IP", Params [0], false, "0.0.0.0"), - GetOptionInteger (options, "Port", Params [0], false, 9072) + GetOptionString (options, ConfigurationKeyword.ListenerIp, Identifier, false, "127.0.0.1"), + GetOptionInteger (options, ConfigurationKeyword.ListenerPort, Identifier, false, 9072) ); } } diff --git a/Ntp.Analyzer/Config/Root/NodeConfiguration.cs b/Ntp.Analyzer/Config/Root/NodeConfiguration.cs index e8d4bac9..2bedd6be 100644 --- a/Ntp.Analyzer/Config/Root/NodeConfiguration.cs +++ b/Ntp.Analyzer/Config/Root/NodeConfiguration.cs @@ -23,25 +23,27 @@ // 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.Config.Net; -using Ntp.Config; using System.Collections.Generic; +using Ntp.Config; +using Ntp.Analyzer.Config.Net; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config.Root { public class NodeConfiguration : EndPointConfiguration { - public NodeConfiguration (string name, int indentLevel, string ip, int port) + private NodeConfiguration (string name, int indentLevel, string ip, int port) : base(name, indentLevel, ip, port) { } - public const string Identifier = "Node"; + public const string Identifier = ConfigurationKeyword.ClusterNode; private static readonly String[] Params = new[] { - Identifier, - "IP", - "Port" + ConfigurationKeyword.ClusterNode, + ConfigurationKeyword.ClusterNodeIp, + ConfigurationKeyword.ClusterNodePort }; protected override IEnumerable Items { @@ -64,11 +66,11 @@ namespace Ntp.Analyzer.Config.Root Dictionary options = GetOptions (Params, config); return new NodeConfiguration ( - GetOptionConfigName (options, Params [0], String.Empty, false), + GetOptionConfigName (options, Identifier, String.Empty, false), config.IndentLevel, - GetOptionString (options, "IP", Params [0], false, "0.0.0.0"), - GetOptionInteger (options, "Port", Params [0], false, 9090) + GetOptionString (options, ConfigurationKeyword.ClusterNodeIp, Identifier, false, "127.0.0.1"), + GetOptionInteger (options, ConfigurationKeyword.ClusterNodeIp, Identifier, false, 9090) ); } } -} +} \ No newline at end of file diff --git a/Ntp.Analyzer/Config/Root/NotifyConfiguration.cs b/Ntp.Analyzer/Config/Root/NotifyConfiguration.cs index c47400e2..5e6dd83f 100644 --- a/Ntp.Analyzer/Config/Root/NotifyConfiguration.cs +++ b/Ntp.Analyzer/Config/Root/NotifyConfiguration.cs @@ -23,8 +23,10 @@ // 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.Localize; using Ntp.Config; using Ntp.Process; @@ -58,20 +60,20 @@ namespace Ntp.Analyzer.Config.Root this.ssl = ssl; } - public const string Identifier = "Notify"; + public const string Identifier = ConfigurationKeyword.Notify; private static readonly String[] Params = new[] { - Identifier, - "InitialRun", - "FixedRun", - "Frequency", - "Mail", - "Subject", - "Sender", - "SmtpHost", - "SmtpPort", - "SmtpUser", - "SmtpPass", - "EnableSsl" + ConfigurationKeyword.Notify, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun, + ConfigurationKeyword.NotifyRecipient, + ConfigurationKeyword.NotifySubject, + ConfigurationKeyword.NotifySender, + ConfigurationKeyword.NotifySmtpHost, + ConfigurationKeyword.NotifySmtpPort, + ConfigurationKeyword.NotifySmtpUser, + ConfigurationKeyword.NotifySmtpPass, + ConfigurationKeyword.NotifyEnableSsl }; private readonly string mail; @@ -119,9 +121,9 @@ namespace Ntp.Analyzer.Config.Root get { return new object[] { ConfigName, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0, Frequency, + InitialRun, + FixedRun, mail, subject, sender, @@ -129,7 +131,7 @@ namespace Ntp.Analyzer.Config.Root port, user, pass, - ssl ? 1 : 0 + ssl }; } } @@ -147,19 +149,19 @@ namespace Ntp.Analyzer.Config.Root Dictionary options = GetOptions (Params, config); return new NotifyConfiguration ( - GetOptionConfigName (options, Params [0], String.Empty, false), + GetOptionConfigName (options, Identifier, String.Empty, false), config.IndentLevel, - GetOptionBoolean (options, "InitialRun", Params [0], false, false), - GetOptionBoolean (options, "FixedRun", Params [0], false, true), - GetOptionInteger (options, "Frequency", Params [0], true, -1), - GetOptionString (options, "Mail", Params [0], true), - GetOptionString (options, "Subject", Params [0], true), - GetOptionString (options, "Sender", Params [0], true), - GetOptionString (options, "SmtpHost", Params [0], true), - GetOptionInteger (options, "SmtpPort", Params [0], false, 25), - GetOptionString (options, "SmtpUser", Params [0], false), - GetOptionString (options, "SmtpPass", Params [0], false), - GetOptionBoolean (options, "EnableSsl", Params [0], false) + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, false, false), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, false, true), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true, -1), + GetOptionString (options, ConfigurationKeyword.NotifyRecipient, Identifier, true), + GetOptionString (options, ConfigurationKeyword.NotifySubject, Identifier, true), + GetOptionString (options, ConfigurationKeyword.NotifySender, Identifier, true), + GetOptionString (options, ConfigurationKeyword.NotifySmtpHost, Identifier, true), + GetOptionInteger (options, ConfigurationKeyword.NotifySmtpPort, Identifier, false, 25), + GetOptionString (options, ConfigurationKeyword.NotifySmtpUser, Identifier, false), + GetOptionString (options, ConfigurationKeyword.NotifySmtpPass, Identifier, false), + GetOptionBoolean (options, ConfigurationKeyword.NotifyEnableSsl, Identifier, false) ); } } diff --git a/Ntp.Analyzer/Config/Root/ReadingBulkConfiguration.cs b/Ntp.Analyzer/Config/Root/ReadingBulkConfiguration.cs index 7c962ff2..f311f90e 100644 --- a/Ntp.Analyzer/Config/Root/ReadingBulkConfiguration.cs +++ b/Ntp.Analyzer/Config/Root/ReadingBulkConfiguration.cs @@ -23,8 +23,10 @@ // 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.Localize; using Ntp.Config; using Ntp.Process; @@ -49,14 +51,15 @@ namespace Ntp.Analyzer.Config.Root this.name = name; } - public const string Identifier = "Reading"; + public const string Identifier = ConfigurationKeyword.Reading; private static readonly String[] Params = new[] { - Identifier, - "Name", - "Frequency", - "InitialRun", - "FixedRun" + ConfigurationKeyword.Reading, + ConfigurationKeyword.ReadingName, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun }; + private readonly string name; public string Name { @@ -69,8 +72,8 @@ namespace Ntp.Analyzer.Config.Root ConfigName, Name, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0 + InitialRun, + FixedRun }; } } @@ -88,12 +91,12 @@ namespace Ntp.Analyzer.Config.Root Dictionary options = GetOptions (Params, config); return new ReadingBulkConfiguration ( - GetOptionConfigName (options, Params [0], String.Empty, false), + GetOptionConfigName (options, ConfigurationKeyword.Reading, String.Empty, false), config.IndentLevel, - GetOptionString (options, "Name", Params [0], true), - GetOptionInteger (options, "Frequency", Params [0], true), - GetOptionBoolean (options, "InitialRun", Params [0], true), - GetOptionBoolean (options, "FixedRun", Params [0], true) + GetOptionString (options, ConfigurationKeyword.ReadingName, Identifier, true), + GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, true), + GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, true) ); } } diff --git a/Ntp.Analyzer/Config/ServerConfiguration.cs b/Ntp.Analyzer/Config/ServerConfiguration.cs index 085ef686..39f6a3a9 100644 --- a/Ntp.Analyzer/Config/ServerConfiguration.cs +++ b/Ntp.Analyzer/Config/ServerConfiguration.cs @@ -23,6 +23,7 @@ // 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.Config; @@ -31,6 +32,7 @@ using Ntp.Analyzer.Config.Navigation; using Ntp.Analyzer.Config.Page; using Ntp.Analyzer.Config.Root; using Ntp.Analyzer.Config.Stats; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Config { @@ -42,7 +44,6 @@ namespace Ntp.Analyzer.Config int hostId, string serverName, ServerType serverType, - string configFile, string filePath, string webPath) : base(configName, indentLevel) @@ -50,7 +51,6 @@ namespace Ntp.Analyzer.Config this.hostId = hostId; this.serverName = serverName; this.serverType = serverType; - this.configFile = configFile; this.filePath = filePath; this.webPath = webPath; @@ -62,30 +62,29 @@ namespace Ntp.Analyzer.Config peerGraphs = new List (); } - public const string Identifier = "Server"; + public const string Identifier = ConfigurationKeyword.Server; private static readonly String[] Params = new[] { - Identifier, - "HostID", - "HostAddress", - "HostType", - "ConfigFile", - "FilePath", - "WebPath", - "Menu", - "AboutPage", - "HostPage", - "HostGraph", - "TrafficGraph", - "PeerPages", - "PeerGraphs", - "PeerSummaryPage", - "HostGraphPage", - "PeerGraphPage", - "HostStats", - "HostIOStats", - "PeerStats" + ConfigurationKeyword.Server, + ConfigurationKeyword.ServerHostId, + ConfigurationKeyword.ServerHostAddress, + ConfigurationKeyword.ServerHostType, + ConfigurationKeyword.ServerFilePath, + ConfigurationKeyword.ServerWebPath, + MenuConfiguration.Identifier, + AboutPageConfiguration.Identifier, + HostPageConfiguration.Identifier, + HostGraphConfiguration.Identifier, + TrafficGraphConfiguration.Identifier, + PeerPageConfiguration.Identifier, + PeerGraphConfiguration.Identifier, + PeerSummaryPageConfiguration.Identifier, + HostGraphPageConfiguration.Identifier, + PeerGraphPageConfiguration.Identifier, + HostStatConfiguration.Identifier, + HostIOStatConfiguration.Identifier, + PeerStatConfiguration.Identifier }; - private readonly string configFile; + private readonly string filePath; private readonly List hostGraphs; private readonly List trafficGraphs; @@ -117,10 +116,6 @@ namespace Ntp.Analyzer.Config get { return serverType; } } - public string ConfigFile { - get { return configFile; } - } - public string FilePath { get { return filePath; } } @@ -188,7 +183,6 @@ namespace Ntp.Analyzer.Config hostId, serverName, GetServerTypeString(serverType), - configFile, filePath, webPath, menu, @@ -212,11 +206,11 @@ namespace Ntp.Analyzer.Config { switch (type) { case ServerType.Ntpdc: - return "ntpdc"; + return ConfigurationKeyword.ServerTypeNtpdc; case ServerType.Ntpq: - return "ntpq"; + return ConfigurationKeyword.ServerTypeNtpq; default: - return "unknown"; + return ConfigurationKeyword.ServerTypeUnknown; } } @@ -226,21 +220,17 @@ namespace Ntp.Analyzer.Config string configPath) { if (!options.ContainsKey (type) || options [type].Trim () == String.Empty) { - ConfigError (String.Format ( - "No value for setting {0} in section {1} was specified.", - type, configPath)); + ConfigError (String.Format (ConfigurationMessage.NoValueForSetting, type, configPath)); return ServerType.Unknown; } switch (options [type].Trim ()) { - case "ntpdc": + case ConfigurationKeyword.ServerTypeNtpdc: return ServerType.Ntpdc; - case "ntpq": + case ConfigurationKeyword.ServerTypeNtpq: return ServerType.Ntpq; default: - ConfigError (String.Format ( - "Invalid value for setting {0} in section {1}. Specify either ntpq or ntpdc.", - type, configPath)); + ConfigError (String.Format (ConfigurationMessage.InvalidValue, type, configPath)); return ServerType.Unknown; } } @@ -255,47 +245,49 @@ namespace Ntp.Analyzer.Config Dictionary options = GetOptions (Params, configBlock); ServerConfiguration config = new ServerConfiguration ( - GetOptionConfigName (options, Params [0], Params [0], true), - configBlock.IndentLevel, - GetOptionInteger (options, Params [1], Params [0], true), - GetOptionString (options, Params [2], Params [0], true), - GetServerTypeString (options, Params [3], Params [0]), - GetOptionString (options, Params [4], Params [0], false), - GetOptionString (options, Params [5], Params [0], false), - GetOptionString (options, Params [6], Params [0], false) - ); + GetOptionConfigName (options, Identifier, Identifier, true), + configBlock.IndentLevel, + GetOptionInteger (options, ConfigurationKeyword.ServerHostId, Identifier, true), + GetOptionString (options, ConfigurationKeyword.ServerHostAddress, Identifier, true), + GetServerTypeString (options, ConfigurationKeyword.ServerHostType, Identifier), + GetOptionString (options, ConfigurationKeyword.ServerFilePath, Identifier, false), + GetOptionString (options, ConfigurationKeyword.ServerWebPath, Identifier, false) + ); - // Set sub configuration blocks ConfigurationBlock block; - block = FindSingleBlock (Params [17], configBlock); + block = FindSingleBlock (HostStatConfiguration.Identifier, configBlock); config.hostStats = block != null ? HostStatConfiguration.Create (config, bulk, block) : null; - block = FindSingleBlock (Params [18], configBlock); + block = FindSingleBlock (HostIOStatConfiguration.Identifier, configBlock); config.hostIoStats = block != null ? HostIOStatConfiguration.Create (config, bulk, block) : null; - block = FindSingleBlock (Params [19], configBlock); + block = FindSingleBlock (PeerStatConfiguration.Identifier, configBlock); config.peerStats = block != null ? PeerStatConfiguration.Create (config, bulk, block) : null; - block = FindSingleBlock (Params [8], configBlock); + block = FindSingleBlock (AboutPageConfiguration.Identifier, configBlock); config.aboutPage = block != null ? AboutPageConfiguration.Create (config, block) : null; - ConfigurationBlock[] hostGraphBlock = FindBlocks (Params [10], configBlock); + ConfigurationBlock[] hostGraphBlock = FindBlocks ( + HostGraphConfiguration.Identifier, configBlock); foreach (ConfigurationBlock hostBlock in hostGraphBlock) { config.hostGraphs.Add (HostGraphConfiguration.Create (config, hostBlock)); } - ConfigurationBlock[] trafficGraphBlocks = FindBlocks (Params [11], configBlock); + ConfigurationBlock[] trafficGraphBlocks = FindBlocks ( + TrafficGraphConfiguration.Identifier, configBlock); foreach (ConfigurationBlock trafficBlock in trafficGraphBlocks) { config.trafficGraphs.Add (TrafficGraphConfiguration.Create (config, trafficBlock)); } - ConfigurationBlock[] peerGraphBlock = FindBlocks (Params [13], configBlock); + ConfigurationBlock[] peerGraphBlock = FindBlocks ( + PeerGraphConfiguration.Identifier, configBlock); foreach (ConfigurationBlock peerBlock in peerGraphBlock) { config.peerGraphs.Add (PeerGraphConfiguration.Create (config, peerBlock)); } - ConfigurationBlock[] peerBlocks = FindBlocks (Params [12], configBlock); + ConfigurationBlock[] peerBlocks = FindBlocks ( + PeerPageConfiguration.Identifier, configBlock); foreach (ConfigurationBlock peerBlock in peerBlocks) { config.peerPages.Add (PeerPageConfiguration.Create ( config, @@ -303,7 +295,8 @@ namespace Ntp.Analyzer.Config config.peerGraphs)); } - ConfigurationBlock[] peerSummaryBlocks = FindBlocks (Params [14], configBlock); + ConfigurationBlock[] peerSummaryBlocks = FindBlocks ( + PeerSummaryPageConfiguration.Identifier, configBlock); foreach (ConfigurationBlock peerSummaryBlock in peerSummaryBlocks) { config.peerSummaryPages.Add (PeerSummaryPageConfiguration.Create ( config, peerSummaryBlock, @@ -315,7 +308,7 @@ namespace Ntp.Analyzer.Config graphs.AddRange (config.hostGraphs); graphs.AddRange (config.trafficGraphs); - ConfigurationBlock[] hostBlocks = FindBlocks (Params [9], configBlock); + ConfigurationBlock[] hostBlocks = FindBlocks (HostPageConfiguration.Identifier, configBlock); foreach (ConfigurationBlock hostBlock in hostBlocks) { config.hostPages.Add (HostPageConfiguration.Create ( config, @@ -325,14 +318,14 @@ namespace Ntp.Analyzer.Config config.PeerSummaryPages)); } - block = FindSingleBlock (Params [15], configBlock); + block = FindSingleBlock (HostGraphPageConfiguration.Identifier, configBlock); config.hostGraphPage = block != null ? HostGraphPageConfiguration.Create ( config, block, config.hostPages) : null; - block = FindSingleBlock (Params [16], configBlock); + block = FindSingleBlock (PeerGraphPageConfiguration.Identifier, configBlock); config.peerGraphPage = block != null ? PeerGraphPageConfiguration.Create ( config, @@ -347,7 +340,7 @@ namespace Ntp.Analyzer.Config linkables.AddRange (config.peerPages); linkables.AddRange (config.PeerSummaryPages); - block = FindSingleBlock (Params [7], configBlock); + block = FindSingleBlock (MenuConfiguration.Identifier, configBlock); config.menu = block != null ? MenuConfiguration.Create (block, linkables) : null; return config; diff --git a/Ntp.Analyzer/Config/ServerSubConfiguration.cs b/Ntp.Analyzer/Config/ServerSubConfiguration.cs index 7a0e8a7a..76a6e485 100644 --- a/Ntp.Analyzer/Config/ServerSubConfiguration.cs +++ b/Ntp.Analyzer/Config/ServerSubConfiguration.cs @@ -63,14 +63,6 @@ namespace Ntp.Analyzer.Config get { return server.ServerType; } } - /// - /// Gets the config file in the . - /// - /// The config file. - public string ConfigFile { - get { return server.ConfigFile; } - } - /// /// Gets the host identifier in the . /// diff --git a/Ntp.Analyzer/Config/Stats/HostIOStatConfiguration.cs b/Ntp.Analyzer/Config/Stats/HostIOStatConfiguration.cs index 33d54992..9e21daf3 100644 --- a/Ntp.Analyzer/Config/Stats/HostIOStatConfiguration.cs +++ b/Ntp.Analyzer/Config/Stats/HostIOStatConfiguration.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; using System.Collections.Generic; +using Ntp.Analyzer.Localize; using Ntp.Config; using Ntp.Analyzer.Config.Root; @@ -41,15 +42,16 @@ namespace Ntp.Analyzer.Config.Stats bool initialRun, bool fixedRun ) - : base(configName, indentLevel, server, bulk, frequency, initialRun, fixedRun) + : base (configName, indentLevel, server, bulk, frequency, initialRun, fixedRun) { } + public const string Identifier = ConfigurationKeyword.HostIOStats; private static readonly String[] Params = new[] { - "HostIOStats", - "Frequency", - "InitialRun", - "FixedRun" + ConfigurationKeyword.HostIOStats, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun }; protected override IEnumerable Items { @@ -57,15 +59,20 @@ namespace Ntp.Analyzer.Config.Stats return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0 + InitialRun, + FixedRun }; } } public override string ToString () { - return ConfigText (Params, Items); + return + Bulk == null ? + ConfigText (Params, Items) : + ConfigText ( + new[] { ConfigurationKeyword.HostIOStats, ConfigurationKeyword.Frequency }, + new[] { ConfigName, Bulk.Name }); } public static HostIOStatConfiguration Create ( @@ -75,7 +82,7 @@ namespace Ntp.Analyzer.Config.Stats { OptionSet options = GetOptions (Params, config); - string configName = GetOptionConfigName (options, Params[0], String.Empty, false); + string configName = GetOptionConfigName (options, ConfigurationKeyword.HostIOStats, String.Empty, false); bool initialRun = false; bool fixedRun = false; @@ -84,16 +91,18 @@ namespace Ntp.Analyzer.Config.Stats ReadingBulkConfiguration bulkConfig = null; // TODO: Implement handling of multimple ReadingBulkConfigurations - if (!Int32.TryParse (options[Params[1]], out frequency)) { - if (bulk != null && options[Params[1]] == bulk.Name) + if (!Int32.TryParse (options [ConfigurationKeyword.Frequency], out frequency)) { + if (bulk != null && options [ConfigurationKeyword.Frequency] == bulk.Name) bulkConfig = bulk; else { - ConfigError ("HostIOStats->Frequency is not defied correctly (" + configName + ")."); + ConfigError (String.Format ( + ConfigurationMessage.WrongReference, + ConfigurationKeyword.Frequency, Identifier, configName)); } } else { - frequency = GetOptionInteger (options, Params[1], Params[0], true); - initialRun = GetOptionBoolean (options, Params[2], Params[0], true); - fixedRun = GetOptionBoolean (options, Params[3], Params[0], true); + frequency = GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true); + initialRun = GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, true); + fixedRun = GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, true); } return new HostIOStatConfiguration ( diff --git a/Ntp.Analyzer/Config/Stats/HostStatConfiguration.cs b/Ntp.Analyzer/Config/Stats/HostStatConfiguration.cs index 483f5776..aafb3ea4 100644 --- a/Ntp.Analyzer/Config/Stats/HostStatConfiguration.cs +++ b/Ntp.Analyzer/Config/Stats/HostStatConfiguration.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; using System.Collections.Generic; +using Ntp.Analyzer.Localize; using Ntp.Config; using Ntp.Analyzer.Config.Root; @@ -45,11 +46,12 @@ namespace Ntp.Analyzer.Config.Stats { } + public const string Identifier = ConfigurationKeyword.HostStats; private static readonly String[] Params = new[] { - "HostStats", - "Frequency", - "InitialRun", - "FixedRun" + ConfigurationKeyword.HostStats, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun }; protected override IEnumerable Items { @@ -57,15 +59,20 @@ namespace Ntp.Analyzer.Config.Stats return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0 + InitialRun, + FixedRun }; } } public override string ToString () { - return ConfigText (Params, Items); + return + Bulk == null ? + ConfigText (Params, Items) : + ConfigText ( + new[] { ConfigurationKeyword.HostIOStats, ConfigurationKeyword.Frequency }, + new[] { ConfigName, Bulk.Name }); } public static HostStatConfiguration Create ( @@ -75,7 +82,7 @@ namespace Ntp.Analyzer.Config.Stats { OptionSet options = GetOptions (Params, config); - string configName = GetOptionConfigName (options, Params[0], String.Empty, false); + string configName = GetOptionConfigName (options, ConfigurationKeyword.HostStats, String.Empty, false); bool initialRun = false; bool fixedRun = false; @@ -84,16 +91,18 @@ namespace Ntp.Analyzer.Config.Stats ReadingBulkConfiguration bulkConfig = null; // TODO: Implement handling of multimple ReadingBulkConfigurations - if (!Int32.TryParse (options[Params[1]], out frequency)) { - if (bulk != null && options[Params[1]] == bulk.Name) + if (!Int32.TryParse (ConfigurationKeyword.Frequency, out frequency)) { + if (bulk != null && options [ConfigurationKeyword.Frequency] == bulk.Name) bulkConfig = bulk; else { - ConfigError ("HostStats->Frequency is not defied correctly (" + configName + ")."); + ConfigError (String.Format ( + ConfigurationMessage.WrongReference, + ConfigurationKeyword.Frequency, Identifier, configName)); } } else { - frequency = GetOptionInteger (options, Params[1], Params[0], true); - initialRun = GetOptionBoolean (options, Params[2], Params[0], true); - fixedRun = GetOptionBoolean (options, Params[3], Params[0], true); + frequency = GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true); + initialRun = GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, true); + fixedRun = GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, true); } return new HostStatConfiguration ( diff --git a/Ntp.Analyzer/Config/Stats/PeerStatConfiguration.cs b/Ntp.Analyzer/Config/Stats/PeerStatConfiguration.cs index 4b68c6d6..81d4282a 100644 --- a/Ntp.Analyzer/Config/Stats/PeerStatConfiguration.cs +++ b/Ntp.Analyzer/Config/Stats/PeerStatConfiguration.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; using System.Collections.Generic; +using Ntp.Analyzer.Localize; using Ntp.Config; using Ntp.Analyzer.Config.Root; @@ -45,11 +46,12 @@ namespace Ntp.Analyzer.Config.Stats { } + public const string Identifier = ConfigurationKeyword.PeerStats; private static readonly String[] Params = new[] { - "PeerStats", - "Frequency", - "InitialRun", - "FixedRun" + ConfigurationKeyword.PeerStats, + ConfigurationKeyword.Frequency, + ConfigurationKeyword.InitialRun, + ConfigurationKeyword.FixedRun }; protected override IEnumerable Items { @@ -57,15 +59,20 @@ namespace Ntp.Analyzer.Config.Stats return new object[] { ConfigName, Frequency, - InitialRun ? 1 : 0, - FixedRun ? 1 : 0 + InitialRun, + FixedRun }; } } public override string ToString () { - return ConfigText (Params, Items); + return + Bulk == null ? + ConfigText (Params, Items) : + ConfigText ( + new[] { ConfigurationKeyword.HostIOStats, ConfigurationKeyword.Frequency }, + new[] { ConfigName, Bulk.Name }); } public static PeerStatConfiguration Create ( @@ -75,7 +82,7 @@ namespace Ntp.Analyzer.Config.Stats { OptionSet options = GetOptions (Params, config); - string configName = GetOptionConfigName (options, Params[0], String.Empty, false); + string configName = GetOptionConfigName (options, ConfigurationKeyword.PeerStats, String.Empty, false); bool initialRun = false; bool fixedRun = false; @@ -84,16 +91,18 @@ namespace Ntp.Analyzer.Config.Stats ReadingBulkConfiguration bulkConfig = null; // TODO: Implement handling of multimple ReadingBulkConfigurations - if (!Int32.TryParse (options[Params[1]], out frequency)) { - if (bulk != null && options[Params[1]] == bulk.Name) + if (!Int32.TryParse (options [ConfigurationKeyword.Frequency], out frequency)) { + if (bulk != null && options [ConfigurationKeyword.Frequency] == bulk.Name) bulkConfig = bulk; else { - ConfigError ("PeerStats->Frequency is not defied correctly (" + configName + ")."); + ConfigError (String.Format ( + ConfigurationMessage.WrongReference, + ConfigurationKeyword.Frequency, Identifier, configName)); } } else { - frequency = GetOptionInteger (options, Params[1], Params[0], true); - initialRun = GetOptionBoolean (options, Params[2], Params[0], true); - fixedRun = GetOptionBoolean (options, Params[3], Params[0], true); + frequency = GetOptionInteger (options, ConfigurationKeyword.Frequency, Identifier, true); + initialRun = GetOptionBoolean (options, ConfigurationKeyword.InitialRun, Identifier, true); + fixedRun = GetOptionBoolean (options, ConfigurationKeyword.FixedRun, Identifier, true); } return new PeerStatConfiguration ( diff --git a/Ntp.Analyzer/Config/Stats/StatsConfiguration.cs b/Ntp.Analyzer/Config/Stats/StatsConfiguration.cs index 65f93ad9..f3b8a6db 100644 --- a/Ntp.Analyzer/Config/Stats/StatsConfiguration.cs +++ b/Ntp.Analyzer/Config/Stats/StatsConfiguration.cs @@ -23,6 +23,7 @@ // 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 Ntp.Analyzer.Config.Root; namespace Ntp.Analyzer.Config.Stats diff --git a/Ntp.Analyzer/Export/DirectoryStreamDestination.cs b/Ntp.Analyzer/Export/DirectoryStreamDestination.cs index 149535b1..1c3ef0a7 100644 --- a/Ntp.Analyzer/Export/DirectoryStreamDestination.cs +++ b/Ntp.Analyzer/Export/DirectoryStreamDestination.cs @@ -27,7 +27,7 @@ using System; using System.IO; using Ntp.Analyzer.Log; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Analyzer.Export { diff --git a/Ntp.Analyzer/Export/FileStreamDestination.cs b/Ntp.Analyzer/Export/FileStreamDestination.cs index 3ba3a0d0..29fee07d 100644 --- a/Ntp.Analyzer/Export/FileStreamDestination.cs +++ b/Ntp.Analyzer/Export/FileStreamDestination.cs @@ -27,7 +27,7 @@ using System; using System.IO; using Ntp.Analyzer.Log; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Analyzer.Export { diff --git a/Ntp.Analyzer/Graph/GraphBase.cs b/Ntp.Analyzer/Graph/GraphBase.cs index 788d265e..f855d007 100644 --- a/Ntp.Analyzer/Graph/GraphBase.cs +++ b/Ntp.Analyzer/Graph/GraphBase.cs @@ -131,6 +131,11 @@ namespace Ntp.Analyzer.Graph return Render (); } + public string ImageFileExtension + { + get { return "png"; } + } + public Stream Render () { MemoryStream stream = new MemoryStream (); @@ -152,7 +157,7 @@ namespace Ntp.Analyzer.Graph b = null; g = null; - // Forece garbage collection + // Force garbage collection GC.Collect (); } diff --git a/Ntp.Analyzer/Ntp.Analyzer.csproj b/Ntp.Analyzer/Ntp.Analyzer.csproj index 7a3fd2c9..e2c13553 100644 --- a/Ntp.Analyzer/Ntp.Analyzer.csproj +++ b/Ntp.Analyzer/Ntp.Analyzer.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + @@ -132,7 +137,6 @@ - @@ -142,6 +146,7 @@ + @@ -190,9 +195,13 @@ {C2DEBED1-FE91-4929-B686-8E920731E88C} NPlot - + + {6F200007-52DB-4861-A565-124270C07F67} + Ntp.Analyzer.Localize + + {A98DB601-2993-4181-A573-5FCCC5E954C1} - Ntp.System + Ntp.Interop \ No newline at end of file diff --git a/Ntp.Analyzer/Page/BootstrapPeerPageBuilder.cs b/Ntp.Analyzer/Page/BootstrapPeerPageBuilder.cs index df13ea54..c6280532 100644 --- a/Ntp.Analyzer/Page/BootstrapPeerPageBuilder.cs +++ b/Ntp.Analyzer/Page/BootstrapPeerPageBuilder.cs @@ -23,26 +23,22 @@ // 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.IO; +using Ntp.Analyzer.Objects; +using Ntp.Process; using Ntp.Analyzer.Config.Navigation; using Ntp.Analyzer.Config.Page; using Ntp.Analyzer.Export; -using Ntp.Analyzer.Objects; using Ntp.Analyzer.Render; using Ntp.Analyzer.Render.Peer; -using Ntp.Process; namespace Ntp.Analyzer.Page { public sealed class BootstrapPeerPageBuilder : PageBuilderBase { - private readonly Host host; - private readonly MenuConfiguration menu; - private readonly PeerPageConfiguration page; - private readonly Peer peer; - public BootstrapPeerPageBuilder ( Host host, Peer peer, @@ -55,6 +51,11 @@ namespace Ntp.Analyzer.Page this.page = page; } + private readonly Host host; + private readonly MenuConfiguration menu; + private readonly PeerPageConfiguration page; + private readonly Peer peer; + public override IEnumerable Destinations { get { return page.Destinations.Destinations; } } @@ -70,7 +71,7 @@ namespace Ntp.Analyzer.Page BootstrapPeerPageRender peerPage = new BootstrapPeerPageRender (page.WebPath, peer.Name, wait); peerPage.Add (new BootstrapMenuRender (page.WebPath, menu, page)); peerPage.Add (new BootstrapPeerInfoRender (page.WebPath, peer.Server, now, next, peer.Name)); - peerPage.Add (new BootstrapPeerGraphRender (page.WebPath, peer.Name, host, page, peer.Server, page.Graphs)); + peerPage.Add (new BootstrapPeerGraphRender (page.WebPath, peer, host, page, page.Graphs)); // Generate HTML HtmlRenderer htmlRender = new HtmlRenderer (peerPage); diff --git a/Ntp.Analyzer/Page/BootstrapPeerSummaryPageBuilder.cs b/Ntp.Analyzer/Page/BootstrapPeerSummaryPageBuilder.cs index 9ab14c90..669b3337 100644 --- a/Ntp.Analyzer/Page/BootstrapPeerSummaryPageBuilder.cs +++ b/Ntp.Analyzer/Page/BootstrapPeerSummaryPageBuilder.cs @@ -57,7 +57,7 @@ namespace Ntp.Analyzer.Page // Create page BootstrapSummaryPageRender PeerSummaryPage = new BootstrapSummaryPageRender(page.WebPath, page.ServerName); PeerSummaryPage.Add(new BootstrapMenuRender(page.WebPath, menu, page)); - PeerSummaryPage.Add(new BootstrapSummaryGraphRender(page.WebPath, page, page.Graphs)); + PeerSummaryPage.Add(new BootstrapSummaryGraphRender(page.WebPath, page.HostId, page, page.Graphs)); // Generate HTML HtmlRenderer htmlRender = new HtmlRenderer(PeerSummaryPage); diff --git a/Ntp.Analyzer/Page/DefaultPeerSummaryPageBuilder.cs b/Ntp.Analyzer/Page/DefaultPeerSummaryPageBuilder.cs index 9eb05a2b..e8f5f11d 100644 --- a/Ntp.Analyzer/Page/DefaultPeerSummaryPageBuilder.cs +++ b/Ntp.Analyzer/Page/DefaultPeerSummaryPageBuilder.cs @@ -51,7 +51,7 @@ namespace Ntp.Analyzer.Page { // Create page DefaultPeerSummaryPageRender PeerSummaryPage = new DefaultPeerSummaryPageRender(config.WebPath, config.ServerName); - PeerSummaryPage.Add(new DefaultPeerSummaryGraphRender(config, config.Graphs)); + PeerSummaryPage.Add(new DefaultPeerSummaryGraphRender(config.HostId, config, config.Graphs)); // Generate HTML HtmlRenderer htmlRender = new HtmlRenderer(PeerSummaryPage); diff --git a/Ntp.Analyzer/Render/Host/HostLineRender.cs b/Ntp.Analyzer/Render/Host/HostLineRender.cs index 6d2134a3..329a99ab 100644 --- a/Ntp.Analyzer/Render/Host/HostLineRender.cs +++ b/Ntp.Analyzer/Render/Host/HostLineRender.cs @@ -29,6 +29,7 @@ using System.Text; using Ntp.Analyzer.Config.Page; using Ntp.Analyzer.Objects.Live; using Ntp.Analyzer.Objects; +using Ntp.Analyzer.Localize; namespace Ntp.Analyzer.Render.Host { @@ -49,14 +50,36 @@ namespace Ntp.Analyzer.Render.Host get { return statusLine.Peer; } } - private NtpConfEntry Conf - { - get { return statusLine.Conf; } - } - private TimeServer Server { - get { return statusLine.Server; } + get { return statusLine.PeerActivity.Peer.Server; } + } + + private string PeerName { + get { + string name = statusLine.PeerActivity.Peer.Name; + return name.Substring (0, name.Length > 18 ? 18 : name.Length); + } + } + + private string Country { + get { + return Server != null ? Server.Country : String.Empty; + } + } + + private string Location { + get { + return + (Server == null || String.IsNullOrEmpty (Server.DisplayLocation)) ? + PageText.UnknownLocation : Server.DisplayLocation; + } + } + + private int PageId { + get { + return statusLine.PeerActivity.Id; + } } public override string RenderHead() @@ -68,13 +91,8 @@ namespace Ntp.Analyzer.Render.Host { StringBuilder builder = new StringBuilder (); - int? id = (Server != null ? Server.Id : statusLine.PeerId); - string name = Conf.Name.Substring (0, Conf.Name.Length > 18 ? 18 : Conf.Name.Length); - string country = (Server != null ? Server.Country : String.Empty); - string location = (Server != null ? Server.DisplayLocation : "Unknown"); - builder.Append ("" + Peer.TallyChar + ""); - builder.Append ("" + name + ""); + builder.Append ("" + PeerName + ""); builder.Append (@"" + Peer.Stratus + ""); builder.Append (@"" + Peer.LastPoll + ""); builder.Append (@"" + Peer.Poll + ""); @@ -82,14 +100,12 @@ namespace Ntp.Analyzer.Render.Host builder.Append (@"" + Peer.Delay.ToString ("0.000") + ""); builder.Append (@"" + Peer.Offset.ToString ("0.000") + ""); builder.Append (@"" + Peer.Jitter.ToString ("0.000") + ""); - if (id != null) { - builder.Append (@"" + country + ""); - builder.Append (@""); - builder.Append (location); - builder.AppendLine (""); - } + builder.Append (@"" + Country + ""); + builder.Append (@""); + builder.Append (Location); + builder.AppendLine (""); return builder.ToString (); } diff --git a/Ntp.Analyzer/Render/Peer/BootstrapPeerGraphRender.cs b/Ntp.Analyzer/Render/Peer/BootstrapPeerGraphRender.cs index 1a166e76..44137f94 100644 --- a/Ntp.Analyzer/Render/Peer/BootstrapPeerGraphRender.cs +++ b/Ntp.Analyzer/Render/Peer/BootstrapPeerGraphRender.cs @@ -28,133 +28,120 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Ntp.Analyzer.Data; +using Ntp.Analyzer.Objects; using Ntp.Analyzer.Config.Destination; using Ntp.Analyzer.Config.Graph; using Ntp.Analyzer.Config.Page; -using Ntp.Analyzer.Objects; namespace Ntp.Analyzer.Render.Peer { public sealed class BootstrapPeerGraphRender : HtmlObjectRender { - private readonly List graphs; - private readonly Objects.Host host; - private readonly PeerPageConfiguration page; - private readonly TimeServer server; - - /// - /// Initializes a new instance of the class. - /// - /// Web path. - /// Host. - /// Page. - /// Server. - /// Graphs. public BootstrapPeerGraphRender( string webPath, - string peerName, + Objects.Peer peer, Objects.Host host, PeerPageConfiguration page, - TimeServer server, IEnumerable graphs) : base(webPath) { - this.peerName = peerName; + this.peer = peer; this.host = host; this.page = page; - this.server = server; - this.graphs = new List(graphs); + this.graphs = new List (graphs); } - private readonly string peerName; + private readonly List graphs; + private readonly Objects.Peer peer; + private readonly Objects.Host host; + private readonly PeerPageConfiguration page; public override string RenderHead() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); - return builder.ToString(); + return builder.ToString (); } public override string Render() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); int count = 1; - foreach (GraphSetConfiguration graphSet in graphs) - { + PeerActivity activity = DataFace.Instance.PeerActivity. + Single (p => p.Host == host && p.Peer == peer && p.IsActive); + + foreach (GraphSetConfiguration graphSet in graphs) { string open = (count == 1) ? " in" : String.Empty; - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"

"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"

"); // Include panel counter - builder.Append(@" "); + builder.Append (@" "); - builder.AppendLine(@" " + graphSet.Title); - builder.AppendLine(@" "); - builder.AppendLine(@"

"); - builder.AppendLine(@"
"); + builder.AppendLine (@" " + graphSet.Title); + builder.AppendLine (@" "); + builder.AppendLine (@"

"); + builder.AppendLine (@"
"); // Include panel counter - builder.Append(@"
", open); - builder.AppendLine(); - builder.AppendLine(@"
"); + builder.Append (@"
", open); + builder.AppendLine (); + builder.AppendLine (@"
"); // TODO: Add links for images. - foreach (GraphBaseConfiguration graph in graphSet.Graphs) - { - builder.Append(@"
"); + foreach (GraphBaseConfiguration graph in graphSet.Graphs) { + builder.Append (@" "); + builder.AppendLine (@"
"); } - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); count++; } - return builder.ToString(); + return builder.ToString (); } public override string RenderFooter() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@" "); - return builder.ToString(); + return builder.ToString (); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Render/Peer/BootstrapPeerInfoRender.cs b/Ntp.Analyzer/Render/Peer/BootstrapPeerInfoRender.cs index eac08030..b192fbf3 100644 --- a/Ntp.Analyzer/Render/Peer/BootstrapPeerInfoRender.cs +++ b/Ntp.Analyzer/Render/Peer/BootstrapPeerInfoRender.cs @@ -26,17 +26,15 @@ using System; using System.Globalization; +using System.Net; using System.Text; +using Ntp.Analyzer.Localize; using Ntp.Analyzer.Objects; namespace Ntp.Analyzer.Render.Peer { public sealed class BootstrapPeerInfoRender : HtmlObjectRender { - private readonly DateTime next; - private readonly DateTime now; - private readonly TimeServer server; - public BootstrapPeerInfoRender(string webPath, TimeServer server, DateTime now, DateTime next, string name) : base(webPath) { @@ -47,199 +45,276 @@ namespace Ntp.Analyzer.Render.Peer } private readonly string name; + private readonly DateTime next; + private readonly DateTime now; + private readonly TimeServer server; + + private string Name { + get { + if (server == null || String.IsNullOrEmpty (server.Name)) + return name; + + return server.Name; + } + } + + private string StratumText { + get { + if (server == null || server.Stratum == 0) + return null; + + switch (server.Stratum) { + case 1: + return PageText.Stratum1; + case 2: + return PageText.Stratum2; + case 3: + return PageText.Stratum3; + case 4: + return PageText.Stratum4; + case 5: + return PageText.Stratum5; + case 6: + return PageText.Stratum6; + case 7: + return PageText.Stratum7; + default: + return null; + } + } + } + + public string Time { + get { + return String.Concat ( + now.ToLongDateString (), + " ", + TimeZoneInfo.Local.IsDaylightSavingTime (now) ? + TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName, + " ", + now.ToLongTimeString () + ); + } + } + + public string Location { + get { + if (server == null || String.IsNullOrEmpty (server.Location)) + return PageText.HtmlBlank; + + return server.Location; + } + } + + private string ServerSync { + get { + if (server == null || String.IsNullOrEmpty (server.Server)) + return PageText.HtmlBlank; + + return server.Server; + } + } + + private string IpV4Address { + get { + if (server == null || server.Address == null || server.Address == IPAddress.None) + return PageText.HtmlBlank; + + return server.Address.ToString (); + } + } + + private string ServerAccess { + get { + if (server == null || String.IsNullOrEmpty (server.AccessPolicy)) + return PageText.HtmlBlank; + + switch (server.AccessPolicy) { + case ConfigurationKeyword.NtpAccessPolicyOpen: + return PageText.AccessPolicyOpen; + default: + return PageText.AccessPolicyUnknown; + } + } + } + + private string IpV6Address { + get { + if (server == null || String.IsNullOrEmpty (server.V6Address)) + return PageText.HtmlBlank; + + return server.V6Address.ToString (); + } + } + + private string ServiceArea { + get { + if (server == null || String.IsNullOrEmpty (server.ServiceArea)) + return PageText.HtmlBlank; + + string description = server.ServiceArea.Trim (); + string firstLetter = description.Substring (0, 1); + string rest = description.Substring (1); + + return firstLetter.ToUpper () + rest; + } + } + + private string PoolMemberStatus { + get { + if (server == null) + return PageText.HtmlBlank; + + return server.IsPoolMember ? + PageText.PoolMemberYes : + PageText.PoolMemberNo; + } + } + + private string PoolMemberLink { + get { + if (server == null || !server.IsPoolMember) + return null; + + StringBuilder builder = new StringBuilder (); + builder.Append (@"View info on pool.ntp.org »"); + return builder.ToString (); + } + } + + private string ProviderLink { + get { + if (server == null || String.IsNullOrEmpty (server.ProviderPage)) + return null; + + StringBuilder builder = new StringBuilder (); + builder.Append (@"View info on "); + builder.Append (server.ProviderPage); + builder.Append (" »"); + return builder.ToString (); + } + } public override string RenderHead() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); - builder.Append("

"); - builder.Append(server != null ? server.Name : name); - builder.Append("

    

Stratum "); - builder.Append(server != null ? GetStratumText() : String.Empty); - builder.AppendLine(" server

"); + builder.Append ("

"); + builder.Append (Name); + builder.Append ("

"); - builder.Append("

"); + if (StratumText != null) { + builder.Append ("    

Stratum "); + builder.Append (StratumText); + builder.AppendLine (" server

"); + } - builder.Append (now.ToLongDateString () + " "); - builder.Append ((TimeZoneInfo.Local.IsDaylightSavingTime (now) ? - TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName)); - builder.Append (" " + now.ToLongTimeString () + ". "); + builder.Append ("

"); + builder.Append (Time); + builder.Append (". "); + builder.Append ("Next refresh scheduled at "); + builder.Append (next.ToShortTimeString ()); + builder.AppendLine (".

"); - builder.Append("Next refresh scheduled at "); - builder.Append(next.ToShortTimeString()); - builder.AppendLine(".

"); - - return builder.ToString(); + return builder.ToString (); } public override string Render() { - const string na = ""; - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - builder.AppendLine(@"
"); - builder.AppendLine(@"
Server location
"); - builder.AppendLine(String.Format(@"
{0}
", - server != null ? server.Location : na)); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
Server location
"); + builder.Append (@"
"); + builder.Append (Location); + builder.AppendLine ("
"); + builder.AppendLine (@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"
Synchronization
"); - builder.AppendFormat(@"
{0}
", - server != null ? GetServerSync() : na); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
Synchronization
"); + builder.Append (@"
"); + builder.Append (ServerSync); + builder.AppendLine ("
"); + builder.AppendLine (@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"
IP address
"); - builder.AppendLine(String.Format(@"
{0}
", - server != null && server.Address != null ? server.Address.ToString() : String.Empty)); - builder.AppendLine(@"
Access policy
"); - builder.AppendLine(String.Format(@"
{0}
", - server != null ? GetServerAccess() : na)); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
IP address
"); + builder.Append (@"
"); + builder.Append (IpV4Address); + builder.AppendLine ("
"); + + builder.AppendLine (@"
Access policy
"); + builder.Append (@"
"); + builder.Append (ServerAccess); + builder.AppendLine ("
"); + builder.AppendLine (@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"
IPv6 address
"); - builder.AppendLine(String.Format(@"
{0}
", - server != null && server.V6Address != null ? server.V6Address.ToString() : na)); - builder.AppendLine(@"
Service area
"); - builder.AppendLine(String.Format(@"
{0}
", - server != null ? GetServiceArea() : na)); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
IPv6 address
"); + builder.Append (@"
"); + builder.Append (IpV6Address); + builder.AppendLine (@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"
Pool member
"); - builder.AppendLine(String.Format(@"
{0}
", - server != null ? GetPoolMemberStatus() : na)); - builder.AppendLine(@"
Description
"); - builder.AppendLine(String.Format(@"
{0}
", - server != null ? server.Updated.ToLongDateString() : na )); - builder.AppendLine(@"
"); + builder.AppendLine (@"
Service area
"); + builder.Append (@"
"); + builder.Append (ServiceArea); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); - builder.AppendLine(@"

"); + builder.AppendLine (@"

"); + builder.AppendLine (@"
Pool member
"); + builder.Append (@"
"); + builder.Append (PoolMemberStatus); + builder.AppendLine (@"
"); - if (server != null && server.IsPoolMember) - { - builder.AppendLine(String.Format(@" {0}   ", GetPoolMemberLink())); + builder.AppendLine (@"
Description
"); + builder.Append (@"
"); + builder.Append (server != null ? server.Updated.ToLongDateString () : PageText.HtmlBlank); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); + + builder.AppendLine (@"

"); + + if (PoolMemberLink != null) { + builder.Append (@" "); + builder.Append (PoolMemberLink); + builder.AppendLine (@"   "); } - if (server != null && server.ProviderPage != null) - { - builder.AppendLine(String.Format(@" {0}   ", GetProviderLink())); + if (ProviderLink != null) { + builder.Append (@" "); + builder.Append (ProviderLink); + builder.AppendLine (@"   "); } if (server != null && server.Id <= 10000) { - builder.AppendLine( - String.Format( - @" View info on support.ntp.org »", - server.Id.ToString(CultureInfo.InvariantCulture).PadLeft(6, '0'))); + builder.Append (@" "); + builder.Append (@"View info on support.ntp.org »"); } - builder.AppendLine(@"

"); + builder.AppendLine (@"

"); - return builder.ToString(); + return builder.ToString (); } public override string RenderFooter() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - builder.AppendLine("
"); - builder.AppendLine("
"); + builder.AppendLine ("
"); + builder.AppendLine ("
"); - return builder.ToString(); + return builder.ToString (); } - - #region Translators - - private string GetStratumText() - { - switch (server.Stratum) - { - case 1: - return "one"; - case 2: - return "two"; - case 3: - return "three"; - case 4: - return "four"; - case 5: - return "five"; - case 6: - return "six"; - case 7: - return "seven"; - default: - return "Unknown"; - } - } - - private string GetServerSync() - { - return server.Server.Trim() != String.Empty ? server.Server : " "; - } - - private string GetServerAccess() - { - switch (server.AccessPolicy) - { - case "OpenAccess": - return "Open access"; - default: - return "Unknown"; - } - } - - private string GetServiceArea() - { - string description = server.ServiceArea.Trim(); - - if (description == String.Empty) - return " "; - - string firstLetter = description.Substring(0, 1); - string rest = description.Substring(1); - - return firstLetter.ToUpper() + rest; - } - - private string GetPoolMemberStatus() - { - return server.IsPoolMember - ? "Server is pool member" - : "Server is not a pool member"; - } - - private string GetPoolMemberLink() - { - if (!server.IsPoolMember) - return "Server is not a pool member"; - - StringBuilder builder = new StringBuilder(); - builder.Append(@"View info on pool.ntp.org »"); - return builder.ToString(); - } - - private string GetProviderLink() - { - if (server.ProviderPage == null) - return "Not found"; - - StringBuilder builder = new StringBuilder(); - builder.Append(@"View info on "); - builder.Append(server.ProviderPage); - builder.Append(" »"); - return builder.ToString(); - } - - #endregion } } \ No newline at end of file diff --git a/Ntp.Analyzer/Render/Peer/DefaultPeerInfoRender.cs b/Ntp.Analyzer/Render/Peer/DefaultPeerInfoRender.cs index 305dbb7a..4a0e066c 100644 --- a/Ntp.Analyzer/Render/Peer/DefaultPeerInfoRender.cs +++ b/Ntp.Analyzer/Render/Peer/DefaultPeerInfoRender.cs @@ -42,7 +42,7 @@ namespace Ntp.Analyzer.Render.Peer this.name = name; } - private const string na = "N/A"; + private const string na = " "; private readonly string name; public override string RenderHead() diff --git a/Ntp.Analyzer/Render/Summary/BootstrapSummaryGraphRender.cs b/Ntp.Analyzer/Render/Summary/BootstrapSummaryGraphRender.cs index c0d99eb1..26579b7f 100644 --- a/Ntp.Analyzer/Render/Summary/BootstrapSummaryGraphRender.cs +++ b/Ntp.Analyzer/Render/Summary/BootstrapSummaryGraphRender.cs @@ -38,111 +38,101 @@ namespace Ntp.Analyzer.Render.Summary { public sealed class BootstrapSummaryGraphRender : HtmlObjectRender { - private readonly List graphs; - private readonly PeerSummaryPageConfiguration page; - public BootstrapSummaryGraphRender( string webPath, + int hostId, PeerSummaryPageConfiguration page, IEnumerable graphs) : base(webPath) { + this.hostId = hostId; this.page = page; - this.graphs = new List(graphs); + this.graphs = new List (graphs); } + private readonly int hostId; + private readonly List graphs; + private readonly PeerSummaryPageConfiguration page; + public override string RenderHead() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); - return builder.ToString(); + return builder.ToString (); } public override string Render() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); int count = 1; // TODO: Add host graph - foreach (GraphSetConfiguration graphSet in graphs) - { + foreach (GraphSetConfiguration graphSet in graphs) { string open = (count == 1) ? " in" : String.Empty; - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"

"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"

"); // Include panel counter - builder.Append(@" "); + builder.Append (@" "); - builder.AppendLine(@" " + graphSet.Title); - builder.AppendLine(@" "); - builder.AppendLine(@"

"); - builder.AppendLine(@"
"); + builder.AppendLine (@" " + graphSet.Title); + builder.AppendLine (@" "); + builder.AppendLine (@"

"); + builder.AppendLine (@"
"); // Include panel counter - builder.Append(@"
", open); - builder.AppendLine(); - builder.AppendLine(@"
"); + builder.Append (@"
", open); + builder.AppendLine (); + builder.AppendLine (@"
"); - foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[page.ConfigFile]) - { - IEnumerable peers = DataFace.Instance.Peers.Where(p => p.Ip == entry.Address.ToString()); - if (peers.Count () == 0) { - throw new ApplicationException (String.Format ( - "Peer with IP {0} was not found in database.", - entry.Address.ToString () - )); - } - Objects.Peer peer = peers.Single(); + var peers = DataFace.Instance.PeerActivity. + Where (p => p.Host.Id == hostId && p.IsActive); - // TODO: Add links for images. - foreach (GraphBaseConfiguration graph in graphSet.Graphs) - { - int id = peer.OrgId ?? peer.Id; - string name = peer.Server != null ? peer.Server.Name : peer.Name; - - builder.Append(@" "); + foreach (PeerActivity entry in peers) { + foreach (GraphBaseConfiguration graph in graphSet.Graphs) { + builder.Append (@" "); } } - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@"
"); count++; } - return builder.ToString(); + return builder.ToString (); } public override string RenderFooter() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - builder.AppendLine(@"
"); - builder.AppendLine(@"
"); + builder.AppendLine (@"
"); + builder.AppendLine (@" "); - return builder.ToString(); + return builder.ToString (); } } } \ No newline at end of file diff --git a/Ntp.Analyzer/Render/Summary/DefaultPeerSummaryGraphRender.cs b/Ntp.Analyzer/Render/Summary/DefaultPeerSummaryGraphRender.cs index b5d76875..70bd27a5 100644 --- a/Ntp.Analyzer/Render/Summary/DefaultPeerSummaryGraphRender.cs +++ b/Ntp.Analyzer/Render/Summary/DefaultPeerSummaryGraphRender.cs @@ -38,18 +38,21 @@ namespace Ntp.Analyzer.Render.Summary { public sealed class DefaultPeerSummaryGraphRender : HtmlObjectRender { - private readonly List graphs; - private readonly PeerSummaryPageConfiguration page; - public DefaultPeerSummaryGraphRender( + int hostId, PeerSummaryPageConfiguration page, IEnumerable graphs) : base(page.WebPath) { + this.hostId = hostId; this.page = page; this.graphs = new List(graphs); } + private readonly int hostId; + private readonly List graphs; + private readonly PeerSummaryPageConfiguration page; + public override string RenderHead() { return String.Empty; @@ -57,43 +60,28 @@ namespace Ntp.Analyzer.Render.Summary public override string Render() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder (); - // TODO: Add host graph - - foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[page.ConfigFile]) - { - IEnumerable peers = DataFace.Instance.Peers.Where(p => p.Ip == entry.Address.ToString()); - if (peers.Count () == 0) { - throw new ApplicationException (String.Format ( - "Peer with IP {0} was not found in database.", - entry.Address.ToString () - )); - } - - Objects.Peer peer = peers.Single(); - - foreach (GraphSetConfiguration graphSet in graphs) - { - foreach (GraphBaseConfiguration graph in graphSet.Graphs) - { - int id = peer.OrgId ?? peer.Id; - string name = peer.Server != null ? peer.Server.Name : peer.Name; - - builder.Append(@""); - builder.Append(@""); - builder.AppendLine(@""); + var peers = DataFace.Instance.PeerActivity. + Where (p => p.Host.Id == hostId && p.IsActive); + + foreach (PeerActivity entry in peers) { + foreach (GraphSetConfiguration graphSet in graphs) { + foreach (GraphBaseConfiguration graph in graphSet.Graphs) { + builder.Append (@""); + builder.Append (@""); + builder.AppendLine (@""); } } } - return builder.ToString(); + return builder.ToString (); } public override string RenderFooter() diff --git a/Ntp.Analyzer/Statistics/StatusBuilder.cs b/Ntp.Analyzer/Statistics/StatusBuilder.cs index 0b7f5671..ec4e6fdb 100644 --- a/Ntp.Analyzer/Statistics/StatusBuilder.cs +++ b/Ntp.Analyzer/Statistics/StatusBuilder.cs @@ -35,16 +35,16 @@ namespace Ntp.Analyzer.Statistics { public class StatusBuilder { - private readonly FileInfo configuration; - private readonly List entries = new List(); - private readonly ServerName server; - - public StatusBuilder(ServerName server, FileInfo configuration) + public StatusBuilder(ServerName server, Host host) { this.server = server; - this.configuration = configuration; + this.host = host; } + private readonly List entries = new List(); + private readonly ServerName server; + private readonly Host host; + public List Entries { get { return entries; } @@ -52,33 +52,19 @@ namespace Ntp.Analyzer.Statistics public void Build() { - IEnumerable config = DataFace.Instance.NtpConfigCache [configuration.FullName]; + var peers = + DataFace.Instance.PeerActivity. + Where (p => p.Host.Id == host.Id && p.IsActive); - foreach (NtpConfEntry entry in config) - { - AssociationEntry peerStatus = DataFace.Instance.NtpqCache[server.Name]. - SingleOrDefault(p => p.Remote == entry.Address.ToString()); + foreach (PeerActivity entry in peers) { + AssociationEntry peerStatus = DataFace.Instance.NtpqCache [server.Name]. + SingleOrDefault (p => p.Remote == entry.Peer.Ip); if (peerStatus == null) continue; - int? peerId = null; - TimeServer timeServer = null; - if (entry.OrgId.HasValue) { - timeServer = DataFace.Instance.Servers [entry.OrgId.Value]; - } else { - Peer peer = DataFace.Instance.Peers.SingleOrDefault (p => p.Ip == peerStatus.Remote); - if (peer != null) { - if (peer.OrgId.HasValue) { - timeServer = DataFace.Instance.Servers [peer.OrgId.Value]; - } else { - peerId = peer.Id; - } - } - } - - StatusLine line = new StatusLine(peerStatus, entry, timeServer, peerId); - entries.Add(line); + StatusLine line = new StatusLine (peerStatus, entry); + entries.Add (line); } } } diff --git a/Ntp.Analyzer/Statistics/SummaryBuilder.cs b/Ntp.Analyzer/Statistics/SummaryBuilder.cs deleted file mode 100644 index 8a76b9f4..00000000 --- a/Ntp.Analyzer/Statistics/SummaryBuilder.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// SummaryBuilder.cs -// -// Author: -// Carsten Sonne Larsen -// -// Copyright (c) 2013-2016 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.Collections.Generic; -using System.IO; -using System.Linq; -using Ntp.Analyzer.Data; -using Ntp.Analyzer.Objects; -using Ntp.Analyzer.Objects.Live; - -namespace Ntp.Analyzer.Statistics -{ - public class SummaryBuilder - { - private readonly FileInfo configuration; - private readonly List entries = new List(); - private readonly ServerName server; - - public SummaryBuilder(ServerName server, FileInfo configuration) - { - this.server = server; - this.configuration = configuration; - } - - public List Entries - { - get { return entries; } - } - - public void Build() - { - foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[configuration.FullName]) - { - AssociationEntry peerStatus = DataFace.Instance.NtpqCache[server.Name]. - SingleOrDefault(p => p.Remote == entry.Address.ToString()); - - if (peerStatus == null) - continue; - - int? peerId = null; - TimeServer timeServer = null; - if (entry.OrgId.HasValue) { - timeServer = DataFace.Instance.Servers [entry.OrgId.Value]; - } else { - Peer peer = DataFace.Instance.Peers.SingleOrDefault (p => p.Ip == peerStatus.Remote); - if (peer != null) { - if (peer.OrgId.HasValue) { - timeServer = DataFace.Instance.Servers [entry.OrgId.Value]; - } else { - peerId = peer.Id; - } - } - } - - StatusLine line = new StatusLine(peerStatus, entry, timeServer, peerId); - entries.Add(line); - } - } - } -} \ No newline at end of file diff --git a/Ntp.Config/ConfigurationBase.cs b/Ntp.Config/ConfigurationBase.cs index ed424f3d..7fc8260e 100644 --- a/Ntp.Config/ConfigurationBase.cs +++ b/Ntp.Config/ConfigurationBase.cs @@ -119,8 +119,12 @@ namespace Ntp.Config } else { + object value = valueList [i]; + if (value is bool) { + value = (int)((bool)value ? (int)1 : (int)0); + } text.Append(indentContent); - text.AppendFormat("{0} {1}", settings[i], valueList[i]); + text.AppendFormat("{0} {1}", settings[i], value); text.AppendLine(); } } @@ -254,7 +258,7 @@ namespace Ntp.Config foreach (string option in options) { - if (line.StartsWith(option)) + if (line.StartsWith(option + " ")) { result[option] = value; break; diff --git a/Ntp.Config/Ntp.Config.csproj b/Ntp.Config/Ntp.Config.csproj index 8dcea33c..3d4788dc 100644 --- a/Ntp.Config/Ntp.Config.csproj +++ b/Ntp.Config/Ntp.Config.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.Data/Ntp.Data.csproj b/Ntp.Data/Ntp.Data.csproj index d679799b..af1f53a0 100644 --- a/Ntp.Data/Ntp.Data.csproj +++ b/Ntp.Data/Ntp.Data.csproj @@ -32,6 +32,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.System/DirectoryCommand.cs b/Ntp.Interop/DirectoryCommand.cs similarity index 99% rename from Ntp.System/DirectoryCommand.cs rename to Ntp.Interop/DirectoryCommand.cs index 0e6479b8..03db29dd 100644 --- a/Ntp.System/DirectoryCommand.cs +++ b/Ntp.Interop/DirectoryCommand.cs @@ -23,12 +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 System.Collections.Generic; -using System.Linq; using System.IO; +using System.Linq; -namespace Ntp.System +namespace Ntp.Interop { public static class DirectoryCommand { diff --git a/Ntp.System/InterProcess.cs b/Ntp.Interop/InterProcess.cs similarity index 99% rename from Ntp.System/InterProcess.cs rename to Ntp.Interop/InterProcess.cs index 6b5c7e57..e3f456f9 100644 --- a/Ntp.System/InterProcess.cs +++ b/Ntp.Interop/InterProcess.cs @@ -33,7 +33,7 @@ using Mono.Unix.Native; using System.Threading; #endif -namespace Ntp.System +namespace Ntp.Interop { public static class InterProcess { diff --git a/Ntp.System/Ntp.System.csproj b/Ntp.Interop/Ntp.Interop.csproj similarity index 88% rename from Ntp.System/Ntp.System.csproj rename to Ntp.Interop/Ntp.Interop.csproj index 32a8a84f..cfa89019 100644 --- a/Ntp.System/Ntp.System.csproj +++ b/Ntp.Interop/Ntp.Interop.csproj @@ -7,8 +7,8 @@ 2.0 {A98DB601-2993-4181-A573-5FCCC5E954C1} Library - Ntp.System - Ntp.System + Ntp.Interop + Ntp.Interop 0.4.2b @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + @@ -44,7 +49,6 @@ - diff --git a/Ntp.System/Options.cs b/Ntp.Interop/Options.cs similarity index 99% rename from Ntp.System/Options.cs rename to Ntp.Interop/Options.cs index af7ddf66..9e71b37d 100644 --- a/Ntp.System/Options.cs +++ b/Ntp.Interop/Options.cs @@ -161,7 +161,7 @@ using MessageLocalizerConverter = System.Converter; namespace NDesk.Options #else //namespace Mono.Options -namespace Ntp.System +namespace Ntp.Interop #endif { static class StringCoda { diff --git a/Ntp.System/ProcessInfo.cs b/Ntp.Interop/ProcessInfo.cs similarity index 98% rename from Ntp.System/ProcessInfo.cs rename to Ntp.Interop/ProcessInfo.cs index 55b48c63..4b4544dc 100644 --- a/Ntp.System/ProcessInfo.cs +++ b/Ntp.Interop/ProcessInfo.cs @@ -30,7 +30,7 @@ using Mono.Unix.Native; System.Diagnostics #endif -namespace Ntp.System +namespace Ntp.Interop { public class ProcessInfo { diff --git a/Ntp.System/Properties/AssemblyInfo.cs b/Ntp.Interop/Properties/AssemblyInfo.cs similarity index 100% rename from Ntp.System/Properties/AssemblyInfo.cs rename to Ntp.Interop/Properties/AssemblyInfo.cs diff --git a/Ntp.System/ShellCommand.cs b/Ntp.Interop/ShellCommand.cs similarity index 99% rename from Ntp.System/ShellCommand.cs rename to Ntp.Interop/ShellCommand.cs index 8ba0d0b7..fc1b8dc5 100644 --- a/Ntp.System/ShellCommand.cs +++ b/Ntp.Interop/ShellCommand.cs @@ -23,12 +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 System.Diagnostics; using System.IO; using Ntp.Analyzer.Log; -namespace Ntp.System +namespace Ntp.Interop { public sealed class ShellCommand { diff --git a/Ntp.Monitor.Cli/Ntp.Monitor.Cli.csproj b/Ntp.Monitor.Cli/Ntp.Monitor.Cli.csproj index f7043ce7..24411355 100644 --- a/Ntp.Monitor.Cli/Ntp.Monitor.Cli.csproj +++ b/Ntp.Monitor.Cli/Ntp.Monitor.Cli.csproj @@ -9,7 +9,6 @@ Exe Ntp.Monitor.Cli 0.4.2b - ntpac true @@ -21,6 +20,7 @@ 4 true 127.0.0.1 9072 ping + ntpac true @@ -28,11 +28,19 @@ prompt 4 true + ntpac true ..\bin\ 4 + ntpac + + + false + bin\Develop + 4 + Ntp.Monitor.Cli diff --git a/Ntp.Monitor.Client/Ntp.Monitor.Client.csproj b/Ntp.Monitor.Client/Ntp.Monitor.Client.csproj index 221f20a8..9db063a7 100644 --- a/Ntp.Monitor.Client/Ntp.Monitor.Client.csproj +++ b/Ntp.Monitor.Client/Ntp.Monitor.Client.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.Monitor.Server/Ntp.Monitor.Server.csproj b/Ntp.Monitor.Server/Ntp.Monitor.Server.csproj index e912db45..be85a96c 100644 --- a/Ntp.Monitor.Server/Ntp.Monitor.Server.csproj +++ b/Ntp.Monitor.Server/Ntp.Monitor.Server.csproj @@ -34,6 +34,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.Monitor/Ntp.Monitor.csproj b/Ntp.Monitor/Ntp.Monitor.csproj index a17e9fdd..5dbda843 100644 --- a/Ntp.Monitor/Ntp.Monitor.csproj +++ b/Ntp.Monitor/Ntp.Monitor.csproj @@ -36,6 +36,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + diff --git a/Ntp.Process/Cluster.cs b/Ntp.Process/Cluster.cs index e2cdd8f6..b915628c 100644 --- a/Ntp.Process/Cluster.cs +++ b/Ntp.Process/Cluster.cs @@ -28,7 +28,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using Ntp.Analyzer.Log; -using Ntp.System; +using Ntp.Interop; namespace Ntp.Process { diff --git a/Ntp.Process/Ntp.Process.csproj b/Ntp.Process/Ntp.Process.csproj index cc452360..e6ec8260 100644 --- a/Ntp.Process/Ntp.Process.csproj +++ b/Ntp.Process/Ntp.Process.csproj @@ -33,6 +33,11 @@ ..\bin\ 4 + + false + bin\Develop + 4 + @@ -60,9 +65,9 @@ {43A1A769-6ED9-4AE1-821A-43F97814968C} Ntp.Config - + {A98DB601-2993-4181-A573-5FCCC5E954C1} - Ntp.System + Ntp.Interop \ No newline at end of file diff --git a/example/ntp.conf b/example/ntp.conf deleted file mode 100644 index fe4e8056..00000000 --- a/example/ntp.conf +++ /dev/null @@ -1,9 +0,0 @@ -# Adding timeserver ID's to ntp.conf -# -# http://support.ntp.org/bin/view/Servers/PublicTimeServer000000 -# Take ID from URL and add the ID to end of each line -# -server 127.0.0.1 iburst minpoll 4 maxpoll 7 # 000001 -server 127.0.0.1 iburst minpoll 4 maxpoll 7 # 000002 - -... diff --git a/example/ntpa.graph.conf b/example/ntpa.graph.conf index d9edb5cb..3151ce1f 100644 --- a/example/ntpa.graph.conf +++ b/example/ntpa.graph.conf @@ -40,9 +40,6 @@ Server { # The utility used to query ntpd. Use ntpdc for old hosts. HostType ntpq - - # NTP configuration file from host - ConfigFile /opt/ntpa/config/ntp.conf # Base path for generated files FilePath /usr/local/www/ diff --git a/example/ntpa.web.conf b/example/ntpa.web.conf index a2195abc..2c740eb2 100644 --- a/example/ntpa.web.conf +++ b/example/ntpa.web.conf @@ -13,7 +13,7 @@ Database { # Name of database Name ntpa - # Database username + # Database user name User ntpau # Password for the user @@ -61,9 +61,6 @@ Server { # The utility used to query ntpd. Use ntpdc for old hosts. HostType ntpq - # NTP configuration file from host - ConfigFile /usr/local/etc/ntpa/ntp1.conf - # Base path for generated files FilePath /usr/local/www/ diff --git a/example/ntpa.web.small.conf b/example/ntpa.web.small.conf index 1196a8fc..f0ea8508 100644 --- a/example/ntpa.web.small.conf +++ b/example/ntpa.web.small.conf @@ -34,9 +34,6 @@ Server { # The utility used to query ntpd. Use ntpdc for old hosts. HostType ntpq - # NTP configuration file from host - ConfigFile /usr/local/etc/ntpa/ntp1.conf - # Base path for generated files FilePath /usr/local/www/mypage diff --git a/sql/create_tables.sql b/sql/create_tables.sql index 63280fe5..0bf2921b 100644 --- a/sql/create_tables.sql +++ b/sql/create_tables.sql @@ -26,6 +26,16 @@ CREATE TABLE peer ( orgId INT ) ENGINE=INNODB; +CREATE TABLE peerActivity ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + active BIT(1) NOT NULL, + lastActive TIMESTAMP NOT NULL, + hostId INT NOT NULL, + peerId INT NOT NULL, + FOREIGN KEY (hostId) REFERENCES host(id), + FOREIGN KEY (peerId) REFERENCES peer(id) +) ENGINE=INNODB; + CREATE TABLE peerReading ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, time TIMESTAMP NOT NULL,