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 | this.engine.Prepare(initialOperation);
|
---|
36 | RegisterEngineEvents();
|
---|
37 | }
|
---|
38 |
|
---|
39 | [StorableConstructor]
|
---|
40 | protected EngineJob(bool deserializing) : base(deserializing) { }
|
---|
41 | protected EngineJob(EngineJob original, Cloner cloner)
|
---|
42 | : base(original, cloner) {
|
---|
43 | this.engine = cloner.Clone(original.engine);
|
---|
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() {
|
---|
62 | engine.Start();
|
---|
63 | }
|
---|
64 |
|
---|
65 | public override void Pause() {
|
---|
66 | throw new NotImplementedException();
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override void Stop() {
|
---|
70 | engine.Stop();
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override void Resume(IEnumerable<IJob> childJobs) {
|
---|
74 | throw new NotImplementedException();
|
---|
75 | }
|
---|
76 |
|
---|
77 | private void RegisterEngineEvents() {
|
---|
78 | engine.Stopped += new EventHandler(engine_Stopped);
|
---|
79 | engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
|
---|
80 | }
|
---|
81 |
|
---|
82 | void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
83 | OnJobFailed(e);
|
---|
84 | }
|
---|
85 |
|
---|
86 | void engine_Stopped(object sender, EventArgs e) {
|
---|
87 | OnJobStopped();
|
---|
88 | }
|
---|
89 |
|
---|
90 | public override bool CanChangeDescription {
|
---|
91 | get { return false; }
|
---|
92 | }
|
---|
93 |
|
---|
94 | public override bool CanChangeName {
|
---|
95 | get { return false; }
|
---|
96 | }
|
---|
97 |
|
---|
98 | public override string Description {
|
---|
99 | get { return string.Empty; }
|
---|
100 | set { throw new NotSupportedException(); }
|
---|
101 | }
|
---|
102 |
|
---|
103 | public override string Name {
|
---|
104 | get { return engine.ToString(); }
|
---|
105 | set { throw new NotSupportedException(); }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public override string ItemDescription {
|
---|
109 | get { return Description; }
|
---|
110 | }
|
---|
111 |
|
---|
112 | public override Image ItemImage {
|
---|
113 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
|
---|
114 | }
|
---|
115 |
|
---|
116 | public override string ItemName {
|
---|
117 | get { return "EngineJob"; }
|
---|
118 | }
|
---|
119 |
|
---|
120 | public override Version ItemVersion {
|
---|
121 | get { return null; }
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|