[5958] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Drawing;
|
---|
| 4 | using HeuristicLab.Common;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Hive;
|
---|
| 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 8 |
|
---|
| 9 | namespace HeuristicLab.HiveEngine {
|
---|
| 10 | [StorableClass]
|
---|
| 11 | public class EngineJob : AbstractJob {
|
---|
| 12 | [Storable]
|
---|
| 13 | private IEngine engine;
|
---|
| 14 |
|
---|
| 15 | [Storable]
|
---|
| 16 | protected IOperation initialOperation;
|
---|
| 17 | public IOperation InitialOperation {
|
---|
| 18 | get { return initialOperation; }
|
---|
| 19 | set { initialOperation = value; }
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | public override TimeSpan ExecutionTime {
|
---|
| 23 | get { return engine.ExecutionTime; }
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | public override ExecutionState ExecutionState {
|
---|
| 27 | get { return engine.ExecutionState; }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | #region constructors and cloning
|
---|
| 31 | public EngineJob() { }
|
---|
| 32 | public EngineJob(IOperation initialOperation, IEngine engine) {
|
---|
| 33 | this.initialOperation = initialOperation;
|
---|
| 34 | this.engine = engine;
|
---|
| 35 | RegisterEngineEvents();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | [StorableConstructor]
|
---|
| 39 | protected EngineJob(bool deserializing) : base(deserializing) { }
|
---|
| 40 | protected EngineJob(EngineJob original, Cloner cloner)
|
---|
| 41 | : base(original, cloner) {
|
---|
| 42 | this.engine = cloner.Clone(original.engine);
|
---|
[6000] | 43 | this.initialOperation = cloner.Clone(original.initialOperation);
|
---|
[5958] | 44 | RegisterEngineEvents();
|
---|
| 45 | }
|
---|
| 46 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 47 | return new EngineJob(this, cloner);
|
---|
| 48 | }
|
---|
| 49 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 50 | private void AfterDeserialization() {
|
---|
| 51 | RegisterEngineEvents();
|
---|
| 52 | }
|
---|
| 53 | #endregion
|
---|
| 54 |
|
---|
| 55 | public override bool IsParallelizable {
|
---|
| 56 | get { return false; }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | public override void Prepare() { }
|
---|
| 60 |
|
---|
| 61 | public override void Start() {
|
---|
[6000] | 62 | engine.Prepare(initialOperation);
|
---|
[5958] | 63 | engine.Start();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public override void Pause() {
|
---|
[6000] | 67 | engine.Pause();
|
---|
[5958] | 68 | }
|
---|
| 69 |
|
---|
| 70 | public override void Stop() {
|
---|
| 71 | engine.Stop();
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public override void Resume(IEnumerable<IJob> childJobs) {
|
---|
| 75 | throw new NotImplementedException();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | private void RegisterEngineEvents() {
|
---|
| 79 | engine.Stopped += new EventHandler(engine_Stopped);
|
---|
| 80 | engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[6000] | 83 | private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
[5958] | 84 | OnJobFailed(e);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[6000] | 87 | private void engine_Stopped(object sender, EventArgs e) {
|
---|
[5958] | 88 | OnJobStopped();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public override bool CanChangeDescription {
|
---|
| 92 | get { return false; }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | public override bool CanChangeName {
|
---|
| 96 | get { return false; }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public override string Description {
|
---|
| 100 | get { return string.Empty; }
|
---|
| 101 | set { throw new NotSupportedException(); }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public override string Name {
|
---|
| 105 | get { return engine.ToString(); }
|
---|
| 106 | set { throw new NotSupportedException(); }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | public override string ItemDescription {
|
---|
| 110 | get { return Description; }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public override Image ItemImage {
|
---|
| 114 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | public override string ItemName {
|
---|
| 118 | get { return "EngineJob"; }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | public override Version ItemVersion {
|
---|
| 122 | get { return null; }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|