private void buttonIpAssociate_Click(object sender, EventArgs e) { if (awsListView.SelectedItems.Count == 1 && awsListView.SelectedItems[0].Tag.GetType() == typeof(ZAwsElasticIp) && ((ZAwsElasticIp)awsListView.SelectedItems[0].Tag).Associated) { ((ZAwsElasticIp)awsListView.SelectedItems[0].Tag).Disassociate(); return; } ZAwsElasticIp ip = null; ZAwsEc2 ec2 = null; if (awsListView.SelectedItems.Count == 2) { if (awsListView.SelectedItems[0].Tag.GetType() == typeof(ZAwsElasticIp) && (!((ZAwsElasticIp)awsListView.SelectedItems[0].Tag).Associated) && awsListView.SelectedItems[1].Tag.GetType() == typeof(ZAwsEc2)) { ip = (ZAwsElasticIp)awsListView.SelectedItems[0].Tag; ec2 = (ZAwsEc2)awsListView.SelectedItems[1].Tag; } if (awsListView.SelectedItems[1].Tag.GetType() == typeof(ZAwsElasticIp) && (!((ZAwsElasticIp)awsListView.SelectedItems[1].Tag).Associated) && awsListView.SelectedItems[0].Tag.GetType() == typeof(ZAwsEc2)) { ip = (ZAwsElasticIp)awsListView.SelectedItems[1].Tag; ec2 = (ZAwsEc2)awsListView.SelectedItems[0].Tag; } } if (ip == null || ec2 == null) { return; } ip.Associate(ec2); }
public PopupEc2Properties(ZAwsEc2 ec2) : base(ec2) { InitializeComponent(); buttonStart.Click += Do.HandleInZawsUi(buttonStart_Click, "Successfully sent Start EC2 command.", "Error while sending EC2 start command, reason: {0}"); buttonStop.Click += Do.HandleInZawsUi(buttonStop_Click, "Successfully sent Stop EC2 command.", "Error while sending EC2 stop command, reason: {0}"); buttonTerminal.Click += Do.HandleInZawsUi(buttonTerminal_Click, "Successfully started SSH terminal application.", "Error while trying to start terminal application, reason: {0}"); buttonFileBrowser.Click += Do.HandleInZawsUi(buttonFileBrowser_Click, "Successfully started SFTP file browser.", "Error while starting SFTP file browser, reason: {0}"); buttonWWW.Click += Do.HandleInZawsUi(buttonWWW_Click, "Showing object in a Web browser", "Error while trying to show an object in a web browser, reason: {0}"); buttonWWWip.Click += Do.HandleInZawsUi(buttonWWWip_Click, "Showing object in a Web browser", "Error while trying to show an object in a web browser, reason: {0}"); buttonReboot.Click += Do.HandleInZawsUi(buttonReboot_Click, "Successfully sent Reboot EC2 command.", "Error while sending EC2 reboot command, reason: {0}"); buttonChangeName.Click += Do.HandleInZawsUi(buttonChangeName_Click, "Successfully changed EC2 name.", "Error while changing EC2 name, reason: {0}"); buttonMysqlAdmin.Click += Do.HandleInZawsUi(buttonMysqlAdmin_Click, "Successfully started MySQL Admin.", "Error starting MySQL Admin, reason: {0}"); buttonMysqlBrowser.Click += Do.HandleInZawsUi(buttonMysqlBrowser_Click, "Successfully started MySQL Browser.", "Error starting MySQL Browser, reason: {0}"); buttonAppsRefresh.Click += Do.HandleInZawsUi(buttonAppsRefresh_Click, "Apps info retrieved.", "Error while checking installed apps, reason: {0}"); buttonAppsUpdate.Click += Do.HandleInZawsUi(buttonAppsUpdate_Click, "Selected apps updated from repositories. NOTE: You might have to perform additional steps and/or restart the web server for changes to take effect.", "Error updating selected apps, reason: {0}"); buttonAppsRebootApache.Click += Do.HandleInZawsUi(buttonAppsRebootApache_Click, "Apache restarted.", "Problem restarting apache, reason: {0}"); buttonAppWWW.Click += new EventHandler(buttonAppWWW_Click); MyEC2.StatusChanged += new EventHandler(MyEC2_StatusChanged); MyEC2.ObjectDeleted += new EventHandler(MyEC2_ObjectDeleted); buttonChangeName.Enabled = false; }
void Ec2Instance_ConsoleUpdate(object sender, ZAwsEc2.NewConceolOutputEventArgs e) { if (this.InvokeRequired) { this.BeginInvoke(new EventHandler<ZAwsEc2.NewConceolOutputEventArgs>(Ec2Instance_ConsoleUpdate), sender, e); return; } this.Text = "Boot console output for " + Ec2Instance.Name + " - " + e.Timestamp; textBox1.Text = e.Output; textBox1.SelectionStart = textBox1.Text.Length; textBox1.ScrollToCaret(); }
public PopupEc2Output(ZAwsEc2 ec2) : base(ec2) { InitializeComponent(); }
private void awsListView_DrawItem(object sender, DrawListViewItemEventArgs e) { if (!((e.Item != null && e.Item.Tag != null && e.Item.Tag.GetType().IsSubclassOf(typeof(ZAwsObject))))) { e.DrawDefault = true; return; } ZAwsObject obj = (ZAwsObject)e.Item.Tag; e.DrawDefault = false; if ((e.State & ListViewItemStates.Selected) != 0) { e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds); } if ((e.State & ListViewItemStates.Focused) != 0) { e.Graphics.DrawRectangle(new Pen(Color.DarkGreen, 2), Rectangle.Inflate(e.Bounds, -2, -2)); } else { e.Graphics.DrawRectangle(Pens.Gray, Rectangle.Inflate(e.Bounds, -2, -2)); } Font IconFont = new Font(FontFamily.GenericSansSerif, 18, FontStyle.Bold); Font AdditionalStatusFont = new Font(FontFamily.GenericSansSerif, 6, FontStyle.Italic); Font NameFont = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Regular); Rectangle IconSpace = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 3, 100, 25); Rectangle AdditionalIconSpace = new Rectangle(e.Bounds.X + 5, e.Bounds.Y + 25, 50, 10); Rectangle NameSpace = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 30, 100, 30); Rectangle DetailsSpace1 = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 42, 100, 15); Rectangle DetailsSpace2 = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 54, 100, 15); Rectangle DetailsSpace3 = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 66, 100, 15); Rectangle DetailsSpace = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 42, e.Bounds.Width - 4, e.Bounds.Height - 44); e.Graphics.DrawString(obj.Name, NameFont, Brushes.DarkBlue, NameSpace); if (e.Item.Tag.GetType() == typeof(ZAwsEc2)) { ZAwsEc2 ec2 = (ZAwsEc2)e.Item.Tag; switch (ec2.Status) { case ZAwsEc2.Ec2Status.Running: e.Graphics.DrawString("EC2", IconFont, Brushes.Green, IconSpace); if (ec2.StatisticsValid) { bool healthy = ec2.CPUUtilizationMax < 90 && ec2.CPUUtilizationAvg < 60; e.Graphics.DrawString(string.Format("CPU: {0}", (healthy ? "healthy" : "rough")), NameFont, (healthy ? Brushes.DarkGreen : Brushes.Red), DetailsSpace1); e.Graphics.DrawString(string.Format("^{0}% >{1}%", ec2.CPUUtilizationMax, ec2.CPUUtilizationAvg), NameFont, (healthy ? Brushes.DarkGreen : Brushes.Red), DetailsSpace2); e.Graphics.DrawString(string.Format("NET: {0}", ec2.NetworkOutRecent5MinString), NameFont, Brushes.Black, DetailsSpace3); } break; case ZAwsEc2.Ec2Status.Stopped: e.Graphics.DrawString("EC2", IconFont, Brushes.Red, IconSpace); break; case ZAwsEc2.Ec2Status.Stopping: e.Graphics.DrawString("EC2", IconFont, Brushes.Red, IconSpace); e.Graphics.DrawString("stopping", AdditionalStatusFont, Brushes.Red, AdditionalIconSpace); break; case ZAwsEc2.Ec2Status.Pending: e.Graphics.DrawString("EC2", IconFont, Brushes.Green, IconSpace); e.Graphics.DrawString("booting", AdditionalStatusFont, Brushes.Green, AdditionalIconSpace); break; case ZAwsEc2.Ec2Status.Terminated: e.Graphics.DrawString("EC2", IconFont, Brushes.DarkRed, IconSpace); e.Graphics.DrawString("terminated", AdditionalStatusFont, Brushes.DarkRed, AdditionalIconSpace); e.Graphics.DrawLine(Pens.DarkRed, e.Bounds.Left, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom); e.Graphics.DrawLine(Pens.DarkRed, e.Bounds.Left, e.Bounds.Bottom, e.Bounds.Right, e.Bounds.Top); break; case ZAwsEc2.Ec2Status.ShuttingDown: e.Graphics.DrawString("EC2", IconFont, Brushes.DarkRed, IconSpace); e.Graphics.DrawString("shutting down", AdditionalStatusFont, Brushes.DarkRed, AdditionalIconSpace); break; } } else if (e.Item.Tag.GetType() == typeof(ZAwsElasticIp)) { ZAwsElasticIp ip = (ZAwsElasticIp)e.Item.Tag; if (ip.Associated) { e.Graphics.DrawString("IP", IconFont, Brushes.Green, IconSpace); e.Graphics.DrawString("=> " + ip.AssociatedEc2.Name, NameFont, Brushes.Black, DetailsSpace1); } else { e.Graphics.DrawString("IP", IconFont, Brushes.Red, IconSpace); e.Graphics.DrawString("=> X", NameFont, Brushes.Black, DetailsSpace1); } } else if (e.Item.Tag.GetType() == typeof(ZAwsS3)) { e.Graphics.DrawString("S3", IconFont, Brushes.Blue, IconSpace); } else if (e.Item.Tag.GetType() == typeof(ZAwsHostedZone)) { ZAwsHostedZone z = (ZAwsHostedZone)obj; e.Graphics.DrawString("DNS", IconFont, Brushes.Blue, IconSpace); string det = ""; foreach (var s in z.Targets) { if (!string.IsNullOrWhiteSpace(det)) { det += "\r\n"; } det += "=> " + s; } if (!string.IsNullOrWhiteSpace(det)) { e.Graphics.DrawString(det, NameFont, Brushes.Black, DetailsSpace); } } else if (e.Item.Tag.GetType() == typeof(ZAwsSnapshot)) { e.Graphics.DrawString("IMG", IconFont, Brushes.Blue, IconSpace); e.Graphics.DrawString(((ZAwsObject)e.Item.Tag).Description, NameFont, Brushes.Black, DetailsSpace); } else if (e.Item.Tag.GetType() == typeof(ZAwsSecGroup)) { e.Graphics.DrawString("Sec", IconFont, Brushes.Blue, IconSpace); e.Graphics.DrawString(((ZAwsObject)e.Item.Tag).Description, NameFont, Brushes.Black, DetailsSpace); } else if (e.Item.Tag.GetType() == typeof(ZAwsKeyPair)) { e.Graphics.DrawString("Keys", IconFont, ((ZAwsKeyPair)e.Item.Tag).Available ? Brushes.Green : Brushes.Red, IconSpace); e.Graphics.DrawString(((ZAwsObject)e.Item.Tag).Description, NameFont, Brushes.Black, DetailsSpace); } else if (e.Item.Tag.GetType() == typeof(ZAwsAmi)) { e.Graphics.DrawString("AMI", IconFont, Brushes.Purple, IconSpace); e.Graphics.DrawString(((ZAwsObject)e.Item.Tag).Description, NameFont, Brushes.Black, DetailsSpace); } else if (e.Item.Tag.GetType() == typeof(ZAwsEbsVolume)) { e.Graphics.DrawString("EBS", IconFont, Brushes.Blue, IconSpace); e.Graphics.DrawString(((ZAwsObject)e.Item.Tag).Description, NameFont, Brushes.Black, DetailsSpace); } else if (e.Item.Tag.GetType() == typeof(ZAwsSpotRequest)) { ZAwsSpotRequest r = (ZAwsSpotRequest)e.Item.Tag; Brush b = Brushes.Red; if (r.ResponseData.State == "open") { b = Brushes.Blue; } if (r.ResponseData.State == "active") { b = Brushes.Green; } e.Graphics.DrawString("SPOT", IconFont, b, IconSpace); e.Graphics.DrawString(((ZAwsObject)e.Item.Tag).Description, NameFont, Brushes.Black, DetailsSpace); } else { //Unknown ZAWS object Debug.Assert(false, "Unknown ZAWS object"); throw new ArgumentException("Unknown ZAws object: " + e.Item.Tag.GetType().ToString()); } }
DateTime myExtractor(ZAwsEc2.DataSample arg) { return arg.Time; }