Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/Administrator.cs @ 4426

Last change on this file since 4426 was 4426, checked in by swagner, 13 years ago

Worked on OKB data model and services (#1174)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Clients.Common;
24using HeuristicLab.Collections;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.PluginInfrastructure;
28
29namespace HeuristicLab.Clients.OKB {
30  [Item("Administrator", "OKB administrator front-end.")]
31  public sealed class Administrator : IContent {
32    private ItemCollection<AlgorithmClass> algorithmClasses;
33    public ItemCollection<AlgorithmClass> AlgorithmClasses {
34      get { return algorithmClasses; }
35    }
36    private ItemCollection<Algorithm> algorithms;
37    public ItemCollection<Algorithm> Algorithms {
38      get { return algorithms; }
39    }
40
41    public Administrator() {
42      algorithmClasses = new ItemCollection<AlgorithmClass>();
43      algorithms = new ItemCollection<Algorithm>();
44
45      algorithmClasses.ItemsRemoved += new CollectionItemsChangedEventHandler<AlgorithmClass>(algorithmClasses_ItemsRemoved);
46      algorithms.ItemsRemoved += new CollectionItemsChangedEventHandler<Algorithm>(algorithms_ItemsRemoved);
47    }
48
49    public void Refresh() {
50      using (AdminServiceClient adminService = ClientFactory.CreateClient<AdminServiceClient, IAdminService>()) {
51        try {
52          algorithmClasses.Clear();
53          algorithmClasses.AddRange(adminService.GetAlgorithmClasses());
54          algorithms.Clear();
55          algorithms.AddRange(adminService.GetAlgorithms());
56        }
57        catch (Exception ex) {
58          ErrorHandling.ShowErrorDialog(ex);
59        }
60      }
61    }
62
63    private void algorithmClasses_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<AlgorithmClass> e) {
64      using (AdminServiceClient adminService = ClientFactory.CreateClient<AdminServiceClient, IAdminService>()) {
65        foreach (AlgorithmClass ac in e.Items)
66          adminService.DeleteAlgorithmClass(ac.Id);
67      }
68    }
69    private void algorithms_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<Algorithm> e) {
70      using (AdminServiceClient adminService = ClientFactory.CreateClient<AdminServiceClient, IAdminService>()) {
71        foreach (Algorithm a in e.Items)
72          adminService.DeleteAlgorithm(a.Id);
73      }
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.