[7403] | 1 | using System;
|
---|
| 2 | using System.Windows.Forms;
|
---|
| 3 | using HeuristicLab.Clients.Hive.CloudManager.Model;
|
---|
| 4 | using HeuristicLab.Core.Views;
|
---|
| 5 | using HeuristicLab.MainForm;
|
---|
| 6 |
|
---|
| 7 | namespace HeuristicLab.Clients.Hive.CloudManager.Views {
|
---|
| 8 | [View("DeploymentView")]
|
---|
| 9 | [Content(typeof(Deployment), IsDefaultView = true)]
|
---|
| 10 | public partial class DeploymentView : ItemView {
|
---|
[7433] | 11 | private const string SaveChangesString = "Save changes to take effect.";
|
---|
[7403] | 12 | public new Deployment Content {
|
---|
| 13 | get { return (Deployment)base.Content; }
|
---|
| 14 | set { base.Content = value; }
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | public DeploymentView() {
|
---|
| 18 | InitializeComponent();
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | protected override void DeregisterContentEvents() {
|
---|
| 22 | base.DeregisterContentEvents();
|
---|
| 23 | }
|
---|
| 24 | protected override void RegisterContentEvents() {
|
---|
| 25 | base.RegisterContentEvents();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | protected override void OnContentChanged() {
|
---|
| 29 | if (Content == null) {
|
---|
| 30 | txtDeploymentName.Clear();
|
---|
| 31 | txtDeploymentSlot.Clear();
|
---|
| 32 | txtDeploymentStatus.Clear();
|
---|
| 33 | txtCoresUsed.Clear();
|
---|
| 34 | } else {
|
---|
| 35 | txtDeploymentName.Text = Content.Label;
|
---|
| 36 | txtDeploymentSlot.Text = Content.DeploymentSlot;
|
---|
| 37 | txtDeploymentStatus.Text = Content.Status;
|
---|
[7577] | 38 | if (Content.RoleInstanceList != null) {
|
---|
| 39 | txtInstanceCount.Text = Content.RoleInstanceList.Count.ToString();
|
---|
| 40 | if (Content.RoleInstanceList.Count > 0) {
|
---|
| 41 | txtInstanceSize.Text = Content.RoleInstanceList[0].InstanceSize;
|
---|
| 42 | }
|
---|
| 43 | } else {
|
---|
| 44 | txtInstanceCount.Text = "";
|
---|
| 45 | txtInstanceSize.Text = "";
|
---|
[7403] | 46 | }
|
---|
| 47 |
|
---|
[7577] | 48 |
|
---|
[7403] | 49 | tbChangeCores.Minimum = 1;
|
---|
| 50 | tbChangeCores.Maximum = Content.Subscription.MaxCoreCount;
|
---|
[7433] | 51 | if (Content.Modified) {
|
---|
| 52 | tbChangeCores.Value = Content.NewInstanceCount;
|
---|
| 53 | lblChanges.Text = SaveChangesString;
|
---|
| 54 | } else {
|
---|
[7577] | 55 | if (Content.RoleInstanceList == null) {
|
---|
| 56 | tbChangeCores.Value = tbChangeCores.Minimum;
|
---|
| 57 | } else {
|
---|
| 58 | tbChangeCores.Value = Content.RoleInstanceList.Count;
|
---|
| 59 | }
|
---|
[7441] | 60 | lblChanges.Text = "";
|
---|
[7433] | 61 | }
|
---|
[7403] | 62 |
|
---|
| 63 | txtCoresUsed.Text = (tbChangeCores.Value * GetCoresFromInstanceSize(txtInstanceSize.Text)).ToString();
|
---|
| 64 |
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private void tbChangeCores_Scroll(object sender, System.EventArgs e) {
|
---|
| 69 | int tbValue = tbChangeCores.Value;
|
---|
| 70 | int size = GetCoresFromInstanceSize(txtInstanceSize.Text);
|
---|
| 71 | txtInstanceCount.Text = tbValue.ToString();
|
---|
| 72 | int cores = tbValue * (int)size;
|
---|
| 73 | txtCoresUsed.Text = cores.ToString();
|
---|
[7433] | 74 |
|
---|
| 75 | if (Content.RoleInstanceList.Count != tbValue) {
|
---|
| 76 | Content.Modified = true;
|
---|
| 77 | lblChanges.Text = SaveChangesString;
|
---|
| 78 | } else {
|
---|
| 79 | Content.Modified = false;
|
---|
| 80 | lblChanges.Text = string.Empty;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | Content.NewInstanceCount = tbValue;
|
---|
[7403] | 84 | }
|
---|
| 85 |
|
---|
| 86 | private int GetCoresFromInstanceSize(string instanceSize) {
|
---|
[7577] | 87 | if (instanceSize != string.Empty) {
|
---|
| 88 | HeuristicLab.Clients.Hive.CloudManager.Azure.Constants.InstanceSize size =
|
---|
| 89 | (HeuristicLab.Clients.Hive.CloudManager.Azure.Constants.InstanceSize)Enum.Parse(
|
---|
| 90 | typeof(HeuristicLab.Clients.Hive.CloudManager.Azure.Constants.InstanceSize),
|
---|
| 91 | instanceSize,
|
---|
| 92 | true);
|
---|
| 93 | return (int)size;
|
---|
| 94 | } else {
|
---|
| 95 | return 0;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[7403] | 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|