Exemplo n.º 1
0
        public static int SortServers(ref Config config, EServerColName name, bool asc)
        {
            if (config.vmess.Count <= 0)
            {
                return(-1);
            }
            var propertyName = string.Empty;

            switch (name)
            {
            case EServerColName.configType:
            case EServerColName.remarks:
            case EServerColName.address:
            case EServerColName.port:
            case EServerColName.security:
            case EServerColName.network:
            case EServerColName.streamSecurity:
            case EServerColName.testResult:
                propertyName = name.ToString();
                break;

            case EServerColName.subRemarks:
                propertyName = "subid";
                break;

            default:
                return(-1);
            }
            string itemId = config.getItemId();
            var    items  = config.vmess.AsQueryable();

            if (asc)
            {
                config.vmess = items.OrderBy(propertyName).ToList();
            }
            else
            {
                config.vmess = items.OrderByDescending(propertyName).ToList();
            }

            var index_ = config.vmess.FindIndex(it => it.getItemId() == itemId);

            if (index_ >= 0)
            {
                config.index = index_;
            }

            ToJsonFile(config);
            return(0);
        }
Exemplo n.º 2
0
        public static int SortServers(ref Config config, ref List <VmessItem> lstVmess, EServerColName name, bool asc)
        {
            if (lstVmess.Count <= 0)
            {
                return(-1);
            }
            var propertyName = string.Empty;

            switch (name)
            {
            case EServerColName.configType:
            case EServerColName.remarks:
            case EServerColName.address:
            case EServerColName.port:
            case EServerColName.security:
            case EServerColName.network:
            case EServerColName.streamSecurity:
            case EServerColName.testResult:
                propertyName = name.ToString();
                break;

            case EServerColName.subRemarks:
                propertyName = "subid";
                break;

            default:
                return(-1);
            }

            var items = lstVmess.AsQueryable();

            if (asc)
            {
                lstVmess = items.OrderBy(propertyName).ToList();
            }
            else
            {
                lstVmess = items.OrderByDescending(propertyName).ToList();
            }
            for (int i = 0; i < lstVmess.Count; i++)
            {
                lstVmess[i].sort = (i + 1) * 10;
            }

            ToJsonFile(config);
            return(0);
        }
Exemplo n.º 3
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);
            }
        }