示例#1
0
        public void Run()
        {
            while (!exitFlag_)
            {
                try
                {
                    if (Enable && channel_.State == ChannelState.Ready)
                    {
                        QueryStatsResponse res = null;
                        try
                        {
                            res = client_.QueryStats(new QueryStatsRequest()
                            {
                                Pattern = "", Reset = true
                            });
                        }
                        catch (Exception ex)
                        {
                            //Utils.SaveLog(ex.Message, ex);
                        }

                        if (res != null)
                        {
                            string         itemId         = config_.indexId;
                            ServerStatItem serverStatItem = GetServerStatItem(itemId);

                            //TODO: parse output
                            ParseOutput(res.Stat, out ulong up, out ulong down);

                            serverStatItem.todayUp   += up;
                            serverStatItem.todayDown += down;
                            serverStatItem.totalUp   += up;
                            serverStatItem.totalDown += down;

                            if (UpdateUI)
                            {
                                updateFunc_(up, down, new List <ServerStatItem> {
                                    serverStatItem
                                });
                            }
                        }
                    }
                    Thread.Sleep(config_.statisticsFreshRate);
                    channel_.ConnectAsync();
                }
                catch (Exception ex)
                {
                    //Utils.SaveLog(ex.Message, ex);
                }
            }
        }
示例#2
0
文件: MainForm.cs 项目: pedoc/v2rayN
        /// <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();
            //}
        }
示例#3
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
            }
        }
示例#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 (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();
            //}
        }
示例#5
0
        /// <summary>
        /// 刷新服务器列表
        /// </summary>
        private void RefreshServersView()
        {
            int index = GetLvSelectedIndex(false);

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

            for (int k = 0; k < lstVmess.Count; k++)
            {
                string    def  = string.Empty;
                VmessItem item = lstVmess[k];
                if (config.IsActiveNode(item))
                {
                    def = "√";
                }

                ListViewItem lvItem = new ListViewItem(def);
                Utils.AddSubItem(lvItem, EServerColName.configType.ToString(), (item.configType).ToString());
                Utils.AddSubItem(lvItem, EServerColName.remarks.ToString(), item.remarks);
                Utils.AddSubItem(lvItem, EServerColName.address.ToString(), item.address);
                Utils.AddSubItem(lvItem, EServerColName.port.ToString(), item.port.ToString());
                Utils.AddSubItem(lvItem, EServerColName.security.ToString(), item.security);
                Utils.AddSubItem(lvItem, EServerColName.network.ToString(), item.network);
                Utils.AddSubItem(lvItem, EServerColName.streamSecurity.ToString(), item.streamSecurity);
                Utils.AddSubItem(lvItem, EServerColName.subRemarks.ToString(), item.GetSubRemarks(config));
                Utils.AddSubItem(lvItem, EServerColName.testResult.ToString(), item.testResult);

                if (statistics != null && statistics.Enable)
                {
                    string totalUp       = string.Empty,
                           totalDown     = string.Empty,
                           todayUp       = string.Empty,
                           todayDown     = string.Empty;
                    ServerStatItem sItem = statistics.Statistic.Find(item_ => item_.itemId == item.indexId);
                    if (sItem != null)
                    {
                        totalUp   = Utils.HumanFy(sItem.totalUp);
                        totalDown = Utils.HumanFy(sItem.totalDown);
                        todayUp   = Utils.HumanFy(sItem.todayUp);
                        todayDown = Utils.HumanFy(sItem.todayDown);
                    }

                    Utils.AddSubItem(lvItem, EServerColName.todayDown.ToString(), todayDown);
                    Utils.AddSubItem(lvItem, EServerColName.todayUp.ToString(), todayUp);
                    Utils.AddSubItem(lvItem, EServerColName.totalDown.ToString(), totalDown);
                    Utils.AddSubItem(lvItem, EServerColName.totalUp.ToString(), totalUp);
                }

                if (k % 2 == 1) // 隔行着色
                {
                    lvItem.BackColor = Color.WhiteSmoke;
                }
                if (config.IsActiveNode(item))
                {
                    //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
            }
        }
示例#6
0
        public static void SortByStat(ref Config config, List <ServerStatItem> statistic, EServerColName col, bool asc)
        {
            Comparison <VmessItem> comparison = delegate(VmessItem x, VmessItem y)
            {
                ServerStatItem sItemA = statistic.Find(item_ => item_.itemId == x.getItemId());
                ServerStatItem sItemB = statistic.Find(item_ => item_.itemId == y.getItemId());
                ulong          vala   = 0;
                ulong          valb   = 0;

                var i4 = (asc ? 1 : -1);

                switch (col)
                {
                case EServerColName.todayDown:
                    if (sItemA != null)
                    {
                        vala = sItemA.todayDown;
                    }
                    if (sItemB != null)
                    {
                        valb = sItemB.todayDown;
                    }
                    break;

                case EServerColName.todayUp:
                    if (sItemA != null)
                    {
                        vala = sItemA.todayUp;
                    }
                    if (sItemB != null)
                    {
                        valb = sItemB.todayUp;
                    }
                    break;

                case EServerColName.totalDown:
                    if (sItemA != null)
                    {
                        vala = sItemA.totalDown;
                    }
                    if (sItemB != null)
                    {
                        valb = sItemB.totalDown;
                    }
                    break;

                case EServerColName.totalUp:
                    if (sItemA != null)
                    {
                        vala = sItemA.totalUp;
                    }
                    if (sItemB != null)
                    {
                        valb = sItemB.totalUp;
                    }
                    break;
                }

                return((int)(vala - valb) * i4);
            };

            if (config.vmess.Count > 0)
            {
                string itemId = config.getItemId();
                config.vmess.Sort(comparison);

                var index_ = config.vmess.FindIndex(it => it.getItemId() == itemId);
                if (index_ >= 0)
                {
                    config.index = index_;
                }

                ToJsonFile(config);
            }
        }