Example #1
0
        public static bool TryParse(object source, out ServerListItem item)
        {
            ServerListItem dest;

            try
            {
                dest = (ServerListItem)source;
            }
            catch
            {
                item = null;
                return(false);
            }

            item = dest;
            return(true);
        }
Example #2
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);
            e.Graphics.Clip = new Region(e.Bounds);
            e.Graphics.Clear(Color.White);

            if (e.State.HasFlag(DrawItemState.Selected))
            {
                _ren =
                    new VisualStyleRenderer(VisualStyleElement.CreateElement("LISTVIEW",
                                                                             (int)ListViewParts.LVP_GROUPHEADER, (int)GroupHeaderStates.LVGH_OPENSELECTEDNOTFOCUSEDHOT));
            }
            else
            {
                _ren =
                    new VisualStyleRenderer(VisualStyleElement.CreateElement("LISTVIEW",
                                                                             (int)ListViewParts.LVP_GROUPHEADER, (int)GroupHeaderStates.LVGH_OPEN));
            }

            _ren.DrawBackground(e.Graphics, e.Bounds);

            if (Items.Count != 0 && e.Index >= 0)
            {
                ServerListItem itm;
                ServerListItem.TryParse(Items[e.Index], out itm);

                if (itm != null)
                {
                    e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                    e.Graphics.DrawString(itm.HeaderText, Font, new SolidBrush(itm.HeaderColor), 80, e.Bounds.Y + 10);
                    e.Graphics.DrawString(itm.ItemText, Font, new SolidBrush(ForeColor), 80, e.Bounds.Y + 33);
                    e.Graphics.DrawImage(itm.ItemImage, 15, e.Bounds.Y + 13);
                }
                else
                {
                    Items.RemoveAt(e.Index);
                }
            }
        }
Example #3
0
        public static bool TryParse(object source, out ServerListItem item)
        {
            ServerListItem dest;
            try
            {
                dest = (ServerListItem) source;
            }
            catch
            {
                item = null;
                return false;
            }

            item = dest;
            return true;
        }
        /// <summary>
        ///     Initializes the statistic servers.
        /// </summary>
        private bool InitializeServers()
        {
            if (serverList.Items.Count > 0)
                serverList.Items.Clear();

            try
            {
                var sourceContent = File.ReadAllText(Program.StatisticServersFilePath);
                _statisticsServers = Serializer.Deserialize<List<StatisticsServer>>(sourceContent);
                if (_statisticsServers == null || _statisticsServers.Count == 0)
                {
                    _statisticsServers = new List<StatisticsServer>();
                    noServersLabel.Visible = true;
                }
                else
                {
                    noServersLabel.Visible = false;
                }
            }
            catch (Exception ex)
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Error while loading the servers.",
                    ex, PopupButtons.Ok);
                return false;
            }

            foreach (var server in _statisticsServers)
            {
                try
                {
                    var listItem = new ServerListItem
                    {
                        ItemImage = imageList1.Images[0],
                        HeaderText = server.DatabaseName,
                        ItemText = String.Format("Web-URL: \"{0}\" - Database: \"{1}\"",
                            server.WebUrl, server.DatabaseName)
                    };

                    serverList.Items.Add(listItem);
                }
                catch (Exception ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, String.Format("Error while loading \"{0}\"",
                        server.DatabaseName), ex, PopupButtons.Ok);
                    return false;
                }
            }

            return true;
        }