Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Model/Subscription.cs @ 8614

Last change on this file since 8614 was 7668, checked in by spimming, 13 years ago

#1680:

  • restore subscription data on cloud manager startup
  • correct idxs for parsing subscription string
File size: 4.7 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.Text;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26
27namespace HeuristicLab.Clients.Hive.CloudManager.Model {
28  public class Subscription : Item {
29    public string SubscriptionID { get; set; }
30    public string SubscriptionName { get; set; }
31    public string SubscriptionStatus { get; set; }
32    public int MaxCoreCount { get; set; }
33    public int MaxHostedServices { get; set; }
34    public int MaxStorageAccounts { get; set; }
35    public int CurrentCoreCount { get; set; }
36    public int CurrentHostedServices { get; set; }
37    public int CurrentStorageAccounts { get; set; }
38    public string CertificateThumbprint { get; set; }
39    public bool SaveToConfig { get; set; }
40    public bool DiscoverServices { get; set; }
41
42    public Subscription() {
43
44    }
45
46    public Subscription(Subscription original, Cloner cloner) {
47      this.SubscriptionID = original.SubscriptionID;
48      this.SubscriptionName = original.SubscriptionName;
49      this.SubscriptionStatus = original.SubscriptionStatus;
50      this.MaxCoreCount = original.MaxCoreCount;
51      this.MaxHostedServices = original.MaxHostedServices;
52      this.MaxStorageAccounts = original.MaxStorageAccounts;
53      this.CurrentCoreCount = original.CurrentCoreCount;
54      this.CurrentHostedServices = original.CurrentHostedServices;
55      this.CurrentStorageAccounts = original.CurrentStorageAccounts;
56      this.CertificateThumbprint = original.CertificateThumbprint;
57      this.SaveToConfig = original.SaveToConfig;
58      this.DiscoverServices = original.DiscoverServices;
59    }
60
61    //public Subscription(Subscription original, Cloner cloner) {}
62
63    public override string ToString() {
64      StringBuilder sb = new StringBuilder();
65      sb.AppendFormat("AzureSubscription: Id={0}, Name={1}, CoreCount={2}/{3}, HostedServices={4}/{5};", SubscriptionID, SubscriptionName, CurrentCoreCount, MaxCoreCount, CurrentHostedServices, MaxHostedServices);
66      return sb.ToString();
67    }
68
69    public override int GetHashCode() {
70      return base.GetHashCode();
71    }
72
73    public override bool Equals(object obj) {
74      if (obj == null)
75        return false;
76      Subscription sub = obj as Subscription;
77      if ((this.SubscriptionID == sub.SubscriptionID))
78        return true;
79      else
80        return false;
81    }
82
83    public override IDeepCloneable Clone(Cloner cloner) {
84      return new Subscription(this, cloner);
85    }
86
87    public void Merge(Subscription subscription) {
88      if (!this.Equals(subscription)) {
89        throw new ArgumentException("Objects must be equal to be merged.", "subscription");
90      }
91      this.SubscriptionName = subscription.SubscriptionName;
92      this.SubscriptionStatus = subscription.SubscriptionStatus;
93      this.MaxCoreCount = subscription.MaxCoreCount;
94      this.MaxHostedServices = subscription.MaxHostedServices;
95      this.MaxStorageAccounts = subscription.MaxStorageAccounts;
96      this.CurrentCoreCount = subscription.CurrentCoreCount;
97      this.CurrentHostedServices = subscription.CurrentHostedServices;
98      this.CurrentStorageAccounts = subscription.CurrentStorageAccounts;
99      this.CertificateThumbprint = subscription.CertificateThumbprint;
100      this.SaveToConfig = subscription.SaveToConfig;
101      this.DiscoverServices = subscription.DiscoverServices;
102    }
103
104    public string GetSettingString() {
105      return SubscriptionID + ";" + CertificateThumbprint;
106    }
107
108    public static Subscription ParseSettingString(string settingString) {
109      int idxSeparator = settingString.IndexOf(';');
110      string subId = settingString.Substring(0, idxSeparator);
111      int length = settingString.Length - 1 - idxSeparator;
112      string certThumbprint = settingString.Substring(idxSeparator + 1, length);
113      Subscription sub = new Subscription();
114      sub.SubscriptionID = subId;
115      sub.CertificateThumbprint = certThumbprint;
116      return sub;
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.