Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/17/10 10:26:55 (14 years ago)
Author:
cneumuel
Message:
  • Refactored HL.Hive.Experiment. JobItems are not called HiveJobs and OptimizerJobs do not contain a hierarchy anymore.
  • Dynamic generation of jobs on a slave are not reflected on the client user interface.
  • Optimizer-Trees are now strictly synchronized with the HiveJob-Trees (also the ComputeInParallel property is taken into account when the Child HiveJobs are created)
  • Improved the way a class can report progress and lock the UI (IProgressReporter, IProgress, Progress, ProgressView)
  • Changes were made to the config-files, so that server and clients work with blade12.hpc.fh-hagenberg.at
  • Lots of small changes and bugfixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveClient.cs

    r4368 r4423  
    1111using System.ServiceModel;
    1212using HeuristicLab.Hive.Contracts;
     13using HeuristicLab.DataAccess;
     14using HeuristicLab.Collections;
     15using HeuristicLab.Common;
    1316
    1417namespace HeuristicLab.Hive.Experiment {
    1518  [Item("Hive Client", "Connects to Hive and lists all submitted experiments by the current user.")]
    1619  [Creatable("Hive")]
    17   public class HiveClient : Item {
     20  public class HiveClient : Item, IProgressReporter {
    1821    private static object locker = new object();
     22    private bool currentlyUpdating;
    1923
    2024    private ILog log;
     
    2832      set {
    2933        if (hiveExperiments != value) {
    30           if (hiveExperiments != null) {
    31             DeRegisterHiveExperimentsEvents();
    32           }
     34          DeRegisterHiveExperimentsEvents();
    3335          hiveExperiments = value;
    3436          RegisterHiveExperimentsEvent();
     
    3840    }
    3941
     42    private bool isProgressing;
     43    public bool IsProgressing {
     44      get { return isProgressing; }
     45      set {
     46        if (isProgressing != value) {
     47          isProgressing = value;
     48          OnIsProgressingChanged();
     49        }
     50      }
     51    }
     52
     53    private IProgress progress;
     54    public IProgress Progress {
     55      get { return progress; }
     56    }
     57
    4058    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);
     59      if (hiveExperiments != null) {
     60        hiveExperiments.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
     61      }
    4462    }
    4563
    4664    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 
     65      if (hiveExperiments != null) {
     66        hiveExperiments.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
     67      }
    5168    }
    5269
    5370    public HiveClient() {
    5471      this.log = new Log();
    55       this.HiveExperiments = new HiveExperimentList();
    5672    }
    57 
    5873
    5974    public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
     
    6580
    6681    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);
     82      this.progress = new Progress("Downloading HiveExperiments...");
     83      try {
     84        IsProgressing = true;
     85        if (this.HiveExperiments == null) {
     86          this.HiveExperiments = new HiveExperimentList();
     87        }
     88        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
     89          currentlyUpdating = true;
     90          ResponseObject<HiveExperimentDtoList> response = service.Obj.GetHiveExperiments();
     91          progress.Status = "Populating HiveExperiment list...";
     92          RefreshExperimentList(response.Obj);
     93          currentlyUpdating = false;
     94        }
    7195      }
    72       //ServiceLocator.DisposeClientFacade(client);
     96      catch (Exception) {
     97        this.HiveExperiments = null;
     98        throw;
     99      }
     100      finally {
     101        IsProgressing = false;
     102      }
    73103    }
    74104
    75     private void RefreshExperimentList(JobResultList jobResultList) {
    76       foreach (JobResult jobResult in jobResultList) {
    77         HiveExperiment hiveExperiment = GetHiveExperiment(jobResult);
     105    private void RefreshExperimentList(HiveExperimentDtoList hiveExperiments) {
     106      foreach (HiveExperimentDto hiveExperimentDto in hiveExperiments) {
     107        HiveExperiment hiveExperiment = GetHiveExperiment(hiveExperimentDto.Id);
    78108        if (hiveExperiment == null) {
    79           // create new
    80           hiveExperiment = new HiveExperiment() { RootJobItem = new JobItem(jobResult) };
    81           this.hiveExperiments.Add(hiveExperiment);
     109          // not yet there, create new
     110          this.HiveExperiments.Add(new HiveExperiment(hiveExperimentDto));
    82111        } else {
    83112          // update
    84           //hiveExperiment.RootJob.UpdateJob(jobResult);
     113          hiveExperiment.UpdateFromDto(hiveExperimentDto);
    85114        }
    86115      }
    87116    }
    88117
    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;
     118    private HiveExperiment GetHiveExperiment(Guid hiveExperimentId) {
     119      return this.HiveExperiments.SingleOrDefault(he => he.HiveExperimentId.Equals(hiveExperimentId));
    97120    }
    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     //}
    109121
    110122    private void LogMessage(string message) {
     
    120132      if (handler != null) handler(this, EventArgs.Empty);
    121133    }
    122 
    123     void hiveExperiments_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
    124      
     134   
     135    void hiveExperiments_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
     136      if (!currentlyUpdating) {
     137        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
     138          foreach (IndexedItem<HiveExperiment> item in e.Items) {
     139            if (item.Value.HiveExperimentId != Guid.Empty) {
     140              service.Obj.DeleteHiveExperiment(item.Value.HiveExperimentId);
     141            }
     142          }
     143        }
     144      }
    125145    }
    126146
    127     void hiveExperiments_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
    128      
     147    public event EventHandler IsProgressingChanged;
     148    private void OnIsProgressingChanged() {
     149      var handler = IsProgressingChanged;
     150      if (handler != null) handler(this, EventArgs.Empty);
    129151    }
    130 
    131     void hiveExperiments_ItemsMoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
    132      
    133     }
    134 
    135152  }
    136153}
Note: See TracChangeset for help on using the changeset viewer.