Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveClient.cs @ 4368

Last change on this file since 4368 was 4368, checked in by cneumuel, 14 years ago
  • created HiveClient which shows an overview over all submitted HiveExperiments
  • its possible to download all submitted HiveExperiments including results
  • Experiments are now sent as a whole to the Hive and the Hive-Slaves take care of creating child-jobs (if necessary). The parent job is then paused and will be reactivated when all child-jobs are finished
  • WcfService-Clients are now consistently managed by WcfServicePool which allows to use IDisposable-Pattern and always keeps exactly one proxy-object until all callers disposed them.
  • created ProgressView which is able to lock a View and display progress of an action. It also allows to simulate progress if no progress-information is available so that users don't get too nervous while waiting.
File size: 5.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HeuristicLab.Hive.Contracts.Interfaces;
8using HeuristicLab.Hive.Contracts.ResponseObjects;
9using HeuristicLab.Hive.Contracts.BusinessObjects;
10using HeuristicLab.Hive.Experiment.Properties;
11using System.ServiceModel;
12using HeuristicLab.Hive.Contracts;
13
14namespace HeuristicLab.Hive.Experiment {
15  [Item("Hive Client", "Connects to Hive and lists all submitted experiments by the current user.")]
16  [Creatable("Hive")]
17  public class HiveClient : Item {
18    private static object locker = new object();
19
20    private ILog log;
21    public ILog Log {
22      get { return log; }
23    }
24
25    private HiveExperimentList hiveExperiments;
26    public HiveExperimentList HiveExperiments {
27      get { return hiveExperiments; }
28      set {
29        if (hiveExperiments != value) {
30          if (hiveExperiments != null) {
31            DeRegisterHiveExperimentsEvents();
32          }
33          hiveExperiments = value;
34          RegisterHiveExperimentsEvent();
35          OnHiveExperimentsChanged();
36        }
37      }
38    }
39
40    private void RegisterHiveExperimentsEvent() {
41      hiveExperiments.ItemsAdded += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<HiveExperiment>>(hiveExperiments_ItemsAdded);
42      hiveExperiments.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
43      hiveExperiments.ItemsMoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<HiveExperiment>>(hiveExperiments_ItemsMoved);
44    }
45
46    private void DeRegisterHiveExperimentsEvents() {
47      hiveExperiments.ItemsAdded -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<HiveExperiment>>(hiveExperiments_ItemsAdded);
48      hiveExperiments.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
49      hiveExperiments.ItemsMoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<HiveExperiment>>(hiveExperiments_ItemsMoved);
50
51    }
52
53    public HiveClient() {
54      this.log = new Log();
55      this.HiveExperiments = new HiveExperimentList();
56    }
57
58
59    public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
60      HiveClient clone = (HiveClient)base.Clone(cloner);
61      clone.log = (ILog)cloner.Clone(this.log);
62      clone.hiveExperiments = (HiveExperimentList)cloner.Clone(this.hiveExperiments);
63      return clone;
64    }
65
66    public void UpdateExperimentList() {
67      //IClientFacade client = CreateClientFacade();
68      using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
69        ResponseObject<JobResultList> response = service.Obj.GetChildJobResults(null, false, false);
70        RefreshExperimentList(response.Obj);
71      }
72      //ServiceLocator.DisposeClientFacade(client);
73    }
74
75    private void RefreshExperimentList(JobResultList jobResultList) {
76      foreach (JobResult jobResult in jobResultList) {
77        HiveExperiment hiveExperiment = GetHiveExperiment(jobResult);
78        if (hiveExperiment == null) {
79          // create new
80          hiveExperiment = new HiveExperiment() { RootJobItem = new JobItem(jobResult) };
81          this.hiveExperiments.Add(hiveExperiment);
82        } else {
83          // update
84          //hiveExperiment.RootJob.UpdateJob(jobResult);
85        }
86      }
87    }
88
89    private HiveExperiment GetHiveExperiment(JobResult jobResult) {
90      //var matches = this.hiveExperiments.Where(exp => exp.RootJob != null && exp.RootJob.JobDto.Id == jobResult.JobId);
91      //if (matches.Count() == 0) {
92      //  return null;
93      //} else {
94      //  return matches.First();
95      //}
96      return null;
97    }
98
99    //private IClientFacade CreateClientFacade() {
100    //  IClientFacade clientFacade = null;
101    //  try {
102    //    clientFacade = ServiceLocator.CreateClientFacade(Settings.Default.HiveServerIp);
103    //  }
104    //  catch (EndpointNotFoundException exception) {
105    //    LogMessage("Could not connect to Server: " + exception.Message);
106    //  }
107    //  return clientFacade;
108    //}
109
110    private void LogMessage(string message) {
111      // HeuristicLab.Log is not Thread-Safe, so lock on every call
112      lock (locker) {
113        log.LogMessage(message);
114      }
115    }
116
117    public event EventHandler HiveExperimentsChanged;
118    private void OnHiveExperimentsChanged() {
119      var handler = HiveExperimentsChanged;
120      if (handler != null) handler(this, EventArgs.Empty);
121    }
122
123    void hiveExperiments_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
124     
125    }
126
127    void hiveExperiments_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
128     
129    }
130
131    void hiveExperiments_ItemsMoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
132     
133    }
134
135  }
136}
Note: See TracBrowser for help on using the repository browser.