コード例 #1
0
ファイル: ZawsConsoleMain.cs プロジェクト: kueiwa/ZAws
        private void awsListView_DoubleClick(object sender, EventArgs e)
        {
            if (awsListView.SelectedItems.Count != 1)
            {
                return;
            }
            ZAwsObject obj = (ZAwsObject)awsListView.SelectedItems[0].Tag;

            if (obj.GetType() == typeof(ZAwsEc2))
            {
                Program.LaunchPopupForm <PopupEc2Properties>(obj);

                /*
                 * PopupEc2Properties popup2 = new PopupEc2Properties((ZAwsEc2)obj);
                 * popup2.Show();
                 *
                 * PopupEc2Output popup = new PopupEc2Output((ZAwsEc2)obj);
                 * popup.Show();
                 * //((ZAwsEc2)obj).StartTerminal();
                 * */
                return;
            }
            if (obj.GetType() == typeof(ZAwsHostedZone))
            {
                if (((ZAwsHostedZone)obj).RecordsAvailable)
                {
                    new DlgViewDnsRecords(controller, (ZAwsHostedZone)obj).ShowDialog();
                }
                return;
            }
        }
コード例 #2
0
        public ZAwsPopupForm(ZAwsObject obj)
            : this()
        {
            MyObj = obj;
            Debug.Assert(MyObj != null);
            Debug.Assert(MyControler != null);

            this.FormClosed += new FormClosedEventHandler(HandleFormClosed);
        }
コード例 #3
0
ファイル: ZAwsPopupForm.cs プロジェクト: zmilojko/ZAws
        public ZAwsPopupForm(ZAwsObject obj)
            : this()
        {
            MyObj = obj;
            Debug.Assert(MyObj != null);
            Debug.Assert(MyControler != null);

            this.FormClosed += new FormClosedEventHandler(HandleFormClosed);
        }
コード例 #4
0
ファイル: ZawsConsoleMain.cs プロジェクト: kueiwa/ZAws
 ListViewItem ItemFromZAwsObject(ZAwsObject obj)
 {
     foreach (ListViewItem item in awsListView.Items)
     {
         if (((ZAwsObject)(item.Tag)) == obj)
         {
             return(item);
         }
     }
     throw new Exception("Cannot find object in list");
 }
コード例 #5
0
ファイル: ZawsConsoleMain.cs プロジェクト: kueiwa/ZAws
        void ZAwsObject_ObjectDeleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                //Following Invoknig must be asynchronous, so not to cause deadlock with the Disconnect handler.
                this.BeginInvoke(new EventHandler(ZAwsObject_ObjectDeleted), sender, e);
                return;
            }
            ZAwsObject obj = (ZAwsObject)sender;

            awsListView.Items.Remove(ItemFromZAwsObject(obj));
            obj.StatusChanged -= new EventHandler(ZAwsObject_StatusChanged);
            obj.ObjectDeleted -= new EventHandler(ZAwsObject_ObjectDeleted);
            awsListView_SelectedIndexChanged(sender, e);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: kueiwa/ZAws
        internal static void LaunchPopupForm <F>(ZAwsObject obj) where F : ZAwsPopupForm
        {
            foreach (var f in activePopupForms)
            {
                if (f.GetType() == typeof(F) && f.ServedType == obj.GetType() && obj == f.MyObj)
                {
                    f.Select();
                    f.Focus();
                    return;
                }
            }

            F newPopup = (F)Activator.CreateInstance(typeof(F), obj);

            newPopup.Show();
            activePopupForms.Add(newPopup);
        }
コード例 #7
0
ファイル: ZawsConsoleMain.cs プロジェクト: zmilojko/ZAws
 ListViewItem ItemFromZAwsObject(ZAwsObject obj)
 {
     foreach (ListViewItem item in awsListView.Items)
     {
         if (((ZAwsObject)(item.Tag)) == obj)
         {
             return item;
         }
     }
     throw new Exception("Cannot find object in list");
 }
コード例 #8
0
ファイル: ZawsConsoleMain.cs プロジェクト: kueiwa/ZAws
        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());
            }
        }