Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/18/12 17:06:12 (13 years ago)
Author:
spimming
Message:

#1680:

  • Constants for deployments added
  • worker for creating a deployment added
  • create hosted service
File:
1 edited

Legend:

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

    r7362 r7366  
    1313    private BindingList<AffinityGroup> affinityGroups;
    1414
    15     private BackgroundWorker worker;
     15    private BackgroundWorker workerUpdate;
     16    private BackgroundWorker workerCreate;
    1617
    1718    private bool isInitializing;
     
    4142      }
    4243
    43       worker = new BackgroundWorker();
    44       worker.DoWork += new DoWorkEventHandler(UpdateTask);
    45       worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
    46 
     44      workerUpdate = new BackgroundWorker();
     45      workerUpdate.DoWork += new DoWorkEventHandler(UpdateTask);
     46      workerUpdate.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
     47
     48      workerCreate = new BackgroundWorker();
     49      workerCreate.DoWork += new DoWorkEventHandler(CreateDoploymentTask);
     50      workerCreate.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CreateDeploymentCompleted);
    4751
    4852      isInitializing = false;
     
    9094        foreach (T item in list)
    9195          bindinglist.Add(item);
     96      }
     97    }
     98
     99    private void UpdateSubscriptionItem(BindingList<Subscription> bindinglist, Subscription item) {
     100      if (item != null) {
     101        foreach (Subscription blItem in bindinglist)
     102          if (blItem.Equals(item)) {
     103            blItem.Merge(item);
     104          }
    92105      }
    93106    }
     
    119132          progressBar.Visible = true;
    120133          SetAllControlsEnabled(this, false);
    121           worker.RunWorkerAsync(item);
     134          workerUpdate.RunWorkerAsync(item);
    122135        }
    123136      }
     
    141154    private void btnOk_Click(object sender, EventArgs e) {
    142155      if (cmbChooseSubscription.SelectedItem != null) {
    143         if (cbNewHostedService.Checked) {
    144           if (rbRegion.Checked) {
    145             string serviceName = tbServiceName.Text;
    146             string label = tbLabel.Text;
    147             string location = (string)cmbLocation.SelectedItem;
    148             Subscription sub = (Subscription)cmbChooseSubscription.SelectedItem;
    149             CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, serviceName, label, "Hosted service for hive slave", location);
    150           } else {
    151             // rbAffinitGroup.Checked
    152           }
    153         }
     156        Subscription sub = (Subscription)cmbChooseSubscription.SelectedItem;
     157        bool newHostedServiceChecked = cbNewHostedService.Checked;
     158        bool regionChecked = rbRegion.Checked;
     159        string certFile = certificateFile;
     160        string certPw = certificatePassword;
     161        int instanceCount = Convert.ToInt32(tbInstanceCount.Text);
     162        HostedService hostedService = new HostedService();
     163        hostedService.ServiceName = tbServiceName.Text;
     164        HostedServiceProperties properties = new HostedServiceProperties();
     165        if (regionChecked) {
     166          properties.AffinityGroup = string.Empty;
     167          properties.Location = (string)cmbLocation.SelectedItem;
     168        } else {
     169          properties.AffinityGroup = ((AffinityGroup)cmbAffinityGroup.SelectedItem).Name;
     170          properties.Location = string.Empty;
     171        }
     172        properties.AffinityGroup = ((AffinityGroup)cmbAffinityGroup.SelectedItem).Name;
     173        properties.Label = tbLabel.Text;
     174        properties.Location = (string)cmbLocation.SelectedItem;
     175        hostedService.HostedServiceProperties = properties;
     176
     177        var parameters = Tuple.Create<Subscription, bool, bool, string, string, HostedService, int>(sub, newHostedServiceChecked, regionChecked, certificateFile, certificatePassword, hostedService, instanceCount);
     178
     179        bwCompleted = false;
     180        progressBar.Visible = true;
     181        SetAllControlsEnabled(this, false);
     182        workerCreate.RunWorkerAsync(parameters);
    154183      }
    155184    }
     
    165194        List<AffinityGroup> groups = CloudManagerClient.Instance.AzureProvider.ListAffinityGroups(item);
    166195
     196        this.Invoke((MethodInvoker)delegate { UpdateSubscriptionItem(subscriptions, item); });
    167197        this.Invoke((MethodInvoker)delegate { UpdateBindingList<HostedService>(hostedServices, services); });
    168198        this.Invoke((MethodInvoker)delegate { UpdateBindingList<string>(locations, locs); });
     
    182212      }
    183213    }
     214
     215    private void CreateDoploymentTask(object sender, DoWorkEventArgs e) {
     216      Tuple<Subscription, bool, bool, string, string, HostedService, int> parameters = (Tuple<Subscription, bool, bool, string, string, HostedService, int>)e.Argument;
     217
     218      Subscription sub = parameters.Item1;
     219      bool newHostedServiceChecked = parameters.Item2;
     220      bool regionChecked = parameters.Item3;
     221      string certFile = parameters.Item4;
     222      string certPw = parameters.Item5;
     223      HostedService hostedService = parameters.Item6;
     224      int instanceCount = parameters.Item7;
     225
     226      //STEP 1 - Create Hosted Service
     227      if (newHostedServiceChecked) {
     228        if (regionChecked) {
     229          CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, hostedService.ServiceName, hostedService.HostedServiceProperties.Label, hostedService.HostedServiceProperties.Description, hostedService.HostedServiceProperties.Location);
     230        } else {
     231          CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, hostedService.ServiceName, hostedService.HostedServiceProperties.Label, hostedService.HostedServiceProperties.Description, new AffinityGroup() { Name = hostedService.HostedServiceProperties.AffinityGroup });
     232        }
     233      }
     234
     235    }
     236
     237    private void CreateDeploymentCompleted(object sender, RunWorkerCompletedEventArgs e) {
     238      SetAllControlsEnabled(this, true);
     239      progressBar.Visible = false;
     240      bwCompleted = true;
     241      if (closePending) {
     242        this.Close();
     243      }
     244    }
    184245  }
    185246}
Note: See TracChangeset for help on using the changeset viewer.