Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7387


Ignore:
Timestamp:
01/20/12 16:54:16 (13 years ago)
Author:
spimming
Message:

#1680:

  • Collection for hosted services added to CloudManagerClient
  • Disable controls while loading subscription
  • Stop and dispose timer
  • Rebuild treeview content on OnContentChanged event
Location:
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/CloudManagerClient.cs

    r7326 r7387  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Clients.Hive.CloudManager.Azure;
    2425using HeuristicLab.Clients.Hive.CloudManager.Model;
     
    3940    private CloudManagerClient() {
    4041      subscriptions = new ItemList<Subscription>();
     42      hostedServices = new ItemList<HostedService>();
    4143      azureProvider = new AzureProvider();
    4244    }
     
    5052          subscriptions = value;
    5153          //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;
    5264        }
    5365      }
     
    8698        foreach (Subscription subscription in subs) {
    8799          if (subscription.DiscoverServices) {
    88             //Discover
     100            List<HostedService> servs = AzureProvider.DiscoverSlaveService(subscription);
     101            foreach (HostedService s in servs) {
     102              Add(s);
     103            }
    89104          }
    90105        }
     
    119134    }
    120135
    121 
     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      }
     143      HostedServices.Add(hostedService);
     144    }
    122145
    123146
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddAzureServiceDialog.cs

    r7374 r7387  
    108108          }
    109109      }
     110    }
     111
     112    private bool ValidateInput() {
     113      bool valid = true;
     114      // TODO: input validation
     115      // see http://stackoverflow.com/questions/769184/winform-ui-validation
     116      return valid;
    110117    }
    111118
     
    159166      if (cmbChooseSubscription.SelectedItem != null) {
    160167        Subscription sub = (Subscription)cmbChooseSubscription.SelectedItem;
    161         bool newHostedServiceChecked = cbNewHostedService.Checked;
    162         bool regionChecked = rbRegion.Checked;
    163         string certFile = certificateFile;
    164         string certPw = certificatePassword;
    165         int instanceCount = Convert.ToInt32(tbInstanceCount.Text);
    166         HostedService hostedService = new HostedService();
    167         hostedService.ServiceName = tbServiceName.Text;
    168         HostedServiceProperties properties = new HostedServiceProperties();
    169         if (regionChecked) {
    170           properties.AffinityGroup = string.Empty;
     168        if (ValidateInput()) {
     169          bool newHostedServiceChecked = cbNewHostedService.Checked;
     170          bool regionChecked = rbRegion.Checked;
     171          string certFile = certificateFile;
     172          string certPw = certificatePassword;
     173          int instanceCount = Convert.ToInt32(tbInstanceCount.Text);
     174          HostedService hostedService = new HostedService();
     175          hostedService.ServiceName = tbServiceName.Text;
     176          HostedServiceProperties properties = new HostedServiceProperties();
     177          if (regionChecked) {
     178            properties.AffinityGroup = string.Empty;
     179            properties.Location = (string)cmbLocation.SelectedItem;
     180          } else {
     181            properties.AffinityGroup = ((AffinityGroup)cmbAffinityGroup.SelectedItem).Name;
     182            properties.Location = string.Empty;
     183          }
     184
     185          properties.AffinityGroup = ((AffinityGroup)cmbAffinityGroup.SelectedItem).Name;
     186          properties.Label = tbLabel.Text;
    171187          properties.Location = (string)cmbLocation.SelectedItem;
    172         } else {
    173           properties.AffinityGroup = ((AffinityGroup)cmbAffinityGroup.SelectedItem).Name;
    174           properties.Location = string.Empty;
    175         }
    176         properties.AffinityGroup = ((AffinityGroup)cmbAffinityGroup.SelectedItem).Name;
    177         properties.Label = tbLabel.Text;
    178         properties.Location = (string)cmbLocation.SelectedItem;
    179         hostedService.HostedServiceProperties = properties;
    180 
    181         var parameters = Tuple.Create<Subscription, bool, bool, string, string, HostedService, int>(sub, newHostedServiceChecked, regionChecked, certificateFile, certificatePassword, hostedService, instanceCount);
    182 
    183         bwCompleted = false;
    184         progressBar.Visible = true;
    185         SetAllControlsEnabled(this, false);
    186         workerCreate.RunWorkerAsync(parameters);
     188          hostedService.HostedServiceProperties = properties;
     189
     190          var parameters = Tuple.Create<Subscription, bool, bool, string, string, HostedService, int>(sub, newHostedServiceChecked, regionChecked, certificateFile, certificatePassword, hostedService, instanceCount);
     191
     192          bwCompleted = false;
     193          progressBar.Visible = true;
     194          SetAllControlsEnabled(this, false);
     195          workerCreate.RunWorkerAsync(parameters);
     196        }
    187197      }
    188198    }
     
    218228
    219229    private void CreateDoploymentTask(object sender, DoWorkEventArgs e) {
     230      bool errorOccured = false;
    220231      Tuple<Subscription, bool, bool, string, string, HostedService, int> parameters = (Tuple<Subscription, bool, bool, string, string, HostedService, int>)e.Argument;
    221232
     
    229240
    230241      // STEP 1 - Create Hosted Service
    231       if (newHostedServiceChecked) {
    232         if (regionChecked) {
    233           CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, hostedService.ServiceName, hostedService.HostedServiceProperties.Label, hostedService.HostedServiceProperties.Description, hostedService.HostedServiceProperties.Location);
    234         } else {
    235           CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, hostedService.ServiceName, hostedService.HostedServiceProperties.Label, hostedService.HostedServiceProperties.Description, new AffinityGroup() { Name = hostedService.HostedServiceProperties.AffinityGroup });
    236         }
     242      try {
     243        if (newHostedServiceChecked) {
     244          if (regionChecked) {
     245            CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, hostedService.ServiceName, hostedService.HostedServiceProperties.Label, hostedService.HostedServiceProperties.Description, hostedService.HostedServiceProperties.Location);
     246          } else {
     247            CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, hostedService.ServiceName, hostedService.HostedServiceProperties.Label, hostedService.HostedServiceProperties.Description, new AffinityGroup() { Name = hostedService.HostedServiceProperties.AffinityGroup });
     248          }
     249        }
     250      }
     251      catch (Exception ex) {
     252        errorOccured = true;
     253        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    237254      }
    238255
    239256      // STEP 2 - Add Certificate
    240       if (certFile != string.Empty) {
    241         CloudManagerClient.Instance.AzureProvider.AddCertificate(sub, hostedService, certFile, certPw);
     257      try {
     258        if ((!errorOccured) && (certFile != string.Empty)) {
     259          CloudManagerClient.Instance.AzureProvider.AddCertificate(sub, hostedService, certFile, certPw);
     260        }
     261      }
     262      catch (Exception ex) {
     263        errorOccured = true;
     264        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     265        if (newHostedServiceChecked) {
     266          CloudManagerClient.Instance.AzureProvider.DeleteHostedService(sub, hostedService.ServiceName);
     267        }
     268
    242269      }
    243270
    244271      // STEP 3 - Create Deployment
    245       CloudManagerClient.Instance.AzureProvider.CreateDeployment(sub, hostedService.ServiceName, Guid.NewGuid().ToString(), Constants.DeploymentSlotStaging, Constants.DeploymentPackageUrl, Constants.DeploymentConfigurationUrl, Constants.DeploymentLabel, instanceCount);
    246 
     272      try {
     273        if (!errorOccured) {
     274          CloudManagerClient.Instance.AzureProvider.CreateDeployment(sub, hostedService.ServiceName, Guid.NewGuid().ToString(), Constants.DeploymentSlotStaging, Constants.DeploymentPackageUrl, Constants.DeploymentConfigurationUrl, Constants.DeploymentLabel, instanceCount);
     275        }
     276      }
     277      catch (Exception ex) {
     278        errorOccured = true;
     279        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     280        if (newHostedServiceChecked) {
     281          CloudManagerClient.Instance.AzureProvider.DeleteHostedService(sub, hostedService.ServiceName);
     282        }
     283      }
     284
     285      e.Result = errorOccured;
    247286    }
    248287
     
    251290      progressBar.Visible = false;
    252291      bwCompleted = true;
     292      bool errorOccured = (bool)e.Result;
    253293      if (closePending) {
    254294        this.Close();
     295      } else if (!errorOccured) {
     296        this.Close();
     297      } else {
     298        this.Show();
    255299      }
    256300    }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddSubscriptionDialog.cs

    r7362 r7387  
    2424    }
    2525
     26    private void SetAllControlsEnabled(Form frm, bool isEnabled) {
     27      foreach (Control ctrl in frm.Controls) {
     28        if (!(ctrl is ProgressBar)) {
     29          ctrl.Enabled = isEnabled;
     30        }
     31      }
     32    }
     33
    2634    private void btnOk_Click(object sender, System.EventArgs e) {
    2735      this.progressBar.Visible = true;
     36      SetAllControlsEnabled(this, false);
    2837      worker.RunWorkerAsync();
    2938    }
     
    3847
    3948    private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
     49      SetAllControlsEnabled(this, true);
    4050      progressBar.Visible = false;
    4151      if (e.Error == null) {
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/CloudResourcesView.Designer.cs

    r7339 r7387  
    55    /// </summary>
    66    private System.ComponentModel.IContainer components = null;
    7 
    8     /// <summary>
    9     /// Clean up any resources being used.
    10     /// </summary>
    11     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    12     protected override void Dispose(bool disposing) {
    13       if (disposing && (components != null)) {
    14         components.Dispose();
    15       }
    16       base.Dispose(disposing);
    17     }
    187
    198    #region Component Designer generated code
     
    10695      // treeCloudResources
    10796      //
    108       this.treeCloudResources.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    109             | System.Windows.Forms.AnchorStyles.Left) 
     97      this.treeCloudResources.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     98            | System.Windows.Forms.AnchorStyles.Left)
    11099            | System.Windows.Forms.AnchorStyles.Right)));
    111100      this.treeCloudResources.ImageIndex = 0;
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/CloudResourcesView.cs

    r7339 r7387  
    11using System;
    22using System.Diagnostics;
    3 using System.Threading;
    43using System.Timers;
    54using System.Windows.Forms;
     
    1615    private int updateInterval = 15000;
    1716    private DateTime dueTime;
     17
    1818    private const int subscriptionImageIndex = 0;
    1919    private const int serviceImageIndex = 1;
     20    private const int deploymentImageIndex = 2;
    2021
    2122    public new IItemList<Subscription> Content {
     
    2425    }
    2526
     27    private IItemList<HostedService> hostedServices;
     28    public IItemList<HostedService> HostedServices {
     29      get { return hostedServices; }
     30      set { hostedServices = value; }
     31    }
     32
    2633    public CloudResourcesView() {
    2734      InitializeComponent();
    2835
     36      treeCloudResources.ImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.NewFolder);
    2937      treeCloudResources.ImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.NetworkCenterLarge);
    3038      treeCloudResources.ImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.MonitorLarge);
    3139
     40      HostedServices = CloudManagerClient.Instance.HostedServices;
    3241      Content = CloudManagerClient.Instance.Subscriptions;
     42
     43
    3344      CloudManagerClient.Instance.Refreshing += new EventHandler(Instance_Refreshing);
    3445      CloudManagerClient.Instance.Refreshed += new EventHandler(Instance_Refreshed);
     
    4152    }
    4253
    43     public new void Dispose() {
    44       CloudManagerClient.Instance.Refreshing -= new EventHandler(Instance_Refreshing);
    45       CloudManagerClient.Instance.Refreshed -= new EventHandler(Instance_Refreshed);
    46       timer.Dispose();
    47       Debug.WriteLine("Dispose");
    48     }
    49 
    5054    #region Register Content Events
    5155    protected override void DeregisterContentEvents() {
     
    6064    }
    6165    #endregion
     66
     67    /// <summary>
     68    /// Clean up any resources being used.
     69    /// </summary>
     70    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     71    protected override void Dispose(bool disposing) {
     72      if (disposing && (components != null)) {
     73        components.Dispose();
     74        CloudManagerClient.Instance.Refreshing -= new EventHandler(Instance_Refreshing);
     75        CloudManagerClient.Instance.Refreshed -= new EventHandler(Instance_Refreshed);
     76        timer.Stop();
     77        timer.Dispose();
     78        timer = null;
     79      }
     80      base.Dispose(disposing);
     81    }
    6282
    6383    protected override void SetEnabledStateOfControls() {
     
    81101        treeCloudResources.Nodes.Clear();
    82102      } else {
     103        treeCloudResources.BeginUpdate();
    83104        treeCloudResources.Nodes.Clear();
    84105        foreach (Subscription sub in Content) {
    85           TreeNode tn = new TreeNode();
    86           tn.Tag = sub;
    87           tn.Text = sub.SubscriptionName;
    88           tn.ImageIndex = subscriptionImageIndex;
    89           tn.SelectedImageIndex = tn.ImageIndex;
    90           treeCloudResources.Nodes.Add(tn);
     106          TreeNode nodeSub = new TreeNode();
     107          nodeSub.Tag = sub;
     108          nodeSub.Text = sub.SubscriptionName;
     109          nodeSub.ImageIndex = subscriptionImageIndex;
     110          nodeSub.SelectedImageIndex = nodeSub.ImageIndex;
     111
     112          foreach (HostedService s in HostedServices) {
     113            if (s.SubscriptionId == sub.SubscriptionID) {
     114              TreeNode nodeServ = new TreeNode();
     115              nodeServ.Tag = s;
     116              nodeServ.Text = s.HostedServiceProperties.Label;
     117              nodeServ.ImageIndex = serviceImageIndex;
     118              nodeServ.SelectedImageIndex = nodeServ.ImageIndex;
     119
     120              foreach (Deployment d in s.Deployments) {
     121                TreeNode nodeDepl = new TreeNode();
     122                nodeDepl.Tag = d;
     123                nodeDepl.Text = d.Label + " (" + d.DeploymentSlot + ")";
     124                nodeDepl.ImageIndex = deploymentImageIndex;
     125                nodeDepl.SelectedImageIndex = nodeDepl.ImageIndex;
     126                nodeServ.Nodes.Add(nodeDepl);
     127              }
     128              nodeSub.Nodes.Add(nodeServ);
     129            }
     130          }
     131          treeCloudResources.Nodes.Add(nodeSub);
    91132        }
     133        treeCloudResources.EndUpdate();
    92134      }
    93135    }
     
    95137    private void Instance_Refreshing(object sender, EventArgs e) {
    96138      Debug.WriteLine("Instance_Refreshing");
     139      //if (treeCloudResources.InvokeRequired) {
     140      //  treeCloudResources.Invoke((MethodInvoker)delegate { OnContentChanged(); });
     141      //} else {
     142      //  OnContentChanged();
     143      //}
    97144    }
    98145
    99146    private void Instance_Refreshed(object sender, EventArgs e) {
    100147      Debug.WriteLine("Instance_Refreshed");
     148      if (treeCloudResources.InvokeRequired) {
     149        treeCloudResources.Invoke((MethodInvoker)delegate { OnContentChanged(); });
     150      } else {
     151        OnContentChanged();
     152      }
    101153    }
    102154
     
    120172        // statistics
    121173        Debug.WriteLine("perform update");
    122         Thread.Sleep(1000);
     174        CloudManagerClient.Instance.Refresh();
    123175
    124176        dueTime = DateTime.Now.AddMilliseconds(updateInterval);
    125         timer.Start();
     177        if (timer != null) {
     178          timer.Start();
     179        }
    126180      }
    127181    }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/HiveCloudManagerView.cs

    r7324 r7387  
    3939      InitializeComponent();
    4040      cloudResourcesView.Content = CloudManagerClient.Instance.Subscriptions;
     41      cloudResourcesView.HostedServices = CloudManagerClient.Instance.HostedServices;
    4142    }
    4243
Note: See TracChangeset for help on using the changeset viewer.