#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Drawing; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Hive { [Item("Abstract Job", "Represents a executable hive job.")] [StorableClass] public abstract class AbstractJob : DeepCloneable, IJob { public virtual bool IsParallelizable { get { return true; } } [Storable] protected ILog log; public ILog Log { get { return log; } } [Storable] protected bool computeInParallel; public bool ComputeInParallel { get { return computeInParallel; } set { if (computeInParallel != value) { computeInParallel = value; OnComputeInParallelChanged(); } } } [Storable] private bool collectChildJobs; public bool CollectChildJobs { get { return collectChildJobs; } set { collectChildJobs = value; } } public AbstractJob() { this.log = new Log(); } [StorableConstructor] protected AbstractJob(bool deserializing) { } protected AbstractJob(AbstractJob original, Cloner cloner) : base(original, cloner) { this.log = cloner.Clone(original.Log); this.ComputeInParallel = original.ComputeInParallel; this.CollectChildJobs = original.CollectChildJobs; } #region IJob Members public abstract ExecutionState ExecutionState{ get; } public abstract TimeSpan ExecutionTime{ get; } public abstract void Prepare(); public abstract void Start(); public abstract void Pause(); public abstract void Stop(); public abstract void Resume(IEnumerable childJobs); public event EventHandler JobStopped; protected virtual void OnJobStopped() { EventHandler handler = JobStopped; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler JobPaused; protected virtual void OnJobPaused() { EventHandler handler = JobPaused; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler JobFailed; protected virtual void OnJobFailed(EventArgs e) { EventHandler handler = JobFailed; if (handler != null) handler(this, e); } public event EventHandler> NewChildJob; protected virtual void OnNewChildJob(IJob job) { EventHandler> handler = NewChildJob; if (handler != null) handler(this, new EventArgs(job)); } public event EventHandler WaitForChildJobs; protected virtual void OnWaitForChildJobs() { EventHandler handler = WaitForChildJobs; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler DeleteChildJobs; protected virtual void OnDeleteChildJobs() { EventHandler handler = DeleteChildJobs; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler ComputeInParallelChanged; protected virtual void OnComputeInParallelChanged() { EventHandler handler = ComputeInParallelChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler OptimizerChanged; protected virtual void OnOptimizerChanged() { EventHandler handler = OptimizerChanged; if (handler != null) handler(this, EventArgs.Empty); } #endregion #region INamedItem Members public abstract bool CanChangeDescription { get; } public abstract bool CanChangeName { get; } public abstract string Description { get; set; } public abstract string Name { get; set; } #endregion #region Events public event EventHandler DescriptionChanged; protected virtual void OnDescriptionChanged() { var handler = DescriptionChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler ItemImageChanged; protected virtual void OnItemImageChanged() { var handler = ItemImageChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler ToStringChanged; protected virtual void OnToStringChanged() { var handler = ToStringChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler NameChanged; protected virtual void OnNameChanged() { var handler = NameChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler> NameChanging; protected virtual void OnNameChanging(string value, bool cancel) { var handler = NameChanging; if (handler != null) handler(this, new CancelEventArgs(value, cancel)); } public event EventHandler ExecutionTimeChanged; protected virtual void OnExecutionTimeChanged() { EventHandler handler = ExecutionTimeChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler ExecutionStateChanged; protected virtual void OnExecutionStateChanged() { EventHandler handler = ExecutionStateChanged; if (handler != null) handler(this, EventArgs.Empty); } #endregion #region IItem Members public abstract string ItemDescription { get; } public abstract Image ItemImage { get; } public abstract string ItemName { get; } public abstract Version ItemVersion { get; } #endregion public override string ToString() { return Name; } } }