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 : ItemJob {
|
---|
12 | [Storable]
|
---|
13 | protected IOperation initialOperation;
|
---|
14 | public IOperation InitialOperation {
|
---|
15 | get { return initialOperation; }
|
---|
16 | set { initialOperation = value; }
|
---|
17 | }
|
---|
18 |
|
---|
19 | public new IEngine Item {
|
---|
20 | get { return (IEngine)base.Item; }
|
---|
21 | set { base.Item = value; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | public override TimeSpan ExecutionTime {
|
---|
25 | get { return Item.ExecutionTime; }
|
---|
26 | }
|
---|
27 |
|
---|
28 | public override ExecutionState ExecutionState {
|
---|
29 | get { return Item.ExecutionState; }
|
---|
30 | }
|
---|
31 |
|
---|
32 | #region constructors and cloning
|
---|
33 | public EngineJob() { }
|
---|
34 | public EngineJob(IOperation initialOperation, IEngine engine) {
|
---|
35 | this.initialOperation = initialOperation;
|
---|
36 | this.Item = engine;
|
---|
37 | }
|
---|
38 |
|
---|
39 | [StorableConstructor]
|
---|
40 | protected EngineJob(bool deserializing) : base(deserializing) { }
|
---|
41 | protected EngineJob(EngineJob original, Cloner cloner)
|
---|
42 | : base(original, cloner) {
|
---|
43 | this.initialOperation = cloner.Clone(original.initialOperation);
|
---|
44 | }
|
---|
45 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
46 | return new EngineJob(this, cloner);
|
---|
47 | }
|
---|
48 | #endregion
|
---|
49 |
|
---|
50 | public override bool IsParallelizable {
|
---|
51 | get { return false; }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public override void Prepare() { }
|
---|
55 |
|
---|
56 | public override void Start() {
|
---|
57 | Item.Prepare(initialOperation);
|
---|
58 | Item.Start();
|
---|
59 | }
|
---|
60 |
|
---|
61 | public override void Pause() {
|
---|
62 | Item.Pause();
|
---|
63 | }
|
---|
64 |
|
---|
65 | public override void Stop() {
|
---|
66 | Item.Stop();
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override void Resume(IEnumerable<IJob> childJobs) {
|
---|
70 | throw new NotImplementedException();
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected override void RegisterItemEvents() {
|
---|
74 | Item.Stopped += new EventHandler(engine_Stopped);
|
---|
75 | Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected override void DeregisterItemEvents() {
|
---|
79 | Item.Stopped -= new EventHandler(engine_Stopped);
|
---|
80 | Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
84 | OnJobFailed(e);
|
---|
85 | }
|
---|
86 |
|
---|
87 | private void engine_Stopped(object sender, EventArgs e) {
|
---|
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 Item.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 | }
|
---|