Пример #1
0
            public int Compare(BaseItem x, BaseItem y)
            {
                PackageItem itemA = x as PackageItem;
                PackageItem itemB = y as PackageItem;

                if (itemA == itemB)
                {
                    return(0);
                }
                if (itemA == null)
                {
                    return(this.sortOrder == SortOrder.Ascending ? 1 : -1);
                }
                if (itemB == null)
                {
                    return(this.sortOrder == SortOrder.Ascending ? -1 : 1);
                }

                int result = 0;

                if (result == 0 || this.sortMode == SortMode.Version)
                {
                    if (itemA.Version < itemB.Version)
                    {
                        result = -1;
                    }
                    else if (itemA.Version > itemB.Version)
                    {
                        result = 1;
                    }
                }
                if (result == 0 || this.sortMode == SortMode.Downloads)
                {
                    if (itemA.Downloads.HasValue || itemB.Downloads.HasValue)
                    {
                        if (!itemA.Downloads.HasValue || itemA.Downloads < itemB.Downloads)
                        {
                            result = -1;
                        }
                        else if (!itemB.Downloads.HasValue || itemA.Downloads > itemB.Downloads)
                        {
                            result = 1;
                        }
                    }
                }
                if (result == 0 || this.sortMode == SortMode.Name)
                {
                    result = string.Compare(itemA.Title, itemB.Title);
                }
                if (result == 0)
                {
                    result = itemA.GetHashCode() - itemB.GetHashCode();
                }

                return((this.sortOrder == SortOrder.Ascending) ? -result : result);
            }
Пример #2
0
            public int Compare(BaseItem x, BaseItem y)
            {
                PackageItem itemA = x as PackageItem;
                PackageItem itemB = y as PackageItem;

                if (itemA == itemB)
                {
                    return(0);
                }
                if (itemA == null)
                {
                    return(this.sortOrder == SortOrder.Ascending ? 1 : -1);
                }
                if (itemB == null)
                {
                    return(this.sortOrder == SortOrder.Ascending ? -1 : 1);
                }

                int result = 0;

                if (result == 0 || this.sortMode == SortMode.Version)
                {
                    if (itemA.Version < itemB.Version)
                    {
                        result = -1;
                    }
                    else if (itemA.Version > itemB.Version)
                    {
                        result = 1;
                    }
                }
                if (result == 0 || this.sortMode == SortMode.Date)
                {
                    if (itemA.ItemPackageInfo.PublishDate < itemB.ItemPackageInfo.PublishDate)
                    {
                        result = -1;
                    }
                    else if (itemA.ItemPackageInfo.PublishDate > itemB.ItemPackageInfo.PublishDate)
                    {
                        result = 1;
                    }
                }
                if (result == 0 || this.sortMode == SortMode.Downloads)
                {
                    int itemANum = itemA.Downloads.HasValue ? itemA.Downloads.Value : 0;
                    int itemBNum = itemB.Downloads.HasValue ? itemB.Downloads.Value : 0;
                    result = itemANum - itemBNum;
                }
                if (result == 0 || this.sortMode == SortMode.Name)
                {
                    result = string.Compare(itemA.Title, itemB.Title);
                }
                if (result == 0 || this.sortMode == SortMode.PackageType)
                {
                    result = (int)itemA.Type - (int)itemB.Type;
                }
                if (result == 0 || this.sortMode == SortMode.CombinedScore)
                {
                    float scoreA = (float)itemA.ItemPackageInfo.DownloadCount * (1.0f - MathF.Clamp((float)(DateTime.Now - itemA.ItemPackageInfo.PublishDate).TotalDays / 360.0f, 0.001f, 1.0f));
                    float scoreB = (float)itemB.ItemPackageInfo.DownloadCount * (1.0f - MathF.Clamp((float)(DateTime.Now - itemB.ItemPackageInfo.PublishDate).TotalDays / 360.0f, 0.001f, 1.0f));
                    if (scoreA < scoreB)
                    {
                        result = -1;
                    }
                    else if (scoreA > scoreB)
                    {
                        result = 1;
                    }
                }
                if (result == 0)
                {
                    result = itemA.GetHashCode() - itemB.GetHashCode();
                }

                return((this.sortOrder == SortOrder.Ascending) ? -result : result);
            }