Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItemCollection.cs @ 6039

Last change on this file since 6039 was 5955, checked in by cneumuel, 13 years ago

#1233

  • seperated ExperimentMangerClient (OKB-Style, contains business logic) and HiveExperiment (mainly only contains information)
  • fixed redundant cloning methods in dtos
  • added simple statistics in HiveExperiment which the user can see before downloading an experiment
  • added db-delete cascade for slaves and statelogs - now slaves can be safely deleted
File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6
7namespace HeuristicLab.Clients.Hive {
8  [Item("HiveItem Collection", "Represents a collection of OKB items.")]
9  public class HiveItemCollection<T> : ItemCollection<T> where T : class, IHiveItem {
10    protected HiveItemCollection(HiveItemCollection<T> original, Cloner cloner) : base(original, cloner) { }
11    public HiveItemCollection() : base() { }
12    public HiveItemCollection(IEnumerable<T> collection) : base(collection) { }
13
14    public override IDeepCloneable Clone(Cloner cloner) { return new HiveItemCollection<T>(this, cloner); }
15
16    protected override void OnItemsRemoved(IEnumerable<T> items) {
17      IEnumerable<T> successful, unsuccessful;
18      Exception ex;
19      RemoveItems(items, out successful, out unsuccessful, out ex);
20      list.AddRange(unsuccessful);
21      base.OnItemsRemoved(successful);
22      if (ex != null) throw ex;
23    }
24    protected override void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {
25      IEnumerable<T> successful, unsuccessful;
26      Exception ex;
27      RemoveItems(oldItems, out successful, out unsuccessful, out ex);
28      list.AddRange(unsuccessful);
29      base.OnCollectionReset(items.Concat(unsuccessful), oldItems);
30      if (ex != null) throw ex;
31    }
32
33    private void RemoveItems(IEnumerable<T> items, out IEnumerable<T> successful, out IEnumerable<T> unsuccessful, out Exception exception) {
34      List<T> removed = new List<T>();
35      List<T> notremoved = new List<T>();
36      exception = null;
37      foreach (T item in items) {
38        try {
39          ExperimentManagerClient.Delete(item);
40          removed.Add(item);
41        }
42        catch (Exception ex) {
43          exception = ex;
44          notremoved.Add(item);
45        }
46      }
47      successful = removed;
48      unsuccessful = notremoved;
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.