1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
8 | using HeuristicLab.Hive.Contracts;
|
---|
9 | using System.Drawing;
|
---|
10 | using HeuristicLab.Common;
|
---|
11 | using System.Diagnostics;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Hive.Experiment {
|
---|
14 | [StorableClass]
|
---|
15 | public class JobItem : Item {
|
---|
16 | private static object locker = new object();
|
---|
17 |
|
---|
18 | public override Image ItemImage {
|
---|
19 | get {
|
---|
20 | if (jobDto.State == State.Offline) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
|
---|
21 | else if (jobDto.State == State.Idle) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
|
---|
22 | else if (jobDto.State == State.Calculating) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStarted;
|
---|
23 | else if (jobDto.State == State.Offline) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
|
---|
24 | else if (jobDto.State == State.Abort) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
|
---|
25 | else return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event;
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | [Storable]
|
---|
30 | private JobDto jobDto;
|
---|
31 | public JobDto JobDto {
|
---|
32 | get { return jobDto; }
|
---|
33 | set {
|
---|
34 | if (jobDto != value) {
|
---|
35 | jobDto = value;
|
---|
36 | OnJobDtoChanged();
|
---|
37 | OnToStringChanged();
|
---|
38 | OnItemImageChanged();
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | [Storable]
|
---|
44 | private ResponseObject<SerializedJob> latestSnapshot;
|
---|
45 | public ResponseObject<SerializedJob> LatestSnapshot {
|
---|
46 | get { return latestSnapshot; }
|
---|
47 | set {
|
---|
48 | if (latestSnapshot != value) {
|
---|
49 | latestSnapshot = value;
|
---|
50 | latestSnapshotTime = DateTime.Now;
|
---|
51 | OnLatestSnapshotChanged();
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | [Storable]
|
---|
57 | private DateTime latestSnapshotTime;
|
---|
58 | public DateTime LatestSnapshotTime {
|
---|
59 | get { return latestSnapshotTime; }
|
---|
60 | }
|
---|
61 |
|
---|
62 | [Storable]
|
---|
63 | private ILog log;
|
---|
64 | public ILog Log {
|
---|
65 | get { return log; }
|
---|
66 | }
|
---|
67 |
|
---|
68 | public JobItem() {
|
---|
69 | log = new Log();
|
---|
70 | }
|
---|
71 |
|
---|
72 | public override string ToString() {
|
---|
73 | if (jobDto != null) {
|
---|
74 | return base.ToString() + " - " + jobDto.Id.ToString();
|
---|
75 | } else {
|
---|
76 | return base.ToString();
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public event EventHandler LatestSnapshotChanged;
|
---|
81 | private void OnLatestSnapshotChanged() {
|
---|
82 | LogMessage("LatestSnapshotChanged");
|
---|
83 | EventHandler handler = LatestSnapshotChanged;
|
---|
84 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
85 | }
|
---|
86 |
|
---|
87 | public event EventHandler JobDtoChanged;
|
---|
88 | private void OnJobDtoChanged() {
|
---|
89 | LogMessage("JobDtoChanged");
|
---|
90 | EventHandler handler = JobDtoChanged;
|
---|
91 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public void LogMessage(string message) {
|
---|
95 | lock (locker) {
|
---|
96 | log.LogMessage(message);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
101 | LogMessage("I am beeing cloned");
|
---|
102 | JobItem clone = (JobItem)base.Clone(cloner);
|
---|
103 | clone.latestSnapshotTime = this.latestSnapshotTime;
|
---|
104 | clone.jobDto = (JobDto)cloner.Clone(this.jobDto);
|
---|
105 | clone.latestSnapshot = (ResponseObject<SerializedJob>)cloner.Clone(this.latestSnapshot);
|
---|
106 | clone.log = (ILog)cloner.Clone(this.log);
|
---|
107 | return clone;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|