using System; using System.Windows.Forms; using HeuristicLab.Clients.Hive.CloudManager.Model; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; namespace HeuristicLab.Clients.Hive.CloudManager.Views { [View("DeploymentView")] [Content(typeof(Deployment), IsDefaultView = true)] public partial class DeploymentView : ItemView { private const string SaveChangesString = "Save changes to take effect."; public new Deployment Content { get { return (Deployment)base.Content; } set { base.Content = value; } } public DeploymentView() { InitializeComponent(); } protected override void DeregisterContentEvents() { base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); } protected override void OnContentChanged() { if (Content == null) { txtDeploymentName.Clear(); txtDeploymentSlot.Clear(); txtDeploymentStatus.Clear(); txtCoresUsed.Clear(); } else { txtDeploymentName.Text = Content.Label; txtDeploymentSlot.Text = Content.DeploymentSlot; txtDeploymentStatus.Text = Content.Status; if (Content.RoleInstanceList != null) { txtInstanceCount.Text = Content.RoleInstanceList.Count.ToString(); if (Content.RoleInstanceList.Count > 0) { txtInstanceSize.Text = Content.RoleInstanceList[0].InstanceSize; } } else { txtInstanceCount.Text = ""; txtInstanceSize.Text = ""; } tbChangeCores.Minimum = 1; tbChangeCores.Maximum = Content.Subscription.MaxCoreCount; if (Content.Modified) { tbChangeCores.Value = Content.NewInstanceCount; lblChanges.Text = SaveChangesString; } else { if (Content.RoleInstanceList == null) { tbChangeCores.Value = tbChangeCores.Minimum; } else { tbChangeCores.Value = Content.RoleInstanceList.Count; } lblChanges.Text = ""; } txtCoresUsed.Text = (tbChangeCores.Value * GetCoresFromInstanceSize(txtInstanceSize.Text)).ToString(); } } private void tbChangeCores_Scroll(object sender, System.EventArgs e) { int tbValue = tbChangeCores.Value; int size = GetCoresFromInstanceSize(txtInstanceSize.Text); txtInstanceCount.Text = tbValue.ToString(); int cores = tbValue * (int)size; txtCoresUsed.Text = cores.ToString(); if (Content.RoleInstanceList.Count != tbValue) { Content.Modified = true; lblChanges.Text = SaveChangesString; } else { Content.Modified = false; lblChanges.Text = string.Empty; } Content.NewInstanceCount = tbValue; } private int GetCoresFromInstanceSize(string instanceSize) { if (instanceSize != string.Empty) { HeuristicLab.Clients.Hive.CloudManager.Azure.Constants.InstanceSize size = (HeuristicLab.Clients.Hive.CloudManager.Azure.Constants.InstanceSize)Enum.Parse( typeof(HeuristicLab.Clients.Hive.CloudManager.Azure.Constants.InstanceSize), instanceSize, true); return (int)size; } else { return 0; } } } }