예제 #1
0
        public GraphDetailsDialog(GraphList graphList, DesignedGraph designedGraph)
        {
            InitializeComponent();
            tableLayoutPanel1.Visible = false;

            this.graphList = graphList;
            isNew = (designedGraph == null);
            if (isNew)
            {
                this.designedGraph = new DesignedGraph();
                // Generate an unique suggested name for the graph
                if (graphList != null)
                    this.designedGraph.DisplayName = Helpers.MakeUniqueName(Messages.GRAPH_NAME, graphList.DisplayNames);
                base.Text = Messages.GRAPHS_NEW_TITLE;
            }
            else
            {
                this.designedGraph = new DesignedGraph(designedGraph);
                base.Text = string.Format(Messages.GRAPHS_DETAILS_TITLE, this.designedGraph.DisplayName);
                SaveButton.Text = Messages.OK;
            }
            ActiveControl = GraphNameTextBox;
            GraphNameTextBox.Text = this.designedGraph.DisplayName;
            EnableControls();
        }
예제 #2
0
        public GraphDetailsDialog(GraphList graphList, DesignedGraph designedGraph)
        {
            InitializeComponent();
            tableLayoutPanel1.Visible = false;

            this.graphList = graphList;
            isNew          = (designedGraph == null);
            if (isNew)
            {
                this.designedGraph = new DesignedGraph();
                // Generate an unique suggested name for the graph
                if (graphList != null)
                {
                    this.designedGraph.DisplayName = Helpers.MakeUniqueName(Messages.GRAPH_NAME, graphList.DisplayNames);
                }
                base.Text = Messages.GRAPHS_NEW_TITLE;
            }
            else
            {
                this.designedGraph = new DesignedGraph(designedGraph);
                base.Text          = string.Format(Messages.GRAPHS_DETAILS_TITLE, this.designedGraph.DisplayName);
                SaveButton.Text    = Messages.OK;
            }
            ActiveControl         = GraphNameTextBox;
            GraphNameTextBox.Text = this.designedGraph.DisplayName;
            EnableControls();
        }
예제 #3
0
        public GraphDetailsDialog(GraphList graphList, DesignedGraph designedGraph)
        {
            InitializeComponent();

            this.graphList = graphList;
            isNew = (designedGraph == null);
            if (isNew)
            {
                this.designedGraph = new DesignedGraph();
                base.Text = Messages.GRAPHS_NEW_TITLE;
            }
            else
            {
                this.designedGraph = new DesignedGraph(designedGraph);
                base.Text = string.Format(Messages.GRAPHS_DETAILS_TITLE, this.designedGraph.DisplayName);
                SaveButton.Text = Messages.OK;
            }
            ActiveControl = GraphNameTextBox;
            GraphNameTextBox.Text = this.designedGraph.DisplayName;
            EnableControls();
        }
예제 #4
0
        public GraphDetailsDialog(GraphList graphList, DesignedGraph designedGraph)
        {
            InitializeComponent();

            this.graphList = graphList;
            isNew          = (designedGraph == null);
            if (isNew)
            {
                this.designedGraph = new DesignedGraph();
                base.Text          = Messages.GRAPHS_NEW_TITLE;
            }
            else
            {
                this.designedGraph = new DesignedGraph(designedGraph);
                base.Text          = string.Format(Messages.GRAPHS_DETAILS_TITLE, this.designedGraph.DisplayName);
                SaveButton.Text    = Messages.OK;
            }
            ActiveControl         = GraphNameTextBox;
            GraphNameTextBox.Text = this.designedGraph.DisplayName;
            EnableControls();
        }
예제 #5
0
        public void ReplaceGraphAt(int index, DesignedGraph newGraph)
        {
            if (!Graphs.IndexInRange(index))
                return;

            SuspendLayout();
            try
            {
                bool isSelected = (SelectedGraph == Graphs[index]);

                Graphs.RemoveAt(index);
                Graphs.Insert(index, newGraph);

                Plots[index].DisplayName = newGraph.DisplayName;
                Keys[index].DataSourceUUIDsToShow.Clear();
                foreach (DataSourceItem item in newGraph.DataSources)
                    Keys[index].DataSourceUUIDsToShow.Add(item.Uuid);
                Keys[index].UpdateItems();

                if (isSelected)
                {
                    SelectedGraph = newGraph;
                }
                showingDefaultGraphs = false;
            }
            finally
            {
                ResumeLayout();
            }
        }
예제 #6
0
        public void AddGraph(DesignedGraph graph)
        {
            SuspendLayout();
            try
            {
                Graphs.Add(graph);
                AddGraphDetails(graph, Graphs.Count - 1);

                SelectedGraph = graph;
                showingDefaultGraphs = false;
            }
            finally
            {
                if (VScroll)
                {
                    AdjustFormScrollbars(true);
                    ScrollControlIntoView(Plots[SelectedGraphIndex]);
                }
                ResumeLayout();
                RefreshBuffer();                
            }
        }
예제 #7
0
        public void DeleteGraph(DesignedGraph graph)
        {
            if (graph == null)
                return;

            SuspendLayout();
            try
            {
                int index = Graphs.IndexOf(graph);

                DesignedGraph newSelectedGraph = null;
                if (SelectedGraph == graph && Count > 1)
                {
                    newSelectedGraph = SelectedGraphIndex == Count - 1
                                           ? Graphs[SelectedGraphIndex - 1]
                                           : Graphs[SelectedGraphIndex + 1];
                }
                Graphs.Remove(graph);               
                DeleteGraphDetailsAt(index);

                if (newSelectedGraph != null)
                    SelectedGraph = newSelectedGraph;

                showingDefaultGraphs = false;
            }
            finally
            {
                if (VScroll)
                {
                    AdjustFormScrollbars(true);
                    ScrollControlIntoView(Plots[SelectedGraphIndex]);
                }
                ResumeLayout();
                RefreshBuffer();
            }
        }
예제 #8
0
 void AddDataSource(string uuid, List<string> dsuuids, DesignedGraph dg)
 {
     dsuuids.Add(uuid);
     dg.DataSources.Add(new DataSourceItem(new Data_source(), "", Palette.GetColour(uuid), uuid));
 }
예제 #9
0
        private void LoadDefaultGraphs()
        {
            List<string> dsuuids = new List<string>();
            if (XenObject is Host)
            {
                List<DesignedGraph> dg = new List<DesignedGraph>();

                Host host = (Host)XenObject;

                DesignedGraph cpudg = new DesignedGraph();
                cpudg.DisplayName = Messages.GRAPHS_DEFAULT_NAME_CPU;
                foreach (Host_cpu cpu in host.Connection.ResolveAll<Host_cpu>(host.host_CPUs))
                {
                    AddDataSource(string.Format("host:{0}:cpu{1}", host.uuid, cpu.number), dsuuids, cpudg);
                }

                DesignedGraph memdg = new DesignedGraph();
                memdg.DisplayName = Messages.GRAPHS_DEFAULT_NAME_MEMORY;
                AddDataSource(string.Format("host:{0}:memory_total_kib", host.uuid), dsuuids, memdg);
                AddDataSource(string.Format("host:{0}:memory_free_kib", host.uuid), dsuuids, memdg);

                DesignedGraph netdg = new DesignedGraph();
                netdg.DisplayName = Messages.GRAPHS_DEFAULT_NAME_NETWORK;
                foreach (PIF pif in host.Connection.ResolveAll(host.PIFs))
                {
                    AddDataSource(string.Format("host:{0}:pif_{1}_tx", host.uuid, pif.device), dsuuids, netdg);
                    AddDataSource(string.Format("host:{0}:pif_{1}_rx", host.uuid, pif.device), dsuuids, netdg);
                }

                dg.Add(cpudg);
                dg.Add(memdg);
                dg.Add(netdg);
                SetGraphs(dg);
            }

            if (XenObject is VM)
            {
                List<DesignedGraph> dg = new List<DesignedGraph>();

                VM vm = (VM)XenObject;

                DesignedGraph cpudg = new DesignedGraph();
                cpudg.DisplayName = Messages.GRAPHS_DEFAULT_NAME_CPU;
                for (int i = 0; i < vm.VCPUs_max; i++)
                {
                    AddDataSource(string.Format("vm:{0}:cpu{1}", vm.uuid, i), dsuuids, cpudg);
                }

                DesignedGraph memdg = new DesignedGraph();
                memdg.DisplayName = Messages.GRAPHS_DEFAULT_NAME_MEMORY;
                AddDataSource(string.Format("vm:{0}:memory", vm.uuid), dsuuids, memdg);
                AddDataSource(string.Format("vm:{0}:memory_internal_free", vm.uuid), dsuuids, memdg);

                DesignedGraph netdg = new DesignedGraph();
                netdg.DisplayName = Messages.GRAPHS_DEFAULT_NAME_NETWORK;
                foreach (VIF vif in vm.Connection.ResolveAll<VIF>(vm.VIFs))
                {
                    AddDataSource(string.Format("vm:{0}:vif_{1}_tx", vm.uuid, vif.device), dsuuids, netdg);
                    AddDataSource(string.Format("vm:{0}:vif_{1}_rx", vm.uuid, vif.device), dsuuids, netdg);
                }

                DesignedGraph diskdg = new DesignedGraph();
                diskdg.DisplayName = Messages.GRAPHS_DEFAULT_NAME_DISK;
                foreach (VBD vbd in vm.Connection.ResolveAll<VBD>(vm.VBDs))
                {
                    AddDataSource(string.Format("vm:{0}:vbd_{1}_read", vm.uuid, vbd.device), dsuuids, diskdg);
                    AddDataSource(string.Format("vm:{0}:vbd_{1}_write", vm.uuid, vbd.device), dsuuids, diskdg);
                }

                dg.Add(cpudg);
                dg.Add(memdg);
                dg.Add(netdg);
                dg.Add(diskdg);
                SetGraphs(dg);
            }
            DataPlotNav.DisplayedUuids = dsuuids;
            showingDefaultGraphs = true;
        }
예제 #10
0
        public void LoadGraphs(IXenObject xmo)
        {
            if (xmo == null)
                return;

            XenObject = xmo;

            List<string> dsuuids = new List<string>();
            Pool pool = Helpers.GetPoolOfOne(xmo.Connection);

            if (pool != null)
            {
                List<DesignedGraph> dglist = new List<DesignedGraph>();
                Dictionary<string, string> gui_config = Helpers.GetGuiConfig(pool);
                int i = 0;
                while (true)
                {
                    string key = Palette.GetLayoutKey(i,xmo);
                    if (!gui_config.ContainsKey(key))
                        break;

                    DesignedGraph dg = new DesignedGraph();
                    string[] dslist = gui_config[key].Split(',');
                    foreach (string ds in dslist)
                    {
                        AddDataSource(string.Format("{0}:{1}:{2}", xmo is Host ? "host" : "vm", Helpers.GetUuid(xmo), ds), dsuuids, dg);
                    }

                    key = Palette.GetGraphNameKey(i, xmo);
                    if (gui_config.ContainsKey(key))
                    {
                        dg.DisplayName = gui_config[key];
                    }

                    dglist.Add(dg);
                    i++;
                }

                showingDefaultGraphs = false;
                if (dglist.Count == 0)
                {
                    LoadDefaultGraphs();
                    return; // return because loaddefaultgraphs sets the displayed uuids
                }
                SetGraphs(dglist);
            }
            DataPlotNav.DisplayedUuids = dsuuids;
        }
예제 #11
0
        private void AddGraphDetails(DesignedGraph designedGraph, int index)
        {
            int y = (GRAPH_HEIGHT + CONTROL_PADDING) * index;
            if (VScroll)
                y = y - VerticalScroll.Value;

            DataPlot newplot =
                CreatePlot(new Point(CONTROL_LEFT - HorizontalScroll.Value, CONTROL_PADDING + y));

            int left = ClientSize.Width - (KEY_WIDTH + (2 * CONTROL_PADDING));
            if (left < GRAPH_MIN_WIDTH + (2 * CONTROL_PADDING))
            {
                left = GRAPH_MIN_WIDTH + (2 * CONTROL_PADDING);
            }
            DataKey newkey =
                CreateKey(new Point(left - HorizontalScroll.Value, CONTROL_PADDING + y + GRAPH_PADDING));
            foreach (DataSourceItem item in designedGraph.DataSources)
                newkey.DataSourceUUIDsToShow.Add(item.Uuid);
            newplot.DataKey = newkey;
            newkey.Enter += new EventHandler(dataKey_Enter);
            newkey.MouseDown += new MouseEventHandler(dataKey_MouseDown);
            newkey.MouseDoubleClick += new MouseEventHandler(dataKey_MouseDoubleClick);
            newkey.UpdateItems();
            newplot.DisplayName = designedGraph.DisplayName;
            newplot.MouseDown += new MouseEventHandler(dataPlot_MouseDown);
            newplot.MouseDoubleClick += new MouseEventHandler(dataPlot_MouseDoubleClick);
            newplot.RefreshBuffer();
        }
예제 #12
0
        private void buttonPrint_Click(object sender, EventArgs e)
        {
            object          misValue = System.Reflection.Missing.Value;
            FormWindowState fws      = new FormWindowState();

            fws = Program.MainWindow.WindowState;
            SaveFileDialog sfd           = new SaveFileDialog();
            string         localFilePath = null;

            sfd.Filter = "PNG|*.png|JPEG(*.JPG *.JPEG *.JPE)|*.jpg|BMP|*.bmp";
            if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != null && sfd.FileName != "")
            {
                localFilePath = sfd.FileName.ToString();
            }
            else
            {
                return;
            }
            FileStream performanceStream = new FileStream(localFilePath, FileMode.Create);

            try
            {
                //生成性能图表截图
                Program.MainWindow.WindowState = FormWindowState.Maximized;
                Program.MainWindow.Refresh();
                Bitmap   bit = new Bitmap(GraphList.Width - 30, GraphList.Height - 55);
                Graphics g   = Graphics.FromImage(bit);
                g.CopyFromScreen(GraphList.PointToScreen(System.Drawing.Point.Empty), System.Drawing.Point.Empty, GraphList.Size);
                bit.Save(performanceStream, System.Drawing.Imaging.ImageFormat.Png);
                Program.MainWindow.WindowState = fws;
                //取数据
                List <string>        dsuuids = new List <string>();
                Pool                 pool    = Helpers.GetPoolOfOne(XenObject.Connection);
                List <DesignedGraph> dglist  = new List <DesignedGraph>();
                if (pool != null)
                {
                    if (XenObject == null)
                    {
                        return;
                    }

//                    int index = GraphList.Count - 1;
//                    if (GraphList.AuthorizedRole)
//                    {
//                        GraphList.ExchangeGraphs(1, 0);
//                       GraphList.ExchangeGraphs(0, 1);
                    //GraphList.ExchangeGraphs(index-1, index);
                    //GraphList.SaveGraphs(null);
                    // }
                    Dictionary <string, string> gui_config = Helpers.GetGuiConfig(pool);
                    int i = 0;
                    while (true)
                    {
                        DesignedGraph dg  = new DesignedGraph();
                        string        key = Palette.GetLayoutKey(i, XenObject);
                        if (!gui_config.ContainsKey(key))
                        {
                            break;
                        }

                        string[] dslist = gui_config[key].Split(',');
                        foreach (string ds in dslist)
                        {
                            AddDataSource(string.Format("{0}:{1}:{2}", XenObject is Host ? "host" : "vm", Helpers.GetUuid(XenObject), ds), dsuuids, dg);
                        }

                        key = Palette.GetGraphNameKey(i, XenObject);
                        if (gui_config.ContainsKey(key))
                        {
                            dg.DisplayName = gui_config[key];
                        }

                        dglist.Add(dg);
                        i++;
                    }
                }
                //导出到Excel
                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                Workbook  xlWorkBook = xlApp.Workbooks.Add();
                Worksheet xlWorkSheet;
                Dictionary <string, string> config = Helpers.GetGuiConfig(pool);
                for (int j = 0; j < dglist.Count; j++)
                {
                    xlWorkBook.Sheets.Add(misValue, misValue, 1, XlSheetType.xlWorksheet);
                    xlWorkSheet = xlWorkBook.Worksheets.get_Item(1);
                    //每个图表创建一个对应的表单(CPU性能,内存性能...)
                    xlWorkSheet.Name = dglist[j].DisplayName;
                    //取每个表单的标签名称(cpu0,cpu1...)
                    string   key    = Palette.GetLayoutKey(j, XenObject);
                    String[] dslist = config[key].Split(',');

                    for (int i = 0; i < dslist.Length; i++)
                    {
                        //    xlWorkSheet.Cells[i + 2, 1] = dslist[i];
                        xlWorkSheet.Cells[i + 2, 1] = DataKey.items[i];
                        Microsoft.Office.Interop.Excel.Range allColumn = xlWorkSheet.Columns;
                        allColumn.AutoFit();
                    }
                }
                try
                {
                    xlWorkBook.SaveAs(localFilePath.Substring(0, localFilePath.LastIndexOf(".")) + ".xls", XlFileFormat.xlWorkbookNormal, "", "", false, false, XlSaveAsAccessMode.xlExclusive, true, true);
                    xlWorkBook.Close(true, localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1) + ".xls", false);
                    xlApp.Quit();
                }
                catch { }
                ExportSuccessfullyDialog esd = new ExportSuccessfullyDialog();
                esd.ShowDialog();
            }
            finally
            {
                performanceStream.Close();
            }
        }
예제 #13
0
 void AddDataSource(string uuid, List <string> dsuuids, DesignedGraph dg)
 {
     dsuuids.Add(uuid);
     dg.DataSources.Add(new DataSourceItem(new Data_source(), "", Palette.GetColour(uuid), uuid));
 }