mirror of
https://bitbucket.org/anguist/ntpa
synced 2025-10-06 02:51:23 +00:00
Version 0.7.0 prerelease changes
This commit is contained in:
40
Ntp.Analyzer.Monitor.Server/ApplicationState.cs
Normal file
40
Ntp.Analyzer.Monitor.Server/ApplicationState.cs
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Config.Node;
|
||||
using Ntp.Common.Log;
|
||||
using Ntp.Common.Process;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server
|
||||
{
|
||||
public static class ApplicationState
|
||||
{
|
||||
public static DateTime StartupTime;
|
||||
public static string ConfigFile;
|
||||
public static string Version;
|
||||
public static int Pid;
|
||||
public static string Name;
|
||||
public static Configuration Config;
|
||||
public static LogBase Log;
|
||||
public static IScheduler Scheduler;
|
||||
}
|
||||
}
|
26
Ntp.Analyzer.Monitor.Server/AssemblyInfo.cs
Normal file
26
Ntp.Analyzer.Monitor.Server/AssemblyInfo.cs
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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;
|
||||
|
||||
[assembly: AssemblyVersion("0.7.0.0")]
|
||||
[assembly: AssemblyCopyright("Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>")]
|
||||
[assembly: AssemblyCulture("")]
|
218
Ntp.Analyzer.Monitor.Server/Billboard.cs
Normal file
218
Ntp.Analyzer.Monitor.Server/Billboard.cs
Normal file
@ -0,0 +1,218 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Ntp.Common.Process;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server
|
||||
{
|
||||
public static class Billboard
|
||||
{
|
||||
public static string Jobs(IEnumerable<Job> jobs)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("ID".PadRight(3));
|
||||
builder.Append("Act".PadRight(4));
|
||||
builder.Append("Job".PadRight(15));
|
||||
builder.Append("Que".PadLeft(5));
|
||||
builder.Append("Ini".PadLeft(5));
|
||||
builder.Append("Fix".PadLeft(5));
|
||||
builder.Append("Freq".PadLeft(6));
|
||||
builder.Append("Prio".PadLeft(5));
|
||||
builder.Append("Runs".PadLeft(6));
|
||||
builder.Append(" ");
|
||||
builder.Append("Description");
|
||||
builder.AppendLine();
|
||||
|
||||
const int size = 3 + 4 + 15 + 5 + 5 + 5 + 6 + 5 + 6 + 3 + 25;
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
IEnumerable<Job> orderedJobs = jobs.OrderBy(j => j.Description.Priority);
|
||||
|
||||
foreach (Job job in orderedJobs)
|
||||
{
|
||||
builder.Append(job.JobId.ToString("00").PadRight(3));
|
||||
builder.Append(job.Running ? " * " : " ");
|
||||
builder.Append(
|
||||
job.Description.Name.Substring(0,
|
||||
job.Description.Name.Length > 15 ? 15 : job.Description.Name.Length).PadRight(15));
|
||||
builder.Append((job.Queued ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append((job.Schedule.InitialRun ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append((job.Schedule.FixedRun ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append(job.Schedule.Frequency.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(job.Description.Priority.ToString(CultureInfo.InvariantCulture).PadLeft(5));
|
||||
builder.Append(job.RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(" ");
|
||||
builder.Append(job.Description.JobType);
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static string Proc(IEnumerable<Job> jobs)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("ID".PadRight(4));
|
||||
builder.Append("Job".PadRight(16));
|
||||
builder.Append("Ini".PadLeft(5));
|
||||
builder.Append("Fix".PadLeft(5));
|
||||
builder.Append("Freq".PadLeft(7));
|
||||
builder.Append("Prio".PadLeft(6));
|
||||
builder.Append("Runs".PadLeft(5));
|
||||
builder.Append(" ");
|
||||
builder.Append("State".PadRight(12));
|
||||
builder.Append("Time".PadRight(15));
|
||||
builder.AppendLine();
|
||||
|
||||
const int size = 4 + 16 + 5 + 5 + 7 + 6 + 5 + 3 + 12 + 15 + 2;
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
IEnumerable<Job> orderedJobs = jobs.OrderBy(j => j.JobId);
|
||||
|
||||
foreach (Job job in orderedJobs)
|
||||
{
|
||||
builder.Append(job.JobId.ToString("00").PadRight(4));
|
||||
builder.Append(
|
||||
job.Description.Name.Substring(0,
|
||||
job.Description.Name.Length > 15 ? 15 : job.Description.Name.Length).PadRight(15));
|
||||
builder.Append((job.Schedule.InitialRun ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append((job.Schedule.FixedRun ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append(job.Schedule.Frequency.ToString(CultureInfo.InvariantCulture).PadLeft(7));
|
||||
builder.Append(job.Description.Priority.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(job.RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(" ");
|
||||
builder.Append(job.State.PadRight(12));
|
||||
builder.Append(job.TotalRuntime.PadLeft(15).Substring(0, 15));
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static string Running(IEnumerable<Job> jobs)
|
||||
{
|
||||
var list = jobs.ToList();
|
||||
if (list.Count(j => j.Running) == 0)
|
||||
{
|
||||
return "No jobs are currently running.";
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("ID".PadRight(4));
|
||||
builder.Append("Job".PadRight(16));
|
||||
builder.Append("Ini".PadLeft(5));
|
||||
builder.Append("Fix".PadLeft(5));
|
||||
builder.Append("Freq".PadLeft(7));
|
||||
builder.Append("Prio".PadLeft(6));
|
||||
builder.Append("Runs".PadLeft(5));
|
||||
builder.Append(" ");
|
||||
builder.Append("State".PadRight(12));
|
||||
builder.Append("Time".PadRight(15));
|
||||
builder.AppendLine();
|
||||
|
||||
const int size = 4 + 16 + 5 + 5 + 7 + 6 + 5 + 3 + 12 + 15 + 2;
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
IEnumerable<Job> orderedJobs = list.Where(j => j.Running).OrderBy(j => j.JobId);
|
||||
|
||||
foreach (Job job in orderedJobs)
|
||||
{
|
||||
builder.Append(job.JobId.ToString("00").PadRight(4));
|
||||
builder.Append(
|
||||
job.Description.Name.Substring(0,
|
||||
job.Description.Name.Length > 15 ? 15 : job.Description.Name.Length).PadRight(15));
|
||||
builder.Append((job.Schedule.InitialRun ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append((job.Schedule.FixedRun ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append(job.Schedule.Frequency.ToString(CultureInfo.InvariantCulture).PadLeft(7));
|
||||
builder.Append(job.Description.Priority.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(job.RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(" ");
|
||||
builder.Append(job.State.PadRight(12));
|
||||
builder.Append(job.Runtime.PadLeft(15).Substring(0, 15));
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static string Schedule(IEnumerable<ScheduledJob> jobs)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("Server time: " + DateTime.Now.ToLongTimeString());
|
||||
builder.AppendLine();
|
||||
|
||||
builder.Append("ID".PadRight(4));
|
||||
builder.Append("Job".PadRight(15));
|
||||
builder.Append("Ini".PadLeft(4));
|
||||
builder.Append("Fix".PadLeft(5));
|
||||
builder.Append("Freq".PadLeft(6));
|
||||
builder.Append("Prio".PadLeft(5));
|
||||
builder.Append("Runs".PadLeft(6));
|
||||
builder.Append(" ");
|
||||
builder.Append("Next".PadRight(8));
|
||||
builder.AppendLine();
|
||||
|
||||
const int size = 4 + 15 + 4 + 5 + 6 + 5 + 6 + 3 + 8 + 2;
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
IEnumerable<ScheduledJob> orderedJobs = jobs.OrderBy(j => j.Run);
|
||||
|
||||
foreach (ScheduledJob job in orderedJobs)
|
||||
{
|
||||
builder.Append(job.Job.JobId.ToString("00").PadRight(4));
|
||||
builder.Append(
|
||||
job.Job.Description.Name.Substring(0,
|
||||
job.Job.Description.Name.Length > 15 ? 15 : job.Job.Description.Name.Length).PadRight(15));
|
||||
builder.Append((job.Job.Schedule.InitialRun ? " 1" : " 0").PadLeft(4));
|
||||
builder.Append((job.Job.Schedule.FixedRun ? " 1" : " 0").PadLeft(5));
|
||||
builder.Append(job.Job.Schedule.Frequency.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(job.Job.Description.Priority.ToString(CultureInfo.InvariantCulture).PadLeft(5));
|
||||
builder.Append(job.Job.RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
|
||||
builder.Append(" ");
|
||||
builder.Append(job.Run.ToLongTimeString().PadLeft(8));
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(size, '-'));
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
30
Ntp.Analyzer.Monitor.Server/Command.cs
Normal file
30
Ntp.Analyzer.Monitor.Server/Command.cs
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server
|
||||
{
|
||||
internal abstract class Command
|
||||
{
|
||||
public abstract CommandType CommandType { get; }
|
||||
|
||||
public abstract object Execute();
|
||||
}
|
||||
}
|
41
Ntp.Analyzer.Monitor.Server/CommandDescription.cs
Normal file
41
Ntp.Analyzer.Monitor.Server/CommandDescription.cs
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server
|
||||
{
|
||||
internal sealed class CommandDescription<T> : ICommandDescription
|
||||
where T : Command
|
||||
{
|
||||
public CommandDescription(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public string Description { get; }
|
||||
|
||||
public Type Type => typeof(T);
|
||||
}
|
||||
}
|
60
Ntp.Analyzer.Monitor.Server/CommandFactory.cs
Normal file
60
Ntp.Analyzer.Monitor.Server/CommandFactory.cs
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ntp.Analyzer.Monitor.Server.TextCommand;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server
|
||||
{
|
||||
public static class CommandFactory
|
||||
{
|
||||
public static readonly IList<ICommandDescription> Commands = new List<ICommandDescription>
|
||||
{
|
||||
new CommandDescription<ConfigFileCommand>("config", "Shows name and path of current configuration."),
|
||||
new CommandDescription<HelpCommand>("help", "Shows valid commands."),
|
||||
new CommandDescription<JobsCommand>("jobs", "Shows a list of jobs in scheduler."),
|
||||
new CommandDescription<NextJobCommand>("next", "Shows when next scheduled job will be actived."),
|
||||
new CommandDescription<PidCommand>("pid", "Shows process id of NTPA daemon."),
|
||||
new CommandDescription<PingCommand>("ping", "Responds if daemon is running."),
|
||||
new CommandDescription<ProgCommand>("prog", "Shows active configuration."),
|
||||
new CommandDescription<ScheduleCommand>("schedule", "Shows schedule for active jobs."),
|
||||
new CommandDescription<ServerCommand>("pages", "Shows number of configured pages on NTPA daemon."),
|
||||
new CommandDescription<TimeCommand>("time", "Shows current server time in UTC."),
|
||||
new CommandDescription<UptimeCommand>("uptime", "Shows uptime of NTPA daemon."),
|
||||
new CommandDescription<VersionCommand>("version", "Shows name and version."),
|
||||
new CommandDescription<RunningCommand>("running", "Shows a list of running jobs."),
|
||||
new CommandDescription<ProcCommand>("proc", "Shows a list of jobs and execution time."),
|
||||
new CommandDescription<ActivityCommand>("activity", "Shows recent activity in scheduler.")
|
||||
};
|
||||
|
||||
internal static Command Create(string command, string[] args)
|
||||
{
|
||||
var commandDescription = Commands.SingleOrDefault(c => c.Name == command);
|
||||
|
||||
if (commandDescription == null)
|
||||
return new HelpCommand(true);
|
||||
|
||||
return Activator.CreateInstance(commandDescription.Type, new object[] {args}) as Command;
|
||||
}
|
||||
}
|
||||
}
|
29
Ntp.Analyzer.Monitor.Server/CommandType.cs
Normal file
29
Ntp.Analyzer.Monitor.Server/CommandType.cs
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server
|
||||
{
|
||||
public enum CommandType
|
||||
{
|
||||
Text,
|
||||
Binary
|
||||
}
|
||||
}
|
32
Ntp.Analyzer.Monitor.Server/ICommandDescription.cs
Normal file
32
Ntp.Analyzer.Monitor.Server/ICommandDescription.cs
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server
|
||||
{
|
||||
public interface ICommandDescription
|
||||
{
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
Type Type { get; }
|
||||
}
|
||||
}
|
242
Ntp.Analyzer.Monitor.Server/Listener.cs
Normal file
242
Ntp.Analyzer.Monitor.Server/Listener.cs
Normal file
@ -0,0 +1,242 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Globalization;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Ntp.Common.Log;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server
|
||||
{
|
||||
public sealed class Listener : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Listener" /> class.
|
||||
/// </summary>
|
||||
/// <param name="ip">IP Address to listen on.</param>
|
||||
/// <param name="port">Port number.</param>
|
||||
/// <param name="log">Log.</param>
|
||||
public Listener(string ip, int port, LogBase log)
|
||||
{
|
||||
IPAddress address = IPAddress.Parse(ip);
|
||||
endPoint = new IPEndPoint(address, port);
|
||||
this.log = log;
|
||||
shuttingDown = false;
|
||||
}
|
||||
|
||||
private readonly IPEndPoint endPoint;
|
||||
private readonly LogBase log;
|
||||
private Socket listenSocket;
|
||||
private bool shuttingDown;
|
||||
|
||||
/// <summary>
|
||||
/// Close this listener.
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
shuttingDown = true;
|
||||
listenSocket.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open this listener.
|
||||
/// </summary>
|
||||
public void Open()
|
||||
{
|
||||
try
|
||||
{
|
||||
listenSocket = new Socket(
|
||||
AddressFamily.InterNetwork,
|
||||
SocketType.Stream,
|
||||
ProtocolType.Tcp);
|
||||
|
||||
listenSocket.Bind(endPoint);
|
||||
listenSocket.Listen(3);
|
||||
|
||||
listenSocket.BeginAccept(AcceptCallback, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.WriteLine("Error while initializing listener " + ToString(), Severity.Error);
|
||||
log.WriteLine(ex.Message, Severity.Debug);
|
||||
log.WriteLine(ex, Severity.Trace);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return endPoint.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Accepts the callback from client.
|
||||
/// </summary>
|
||||
/// <param name="asyncAccept">Async accept.</param>
|
||||
private void AcceptCallback(IAsyncResult asyncAccept)
|
||||
{
|
||||
try
|
||||
{
|
||||
Socket serverSocket = listenSocket.EndAccept(asyncAccept);
|
||||
|
||||
if (serverSocket.Connected == false)
|
||||
return;
|
||||
|
||||
var req = new Request(128, serverSocket);
|
||||
|
||||
serverSocket.BeginReceive(
|
||||
req.Buffer,
|
||||
0,
|
||||
req.Buffer.Length,
|
||||
SocketFlags.None,
|
||||
ReceiveCallback,
|
||||
req);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!shuttingDown)
|
||||
{
|
||||
log.WriteLine("Unexpected error in listener " + ToString(), Severity.Error);
|
||||
log.WriteLine(ex.Message, Severity.Debug);
|
||||
log.WriteLine(ex, Severity.Trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Receives the callback from client.
|
||||
/// </summary>
|
||||
/// <param name="asyncReceive">Async receive.</param>
|
||||
private void ReceiveCallback(IAsyncResult asyncReceive)
|
||||
{
|
||||
try
|
||||
{
|
||||
var req = (Request) asyncReceive.AsyncState;
|
||||
int size = req.Socket.EndReceive(asyncReceive);
|
||||
req.ReSize(size);
|
||||
|
||||
// Process request
|
||||
Command command = CommandFactory.Create(req.Command, req.Arguments);
|
||||
|
||||
// Force correct time format in strings, etc.
|
||||
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
||||
|
||||
byte[] sendBuffer;
|
||||
|
||||
if (command == null)
|
||||
{
|
||||
sendBuffer = Encoding.ASCII.GetBytes("Unknown command");
|
||||
}
|
||||
else
|
||||
switch (command.CommandType)
|
||||
{
|
||||
case CommandType.Binary:
|
||||
sendBuffer = (byte[]) command.Execute();
|
||||
break;
|
||||
case CommandType.Text:
|
||||
var text = command.Execute() as string;
|
||||
sendBuffer = text != null ? Encoding.ASCII.GetBytes(text) : new byte[] {0};
|
||||
break;
|
||||
default:
|
||||
sendBuffer = Encoding.ASCII.GetBytes("Error in command module. Unknown command type.");
|
||||
break;
|
||||
}
|
||||
|
||||
req.Socket.BeginSend(
|
||||
sendBuffer,
|
||||
0,
|
||||
sendBuffer.Length,
|
||||
SocketFlags.None,
|
||||
SendCallback,
|
||||
req.Socket);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.WriteLine("Unexpected error in listener " + ToString(), Severity.Error);
|
||||
log.WriteLine(ex.Message, Severity.Debug);
|
||||
log.WriteLine(ex, Severity.Trace);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the callback response to client.
|
||||
/// </summary>
|
||||
/// <param name="asyncSend">Async send.</param>
|
||||
private void SendCallback(IAsyncResult asyncSend)
|
||||
{
|
||||
try
|
||||
{
|
||||
var serverSocket = (Socket) asyncSend.AsyncState;
|
||||
serverSocket.EndSend(asyncSend);
|
||||
serverSocket.Shutdown(SocketShutdown.Both);
|
||||
serverSocket.Close();
|
||||
|
||||
// Start new worker socket.
|
||||
listenSocket.BeginAccept(AcceptCallback, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.WriteLine("Unexpected error in listener " + ToString(), Severity.Error);
|
||||
log.WriteLine(ex.Message, Severity.Debug);
|
||||
log.WriteLine(ex, Severity.Trace);
|
||||
}
|
||||
}
|
||||
|
||||
#region IDisposable Support
|
||||
|
||||
private bool disposedValue;
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposedValue)
|
||||
return;
|
||||
|
||||
if (disposing && listenSocket != null)
|
||||
{
|
||||
if (listenSocket.Connected)
|
||||
{
|
||||
listenSocket.Shutdown(SocketShutdown.Both);
|
||||
listenSocket.Close();
|
||||
}
|
||||
|
||||
listenSocket.Dispose();
|
||||
listenSocket = null;
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
|
||||
~Listener()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{13FA10AB-D656-4D72-BC69-2525D484C9DE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Ntp.Analyzer.Monitor.Server</RootNamespace>
|
||||
<AssemblyName>Ntp.Analyzer.Monitor.Server</AssemblyName>
|
||||
<ReleaseVersion>0.7.0</ReleaseVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin</OutputPath>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Billboard.cs" />
|
||||
<Compile Include="Listener.cs" />
|
||||
<Compile Include="Request.cs" />
|
||||
<Compile Include="ApplicationState.cs" />
|
||||
<Compile Include="CommandType.cs" />
|
||||
<Compile Include="CommandFactory.cs" />
|
||||
<Compile Include="CommandDescription.cs" />
|
||||
<Compile Include="ICommandDescription.cs" />
|
||||
<Compile Include="TextCommand\PidCommand.cs" />
|
||||
<Compile Include="TextCommand\PingCommand.cs" />
|
||||
<Compile Include="TextCommand\VersionCommand.cs" />
|
||||
<Compile Include="TextCommand\ConfigFileCommand.cs" />
|
||||
<Compile Include="TextCommand\HelpCommand.cs" />
|
||||
<Compile Include="TextCommand\JobsCommand.cs" />
|
||||
<Compile Include="TextCommand\ScheduleCommand.cs" />
|
||||
<Compile Include="TextCommand\TimeCommand.cs" />
|
||||
<Compile Include="TextCommand\NextJobCommand.cs" />
|
||||
<Compile Include="TextCommand\ServerCommand.cs" />
|
||||
<Compile Include="TextCommand\ProgCommand.cs" />
|
||||
<Compile Include="TextCommand\MonitorTextCommand.cs" />
|
||||
<Compile Include="TextCommand\UptimeCommand.cs" />
|
||||
<Compile Include="Command.cs" />
|
||||
<Compile Include="PacketCommand\PacketCommand.cs" />
|
||||
<Compile Include="TextCommand\RunningCommand.cs" />
|
||||
<Compile Include="TextCommand\ProcCommand.cs" />
|
||||
<Compile Include="TextCommand\ActivityCommand.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ntp.Analyzer\Ntp.Analyzer.csproj">
|
||||
<Project>{28444C86-1B41-4558-BA27-DCF32B2B1E0F}</Project>
|
||||
<Name>Ntp.Analyzer</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ntp.Analyzer.Objects\Ntp.Analyzer.Objects.csproj">
|
||||
<Project>{02912378-E62D-4445-BA30-F56D3ABE9DA2}</Project>
|
||||
<Name>Ntp.Analyzer.Objects</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ntp.Common\Ntp.Common.csproj">
|
||||
<Project>{86848F80-2692-47AB-A68A-BFB2990B632E}</Project>
|
||||
<Name>Ntp.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ntp.Analyzer.Data\Ntp.Analyzer.Data.csproj">
|
||||
<Project>{8263BEAB-1610-4F82-9FC0-84421E5AB6B0}</Project>
|
||||
<Name>Ntp.Analyzer.Data</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
35
Ntp.Analyzer.Monitor.Server/PacketCommand/PacketCommand.cs
Normal file
35
Ntp.Analyzer.Monitor.Server/PacketCommand/PacketCommand.cs
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.PacketCommand
|
||||
{
|
||||
internal abstract class MonitorPacketCommand : Command
|
||||
{
|
||||
public override CommandType CommandType => CommandType.Binary;
|
||||
|
||||
public override object Execute()
|
||||
{
|
||||
return ExecuteBinary();
|
||||
}
|
||||
|
||||
protected abstract byte[] ExecuteBinary();
|
||||
}
|
||||
}
|
67
Ntp.Analyzer.Monitor.Server/Request.cs
Normal file
67
Ntp.Analyzer.Monitor.Server/Request.cs
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server
|
||||
{
|
||||
internal class Request
|
||||
{
|
||||
internal Request(int size, Socket sock)
|
||||
{
|
||||
Buffer = new byte[size];
|
||||
Socket = sock;
|
||||
}
|
||||
|
||||
internal byte[] Buffer;
|
||||
internal Socket Socket;
|
||||
|
||||
private string Content => Encoding.ASCII.GetString(Buffer);
|
||||
|
||||
internal string Command => Content != null ? Content.Split(' ')[0] : string.Empty;
|
||||
|
||||
internal string[] Arguments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Content == null)
|
||||
return new string[0];
|
||||
|
||||
var args = new List<string>(Content.Split(' '));
|
||||
args.RemoveAt(0);
|
||||
|
||||
return args.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
internal void ReSize(int size)
|
||||
{
|
||||
var newBuffer = new byte[size];
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
newBuffer[i] = Buffer[i];
|
||||
|
||||
Buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
}
|
57
Ntp.Analyzer.Monitor.Server/TextCommand/ActivityCommand.cs
Normal file
57
Ntp.Analyzer.Monitor.Server/TextCommand/ActivityCommand.cs
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server.TextCommand
|
||||
{
|
||||
internal class ActivityCommand : MonitorTextCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ActivityCommand" /> class.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments.</param>
|
||||
public ActivityCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
private const int LineCount = 200;
|
||||
|
||||
/// <summary>
|
||||
/// List recent activity.
|
||||
/// </summary>
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendFormat("Listing {0} lines ...", LineCount);
|
||||
|
||||
foreach (string entry in ApplicationState.Scheduler.ActivityLog.Reverse().Take(LineCount).Reverse())
|
||||
{
|
||||
builder.AppendLine(entry);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
36
Ntp.Analyzer.Monitor.Server/TextCommand/ConfigFileCommand.cs
Normal file
36
Ntp.Analyzer.Monitor.Server/TextCommand/ConfigFileCommand.cs
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class ConfigFileCommand : MonitorTextCommand
|
||||
{
|
||||
public ConfigFileCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return $"Configuration: {ApplicationState.ConfigFile}";
|
||||
}
|
||||
}
|
||||
}
|
70
Ntp.Analyzer.Monitor.Server/TextCommand/HelpCommand.cs
Normal file
70
Ntp.Analyzer.Monitor.Server/TextCommand/HelpCommand.cs
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class HelpCommand : MonitorTextCommand
|
||||
{
|
||||
public HelpCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
public HelpCommand(bool error)
|
||||
: base(new string[0])
|
||||
{
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
private readonly bool error;
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
if (error)
|
||||
{
|
||||
builder.AppendLine("Unknown command.");
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
var version = new VersionCommand(new string[0]);
|
||||
builder.Append(version.Execute());
|
||||
builder.AppendLine(". the following commands are valid.");
|
||||
|
||||
int length = CommandFactory.Commands.Max(c => c.Description.Length);
|
||||
length += 15 + 3;
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(length, '-'));
|
||||
|
||||
foreach (ICommandDescription command in CommandFactory.Commands.OrderBy(c => c.Name))
|
||||
{
|
||||
builder.Append(command.Name.PadRight(15));
|
||||
builder.AppendLine(command.Description);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
46
Ntp.Analyzer.Monitor.Server/TextCommand/JobsCommand.cs
Normal file
46
Ntp.Analyzer.Monitor.Server/TextCommand/JobsCommand.cs
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Jobs command list active jobs.
|
||||
/// </summary>
|
||||
internal sealed class JobsCommand : MonitorTextCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JobsCommand" /> class.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments.</param>
|
||||
public JobsCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List active jobs
|
||||
/// </summary>
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return Billboard.Jobs(ApplicationState.Scheduler);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal abstract class MonitorTextCommand : Command
|
||||
{
|
||||
protected MonitorTextCommand(string[] args)
|
||||
{
|
||||
Args = args;
|
||||
}
|
||||
|
||||
protected MonitorTextCommand()
|
||||
{
|
||||
Args = new string[0];
|
||||
}
|
||||
|
||||
protected string[] Args { get; }
|
||||
|
||||
public override CommandType CommandType => CommandType.Text;
|
||||
|
||||
public override object Execute()
|
||||
{
|
||||
return ExecuteTextCommand();
|
||||
}
|
||||
|
||||
protected abstract string ExecuteTextCommand();
|
||||
}
|
||||
}
|
51
Ntp.Analyzer.Monitor.Server/TextCommand/NextJobCommand.cs
Normal file
51
Ntp.Analyzer.Monitor.Server/TextCommand/NextJobCommand.cs
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Globalization;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class NextJobCommand : MonitorTextCommand
|
||||
{
|
||||
public NextJobCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
string jobText = "A job is currently active.";
|
||||
|
||||
if (ApplicationState.Scheduler.NextJob != null)
|
||||
{
|
||||
jobText =
|
||||
"Next run is " +
|
||||
ApplicationState.Scheduler.NextJob.Job.Description.Name +
|
||||
" (Job ID " +
|
||||
ApplicationState.Scheduler.NextJob.Job.JobId.ToString(CultureInfo.InvariantCulture) +
|
||||
") scheduled to " +
|
||||
ApplicationState.Scheduler.NextJob.Run.ToLongTimeString();
|
||||
}
|
||||
|
||||
return jobText;
|
||||
}
|
||||
}
|
||||
}
|
36
Ntp.Analyzer.Monitor.Server/TextCommand/PidCommand.cs
Normal file
36
Ntp.Analyzer.Monitor.Server/TextCommand/PidCommand.cs
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class PidCommand : MonitorTextCommand
|
||||
{
|
||||
public PidCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return $"Process ID: {ApplicationState.Pid}";
|
||||
}
|
||||
}
|
||||
}
|
36
Ntp.Analyzer.Monitor.Server/TextCommand/PingCommand.cs
Normal file
36
Ntp.Analyzer.Monitor.Server/TextCommand/PingCommand.cs
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class PingCommand : MonitorTextCommand
|
||||
{
|
||||
public PingCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return ApplicationState.Scheduler.Active ? "active" : "*";
|
||||
}
|
||||
}
|
||||
}
|
43
Ntp.Analyzer.Monitor.Server/TextCommand/ProcCommand.cs
Normal file
43
Ntp.Analyzer.Monitor.Server/TextCommand/ProcCommand.cs
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class ProcCommand : MonitorTextCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProcCommand" /> class.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments.</param>
|
||||
public ProcCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List all jobs.
|
||||
/// </summary>
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return Billboard.Proc(ApplicationState.Scheduler);
|
||||
}
|
||||
}
|
||||
}
|
36
Ntp.Analyzer.Monitor.Server/TextCommand/ProgCommand.cs
Normal file
36
Ntp.Analyzer.Monitor.Server/TextCommand/ProgCommand.cs
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class ProgCommand : MonitorTextCommand
|
||||
{
|
||||
public ProgCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return ApplicationState.Config.ToString();
|
||||
}
|
||||
}
|
||||
}
|
43
Ntp.Analyzer.Monitor.Server/TextCommand/RunningCommand.cs
Normal file
43
Ntp.Analyzer.Monitor.Server/TextCommand/RunningCommand.cs
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class RunningCommand : MonitorTextCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RunningCommand" /> class.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments.</param>
|
||||
public RunningCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List running jobs.
|
||||
/// </summary>
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return Billboard.Running(ApplicationState.Scheduler);
|
||||
}
|
||||
}
|
||||
}
|
46
Ntp.Analyzer.Monitor.Server/TextCommand/ScheduleCommand.cs
Normal file
46
Ntp.Analyzer.Monitor.Server/TextCommand/ScheduleCommand.cs
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Schedule command list active scheduled jobs.
|
||||
/// </summary>
|
||||
internal sealed class ScheduleCommand : MonitorTextCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScheduleCommand" /> class.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments.</param>
|
||||
public ScheduleCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List scheduled jobs.
|
||||
/// </summary>
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return Billboard.Schedule(ApplicationState.Scheduler.Schedule);
|
||||
}
|
||||
}
|
||||
}
|
70
Ntp.Analyzer.Monitor.Server/TextCommand/ServerCommand.cs
Normal file
70
Ntp.Analyzer.Monitor.Server/TextCommand/ServerCommand.cs
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Ntp.Analyzer.Config.Node;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class ServerCommand : MonitorTextCommand
|
||||
{
|
||||
public ServerCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("Host".PadRight(18));
|
||||
builder.Append("#HP".PadLeft(4));
|
||||
builder.Append("#HG".PadLeft(4));
|
||||
builder.Append("#GP".PadLeft(4));
|
||||
builder.Append("#PP".PadLeft(4));
|
||||
builder.Append("#PG".PadLeft(4));
|
||||
builder.Append("#GP".PadLeft(4));
|
||||
builder.Append("#PS".PadLeft(4));
|
||||
builder.Append("#AB".PadLeft(4));
|
||||
builder.AppendLine();
|
||||
|
||||
builder.AppendLine(string.Empty.PadLeft(18 + 8*4 + 2, '-'));
|
||||
|
||||
foreach (HostConfiguration server in ApplicationState.Config.Servers)
|
||||
{
|
||||
builder.Append(server.ServerName.PadRight(18));
|
||||
builder.Append(server.HostPages.Count().ToString(CultureInfo.InvariantCulture).PadLeft(4));
|
||||
builder.Append(server.HostGraphs.Count().ToString(CultureInfo.InvariantCulture).PadLeft(4));
|
||||
builder.Append((server.HostGraphPage == null ? "0" : "1").PadLeft(4));
|
||||
builder.Append(server.PeerPages.Count().ToString(CultureInfo.InvariantCulture).PadLeft(4));
|
||||
builder.Append(server.PeerGraphs.Count().ToString(CultureInfo.InvariantCulture).PadLeft(4));
|
||||
builder.Append((server.PeerGraphPage == null ? "0" : "1").PadLeft(4));
|
||||
builder.Append(server.PeerSummaryPages.Count().ToString(CultureInfo.InvariantCulture).PadLeft(4));
|
||||
builder.Append((server.AboutPage == null ? "0" : "1").PadLeft(4));
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
44
Ntp.Analyzer.Monitor.Server/TextCommand/TimeCommand.cs
Normal file
44
Ntp.Analyzer.Monitor.Server/TextCommand/TimeCommand.cs
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class TimeCommand : MonitorTextCommand
|
||||
{
|
||||
public TimeCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
DateTime now = DateTime.Now.ToUniversalTime();
|
||||
|
||||
return
|
||||
"Server time is " +
|
||||
now.ToLongDateString() +
|
||||
" UTC " +
|
||||
now.ToLongTimeString();
|
||||
}
|
||||
}
|
||||
}
|
121
Ntp.Analyzer.Monitor.Server/TextCommand/UptimeCommand.cs
Normal file
121
Ntp.Analyzer.Monitor.Server/TextCommand/UptimeCommand.cs
Normal file
@ -0,0 +1,121 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Ntp.Analyzer.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class UptimeCommand : MonitorTextCommand
|
||||
{
|
||||
public UptimeCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
TimeSpan runtime = DateTime.Now.Subtract(ApplicationState.StartupTime);
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("Daemon was started ");
|
||||
builder.Append(ApplicationState.StartupTime.ToShortDateString());
|
||||
builder.Append(" ");
|
||||
builder.Append(TimeZone.CurrentTimeZone.StandardName);
|
||||
builder.Append(" ");
|
||||
builder.Append(ApplicationState.StartupTime.ToLongTimeString());
|
||||
builder.AppendLine();
|
||||
|
||||
builder.Append("Uptime ");
|
||||
builder.Append(FormatTimespan(runtime));
|
||||
builder.AppendLine();
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private string FormatTimespan(TimeSpan time)
|
||||
{
|
||||
string days;
|
||||
|
||||
if (time.TotalDays >= 1 && time.TotalDays < 2)
|
||||
{
|
||||
days = "1 day ";
|
||||
}
|
||||
else if (time.TotalDays >= 2)
|
||||
{
|
||||
days = time.TotalDays.ToString(CultureInfo.InvariantCulture) + " days ";
|
||||
}
|
||||
else
|
||||
{
|
||||
days = string.Empty;
|
||||
}
|
||||
|
||||
string hours;
|
||||
|
||||
if (time.Hours >= 1 && time.Hours < 2)
|
||||
{
|
||||
hours = "1 hour ";
|
||||
}
|
||||
else if (time.Hours >= 2)
|
||||
{
|
||||
hours = time.Hours.ToString(CultureInfo.InvariantCulture) + " hours ";
|
||||
}
|
||||
else
|
||||
{
|
||||
hours = string.Empty;
|
||||
}
|
||||
|
||||
string minutes;
|
||||
|
||||
if (time.Minutes >= 1 && time.Minutes < 2)
|
||||
{
|
||||
minutes = "1 minute ";
|
||||
}
|
||||
else if (time.Minutes >= 2)
|
||||
{
|
||||
minutes = time.Minutes.ToString(CultureInfo.InvariantCulture) + " minutes ";
|
||||
}
|
||||
else
|
||||
{
|
||||
minutes = string.Empty;
|
||||
}
|
||||
|
||||
string seconds;
|
||||
|
||||
if (time.Seconds >= 1 && time.Seconds < 2)
|
||||
{
|
||||
seconds = "1 second";
|
||||
}
|
||||
else if (time.Seconds >= 2)
|
||||
{
|
||||
seconds = time.Seconds.ToString(CultureInfo.InvariantCulture) + " seconds";
|
||||
}
|
||||
else
|
||||
{
|
||||
seconds = string.Empty;
|
||||
}
|
||||
|
||||
return string.Concat(days, hours, minutes, seconds);
|
||||
}
|
||||
}
|
||||
}
|
36
Ntp.Analyzer.Monitor.Server/TextCommand/VersionCommand.cs
Normal file
36
Ntp.Analyzer.Monitor.Server/TextCommand/VersionCommand.cs
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// 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.Monitor.Server.TextCommand
|
||||
{
|
||||
internal sealed class VersionCommand : MonitorTextCommand
|
||||
{
|
||||
public VersionCommand(string[] args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExecuteTextCommand()
|
||||
{
|
||||
return $"NTP Analyzer version {ApplicationState.Version}";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user