#region License Information /* HeuristicLab * Copyright (C) 2002-2013 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 HeuristicLab.Clients.Hive; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis.SolutionCaching { [Item("RunCollectionModifierTask", "Represents task which executes a RunCollectionModifierExecutable.")] [StorableClass] public class RunCollectionModifierTask : ItemTask { public new RunCollectionModifierExecutable Item { get { return (RunCollectionModifierExecutable)base.Item; } set { base.Item = value; } } [Storable] private bool isParallelizable; public override bool IsParallelizable { get { return isParallelizable; } set { isParallelizable = value; } } #region Constructors and Cloning public RunCollectionModifierTask(RunCollectionModifierExecutable executable) : base() { Item = executable; isParallelizable = true; } [StorableConstructor] protected RunCollectionModifierTask(bool deserializing) { } protected RunCollectionModifierTask(RunCollectionModifierTask original, Cloner cloner) : base(original, cloner) { isParallelizable = original.isParallelizable; } public override IDeepCloneable Clone(Cloner cloner) { return new RunCollectionModifierTask(this, cloner); } #endregion public override bool CanChangeDescription { get { if (Item == null) return false; else return Item.CanChangeDescription; } } public override bool CanChangeName { get { if (Item == null) return false; else return Item.CanChangeName; } } public override string Description { get { if (Item == null) return string.Empty; else return Item.Description; } set { Item.Description = value; } } public override string Name { get { if (Item == null) return "RunCollectionModifierTask"; else return Item.Name; } set { Item.Name = value; } } public override ExecutionState ExecutionState { get { return Item.ExecutionState; } } public override TimeSpan ExecutionTime { get { return Item.ExecutionTime; } } public override void Pause() { Item.Pause(); } public override void Prepare() { Item.Prepare(); } public override void Start() { Item.Start(); } public override void Stop() { Item.Stop(); } protected override void RegisterItemEvents() { base.RegisterItemEvents(); Item.Stopped += new EventHandler(executable_Stopped); Item.Paused += new EventHandler(executable_Paused); Item.ExceptionOccurred += new EventHandler>(executable_ExceptionOccurred); Item.DescriptionChanged += new EventHandler(executable_DescriptionChanged); Item.NameChanged += new EventHandler(executable_NameChanged); Item.NameChanging += new EventHandler>(executable_NameChanging); Item.ExecutionStateChanged += new EventHandler(executable_ExecutionStateChanged); Item.ExecutionTimeChanged += new EventHandler(executable_ExecutionTimeChanged); Item.Started += new EventHandler(executable_Started); } protected virtual void DeregisterOptimizerEvents() { Item.Stopped -= new EventHandler(executable_Stopped); Item.Paused -= new EventHandler(executable_Paused); Item.ExceptionOccurred -= new EventHandler>(executable_ExceptionOccurred); Item.DescriptionChanged -= new EventHandler(executable_DescriptionChanged); Item.NameChanged -= new EventHandler(executable_NameChanged); Item.NameChanging -= new EventHandler>(executable_NameChanging); Item.ExecutionStateChanged -= new EventHandler(executable_ExecutionStateChanged); Item.ExecutionTimeChanged -= new EventHandler(executable_ExecutionTimeChanged); Item.Started -= new EventHandler(executable_Started); base.DeregisterItemEvents(); } protected void executable_NameChanging(object sender, CancelEventArgs e) { OnNameChanging(new CancelEventArgs(e.Value, e.Cancel)); } protected void executable_NameChanged(object sender, EventArgs e) { this.OnNameChanged(); } protected void executable_DescriptionChanged(object sender, EventArgs e) { OnDescriptionChanged(); } protected virtual void executable_ExceptionOccurred(object sender, EventArgs e) { OnTaskFailed(e); } protected virtual void executable_Started(object sender, EventArgs e) { OnTaskStarted(); } protected virtual void executable_Stopped(object sender, EventArgs e) { OnTaskStopped(); } protected virtual void executable_Paused(object sender, EventArgs e) { OnTaskPaused(); } protected virtual void executable_ExecutionTimeChanged(object sender, EventArgs e) { OnExecutionTimeChanged(); } protected virtual void executable_ExecutionStateChanged(object sender, EventArgs e) { OnExecutionStateChanged(); } } }