Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/CloudManagerClient.cs @ 7433

Last change on this file since 7433 was 7433, checked in by spimming, 12 years ago

#1680:

  • If CloudManagerClient contains hostedservice, merge them in add-method
  • Merge methods added deployment and hostedservice
  • Update/merge treeview in CloudResourceView
  • Indicate a change of the trackbar (DeploymentView)
File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 System.Collections.Generic;
24using HeuristicLab.Clients.Hive.CloudManager.Azure;
25using HeuristicLab.Clients.Hive.CloudManager.Model;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28
29namespace HeuristicLab.Clients.Hive.CloudManager {
30  [Item("CloudManagerClient", "Hive Cloud Manager Client.")]
31  public sealed class CloudManagerClient : IContent {
32    private static CloudManagerClient instance;
33    public static CloudManagerClient Instance {
34      get {
35        if (instance == null) instance = new CloudManagerClient();
36        return instance;
37      }
38    }
39
40    private CloudManagerClient() {
41      subscriptions = new ItemList<Subscription>();
42      hostedServices = new ItemList<HostedService>();
43      azureProvider = new AzureProvider();
44    }
45
46    #region Properties
47    private IItemList<Subscription> subscriptions;
48    public IItemList<Subscription> Subscriptions {
49      get { return subscriptions; }
50      set {
51        if (value != subscriptions) {
52          subscriptions = value;
53          //fire event OnSubscriptionsChagned
54        }
55      }
56    }
57
58    private IItemList<HostedService> hostedServices;
59    public IItemList<HostedService> HostedServices {
60      get { return hostedServices; }
61      set {
62        if (value != hostedServices) {
63          hostedServices = value;
64        }
65      }
66    }
67
68    private IAzureProvider azureProvider;
69    public IAzureProvider AzureProvider {
70      get { return azureProvider; }
71      set { azureProvider = value; }
72    }
73
74    #endregion
75
76    #region Events
77
78    public event EventHandler Refreshing;
79    private void OnRefreshing() {
80      EventHandler handler = Refreshing;
81      if (handler != null) handler(this, EventArgs.Empty);
82    }
83    public event EventHandler Refreshed;
84    private void OnRefreshed() {
85      var handler = Refreshed;
86      if (handler != null) handler(this, EventArgs.Empty);
87    }
88
89    #endregion
90
91    #region Refresh
92
93    public void Refresh() {
94      OnRefreshing();
95
96      try {
97        IItemList<Subscription> subs = new ItemList<Subscription>(Subscriptions);
98        foreach (Subscription subscription in subs) {
99          if (subscription.DiscoverServices) {
100            List<HostedService> servs = AzureProvider.DiscoverSlaveService(subscription);
101            foreach (HostedService s in servs) {
102              Add(s);
103            }
104          }
105        }
106      }
107      catch {
108        throw;
109      }
110      finally {
111        OnRefreshed();
112      }
113    }
114
115    #endregion
116
117    public void Add(Subscription subscription) {
118      if (subscription == null) {
119        throw new ArgumentNullException("subscription", "Subscription must not be null.");
120      }
121      if (Subscriptions.Contains(subscription)) {
122        Subscriptions.Remove(subscription);
123      }
124      Subscriptions.Add(subscription);
125    }
126
127    public void Remove(Subscription subscription) {
128      if (subscription == null) {
129        throw new ArgumentNullException("subscription", "Subscription must not be null.");
130      }
131      if (Subscriptions.Contains(subscription)) {
132        Subscriptions.Remove(subscription);
133      }
134    }
135
136    public void Add(HostedService hostedService) {
137      if (hostedService == null) {
138        throw new ArgumentNullException("subscription", "Subscription must not be null.");
139      }
140      if (HostedServices.Contains(hostedService)) {
141        //HostedServices.Remove(hostedService);
142        HostedService hs = HostedServices[HostedServices.IndexOf(hostedService)];
143        hs.Merge(hostedService);
144
145      } else {
146        HostedServices.Add(hostedService);
147      }
148    }
149
150
151  }
152}
Note: See TracBrowser for help on using the repository browser.