Files
ntpa/Ntp.Process/JobDescription.cs
T
2016-04-03 15:58:11 +02:00

115 lines
3.9 KiB
C#

//
// JobDescription.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
//
// 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;
namespace Ntp.Process
{
/// <summary>
/// Base class for jobs following the GoF Command Pattern.
/// </summary>
public abstract class JobDescription
{
/// <summary>
/// Initializes a new instance of the <see cref="Ntp.Process.JobDescription"/> class.
/// </summary>
/// <param name="config">Configuration for the job.</param>
/// <param name="log">Log to use when registrering events.</param>
protected JobDescription (JobConfiguration config, LogBase log)
{
this.config = config;
this.log = log;
}
private readonly JobConfiguration config;
private readonly LogBase log;
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name {
get { return config.ConfigName; }
}
/// <summary>
/// Gets a value indicating whether this <see cref="Ntp.Process.JobDescription"/> should run as a single thread.
/// </summary>
/// <value><c>true</c> if single thread; otherwise, <c>false</c>.</value>
public abstract bool SingleThread { get; }
/// <summary>
/// Gets the type of the job as text.
/// </summary>
/// <value>The type of the job.</value>
public abstract string JobType { get; }
/// <summary>
/// Gets the priority to use when scheduling jobs.
/// </summary>
/// <value>The priority.</value>
public abstract int Priority { get; }
/// <summary>
/// Gets the configuration for the job.
/// </summary>
/// <value>The configuration.</value>
public JobConfiguration Configuration {
get { return config; }
}
/// <summary>
/// Gets the log to use when registrering events.
/// </summary>
/// <value>The log.</value>
protected LogBase Log {
get { return log; }
}
/// <summary>
/// Perform execution of this instance.
/// </summary>
internal void Execute ()
{
InternalExecute ();
}
/// <summary>
/// Implementing method for descendents.
/// </summary>
protected abstract void InternalExecute ();
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="Ntp.Process.JobDescription"/>.
/// </summary>
/// <returns>A <see cref="System.String"/> that represents the current <see cref="Ntp.Process.JobDescription"/>.</returns>
public override string ToString ()
{
return Name;
}
}
}