Example #1
0
        /// <summary>
        /// 刷新服务器列表
        /// </summary>
        private void RefreshServersView()
        {
            lvServers.Items.Clear();

            for (int k = 0; k < config.vmess.Count; k++)
            {
                string def       = string.Empty;
                string totalUp   = string.Empty,
                       totalDown = string.Empty,
                       todayUp   = string.Empty,
                       todayDown = string.Empty;
                if (config.index.Equals(k))
                {
                    def = "√";
                }

                VmessItem item = config.vmess[k];

                ListViewItem lvItem = null;
                if (statistics != null && statistics.Enable)
                {
                    var index = statistics.Statistic.FindIndex(item_ => item_.itemId == item.getItemId());
                    if (index != -1)
                    {
                        totalUp   = Utils.HumanFy(statistics.Statistic[index].totalUp);
                        totalDown = Utils.HumanFy(statistics.Statistic[index].totalDown);
                        todayUp   = Utils.HumanFy(statistics.Statistic[index].todayUp);
                        todayDown = Utils.HumanFy(statistics.Statistic[index].todayDown);
                    }

                    lvItem = new ListViewItem(new string[]
                    {
                        def,
                        ((EConfigType)item.configType).ToString(),
                        item.remarks,
                        item.address,
                        item.port.ToString(),
                        //item.id,
                        //item.alterId.ToString(),
                        item.security,
                        item.network,
                        item.getSubRemarks(config),
                        item.testResult,
                        totalUp,
                        totalDown,
                        todayUp,
                        todayDown
                    });
                }
                else
                {
                    lvItem = new ListViewItem(new string[]
                    {
                        def,
                        ((EConfigType)item.configType).ToString(),
                        item.remarks,
                        item.address,
                        item.port.ToString(),
                        //item.id,
                        //item.alterId.ToString(),
                        item.security,
                        item.network,
                        item.getSubRemarks(config),
                        item.testResult
                        //totalUp,
                        //totalDown,
                        //todayUp,
                        //todayDown,
                    });
                }

                if (lvItem != null)
                {
                    lvServers.Items.Add(lvItem);
                }
            }

            //if (lvServers.Items.Count > 0)
            //{
            //    if (lvServers.Items.Count <= testConfigIndex)
            //    {
            //        testConfigIndex = lvServers.Items.Count - 1;
            //    }
            //    lvServers.Items[testConfigIndex].Selected = true;
            //    lvServers.Select();
            //}
        }
Example #2
0
        /// <summary>
        /// 刷新服务器列表
        /// </summary>
        private void RefreshServersView()
        {
            int index = lvServers.SelectedIndices.Count > 0 ? lvServers.SelectedIndices[0] : -1;

            lvServers.BeginUpdate();
            lvServers.Items.Clear();

            for (int k = 0; k < config.vmess.Count; k++)
            {
                string def       = string.Empty;
                string totalUp   = string.Empty,
                       totalDown = string.Empty,
                       todayUp   = string.Empty,
                       todayDown = string.Empty;
                if (config.index.Equals(k))
                {
                    def = "√";
                }

                VmessItem item = config.vmess[k];

                void _addSubItem(ListViewItem i, string name, string text)
                {
                    i.SubItems.Add(new ListViewItem.ListViewSubItem()
                    {
                        Name = name, Text = text
                    });
                }

                bool stats = statistics != null && statistics.Enable;
                if (stats)
                {
                    ServerStatItem sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId());
                    if (sItem != null)
                    {
                        totalUp   = Utils.HumanFy(sItem.totalUp);
                        totalDown = Utils.HumanFy(sItem.totalDown);
                        todayUp   = Utils.HumanFy(sItem.todayUp);
                        todayDown = Utils.HumanFy(sItem.todayDown);
                    }
                }
                ListViewItem lvItem = new ListViewItem(def);
                _addSubItem(lvItem, EServerColName.configType.ToString(), ((EConfigType)item.configType).ToString());
                _addSubItem(lvItem, EServerColName.remarks.ToString(), item.remarks);
                _addSubItem(lvItem, EServerColName.address.ToString(), item.address);
                _addSubItem(lvItem, EServerColName.port.ToString(), item.port.ToString());
                _addSubItem(lvItem, EServerColName.security.ToString(), item.security);
                _addSubItem(lvItem, EServerColName.network.ToString(), item.network);
                _addSubItem(lvItem, EServerColName.subRemarks.ToString(), item.getSubRemarks(config));
                _addSubItem(lvItem, EServerColName.testResult.ToString(), item.testResult);
                if (stats)
                {
                    _addSubItem(lvItem, EServerColName.todayDown.ToString(), todayDown);
                    _addSubItem(lvItem, EServerColName.todayUp.ToString(), todayUp);
                    _addSubItem(lvItem, EServerColName.totalDown.ToString(), totalDown);
                    _addSubItem(lvItem, EServerColName.totalUp.ToString(), totalUp);
                }

                if (k % 2 == 1) // 隔行着色
                {
                    lvItem.BackColor = Color.WhiteSmoke;
                }
                if (config.index.Equals(k))
                {
                    //lvItem.Checked = true;
                    lvItem.ForeColor = Color.DodgerBlue;
                    lvItem.Font      = new Font(lvItem.Font, FontStyle.Bold);
                }

                if (lvItem != null)
                {
                    lvServers.Items.Add(lvItem);
                }
            }
            lvServers.EndUpdate();

            if (index >= 0 && index < lvServers.Items.Count && lvServers.Items.Count > 0)
            {
                lvServers.Items[index].Selected = true;
                lvServers.EnsureVisible(index); // workaround
            }
        }
Example #3
0
        /// <summary>
        /// 刷新服务器列表
        /// </summary>
        private void RefreshServersView()
        {
            lvServers.Items.Clear();

            for (int k = 0; k < config.vmess.Count; k++)
            {
                string def       = string.Empty;
                string totalUp   = string.Empty,
                       totalDown = string.Empty,
                       todayUp   = string.Empty,
                       todayDown = string.Empty;
                if (config.index.Equals(k))
                {
                    def = "√";
                }

                VmessItem item = config.vmess[k];

                void _addSubItem(ListViewItem i, string name, string text)
                {
                    i.SubItems.Add(new ListViewItem.ListViewSubItem()
                    {
                        Name = name, Text = text
                    });
                }

                bool stats = statistics != null && statistics.Enable;
                if (stats)
                {
                    ServerStatItem sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId());
                    if (sItem != null)
                    {
                        totalUp   = Utils.HumanFy(sItem.totalUp);
                        totalDown = Utils.HumanFy(sItem.totalDown);
                        todayUp   = Utils.HumanFy(sItem.todayUp);
                        todayDown = Utils.HumanFy(sItem.todayDown);
                    }
                }
                ListViewItem lvItem = new ListViewItem(def);
                _addSubItem(lvItem, "type", ((EConfigType)item.configType).ToString());
                _addSubItem(lvItem, "remarks", item.remarks);
                _addSubItem(lvItem, "address", item.address);
                _addSubItem(lvItem, "port", item.port.ToString());
                //_addSubItem(lvItem, "id", item.id);
                //_addSubItem(lvItem, "alterId", item.alterId.ToString());
                _addSubItem(lvItem, "security", item.security);
                _addSubItem(lvItem, "network", item.network);
                _addSubItem(lvItem, "SubRemarks", item.getSubRemarks(config));
                _addSubItem(lvItem, "testResult", item.testResult);
                if (stats)
                {
                    _addSubItem(lvItem, "todayDown", todayDown);
                    _addSubItem(lvItem, "todayUp", todayUp);
                    _addSubItem(lvItem, "totalDown", totalDown);
                    _addSubItem(lvItem, "totalUp", totalUp);
                }

                if (k % 2 == 1) // 隔行着色
                {
                    lvItem.BackColor = Color.WhiteSmoke;
                }
                if (config.index.Equals(k))
                {
                    //lvItem.Checked = true;
                    lvItem.ForeColor = Color.DodgerBlue;
                    lvItem.Font      = new Font(lvItem.Font, FontStyle.Bold);
                }

                if (lvItem != null)
                {
                    lvServers.Items.Add(lvItem);
                }
            }

            //if (lvServers.Items.Count > 0)
            //{
            //    if (lvServers.Items.Count <= testConfigIndex)
            //    {
            //        testConfigIndex = lvServers.Items.Count - 1;
            //    }
            //    lvServers.Items[testConfigIndex].Selected = true;
            //    lvServers.Select();
            //}
        }
Example #4
0
        /// <summary>
        /// 刷新服务器列表
        /// </summary>
        private void RefreshServersView()
        {
            lvServers.Items.Clear();

            for (int k = 0; k < config.vmess.Count; k++)
            {
                string def       = string.Empty;
                string totalUp   = string.Empty,
                       totalDown = string.Empty,
                       todayUp   = string.Empty,
                       todayDown = string.Empty;
                if (config.index.Equals(k))
                {
                    def = "√";
                }

                VmessItem item = config.vmess[k];

                ListViewItem lvItem = null;
                if (statistics != null && statistics.Enable)
                {
                    ServerStatItem sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId());
                    if (sItem != null)
                    {
                        totalUp   = Utils.HumanFy(sItem.totalUp);
                        totalDown = Utils.HumanFy(sItem.totalDown);
                        todayUp   = Utils.HumanFy(sItem.todayUp);
                        todayDown = Utils.HumanFy(sItem.todayDown);
                    }

                    lvItem = new ListViewItem(new string[]
                    {
                        def,
                        ((EConfigType)item.configType).ToString(),
                        item.remarks,
                        item.address,
                        item.port.ToString(),
                        //item.id,
                        //item.alterId.ToString(),
                        item.security,
                        item.network,
                        item.getSubRemarks(config),
                        item.testResult,
                        todayDown,
                        todayUp,
                        totalDown,
                        totalUp
                    });
                }
                else
                {
                    lvItem = new ListViewItem(new string[]
                    {
                        def,
                        ((EConfigType)item.configType).ToString(),
                        item.remarks,
                        item.address,
                        item.port.ToString(),
                        //item.id,
                        //item.alterId.ToString(),
                        item.security,
                        item.network,
                        item.getSubRemarks(config),
                        item.testResult
                    });
                }
                if (k % 2 == 1) // 隔行着色
                {
                    lvItem.BackColor = Color.WhiteSmoke;
                }
                if (config.index.Equals(k))
                {
                    //lvItem.Checked = true;
                    lvItem.ForeColor = Color.Blue;
                    lvItem.Font      = new Font(lvItem.Font, FontStyle.Bold);
                }

                if (lvItem != null)
                {
                    lvServers.Items.Add(lvItem);
                }
            }

            //if (lvServers.Items.Count > 0)
            //{
            //    if (lvServers.Items.Count <= testConfigIndex)
            //    {
            //        testConfigIndex = lvServers.Items.Count - 1;
            //    }
            //    lvServers.Items[testConfigIndex].Selected = true;
            //    lvServers.Select();
            //}
        }