using System; using System.Collections.Generic; using System.Drawing; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Hive; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.HiveEngine { [StorableClass] public class EngineJob : ItemJob { [Storable] protected IOperation initialOperation; public IOperation InitialOperation { get { return initialOperation; } set { initialOperation = value; } } public new IEngine Item { get { return (IEngine)base.Item; } set { base.Item = value; } } public override TimeSpan ExecutionTime { get { return Item.ExecutionTime; } } public override ExecutionState ExecutionState { get { return Item.ExecutionState; } } #region constructors and cloning public EngineJob() { } public EngineJob(IOperation initialOperation, IEngine engine) { this.initialOperation = initialOperation; this.Item = engine; } [StorableConstructor] protected EngineJob(bool deserializing) : base(deserializing) { } protected EngineJob(EngineJob original, Cloner cloner) : base(original, cloner) { this.initialOperation = cloner.Clone(original.initialOperation); } public override IDeepCloneable Clone(Cloner cloner) { return new EngineJob(this, cloner); } #endregion public override bool IsParallelizable { get { return false; } } public override void Prepare() { } public override void Start() { Item.Prepare(initialOperation); Item.Start(); } public override void Pause() { Item.Pause(); } public override void Stop() { Item.Stop(); } public override void Resume(IEnumerable childJobs) { throw new NotImplementedException(); } protected override void RegisterItemEvents() { Item.Stopped += new EventHandler(engine_Stopped); Item.ExceptionOccurred += new EventHandler>(engine_ExceptionOccurred); } protected override void DeregisterItemEvents() { Item.Stopped -= new EventHandler(engine_Stopped); Item.ExceptionOccurred -= new EventHandler>(engine_ExceptionOccurred); } private void engine_ExceptionOccurred(object sender, EventArgs e) { OnJobFailed(e); } private void engine_Stopped(object sender, EventArgs e) { OnJobStopped(); } public override bool CanChangeDescription { get { return false; } } public override bool CanChangeName { get { return false; } } public override string Description { get { return string.Empty; } set { throw new NotSupportedException(); } } public override string Name { get { return Item.ToString(); } set { throw new NotSupportedException(); } } public override string ItemDescription { get { return Description; } } public override Image ItemImage { get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; } } public override string ItemName { get { return "EngineJob"; } } public override Version ItemVersion { get { return null; } } } }