Пример #1
0
        private static MinecraftModpacksBrowser FromCurseModpack(Curse.CurseBrowser curseModpack)
        {
            var pack = new MinecraftModpacksBrowser()
            {
                Id           = curseModpack.Id,
                Name         = curseModpack.Name,
                Description  = curseModpack.Summary,
                Status       = "success",
                Synopsis     = curseModpack.Summary,
                Type         = "Curseforge",
                Updated      = ((DateTimeOffset)curseModpack.DateReleased.ToUniversalTime()).ToUnixTimeMilliseconds(),
                Installs     = 0,
                Featured     = false,
                Plays        = 0,
                Refreshed    = ((DateTimeOffset)curseModpack.DateModified.ToUniversalTime()).ToUnixTimeMilliseconds(),
                Notification = string.Empty,
                Art          = new MinecraftModpacksArt[] {
                    new MinecraftModpacksArt()
                    {
                        Url = curseModpack.Attachments[0].Url
                    }
                }
            };

            var versions = new List <MinecraftModpacksVersion>();

            foreach (var version in curseModpack.GameVersionLatestFiles)
            {
                versions.Add(new MinecraftModpacksVersion()
                {
                    Id   = version.ProjectFileId,
                    Name = string.Format("{0} {1}", pack.Name, version.GameVersion),
                    Type = "Release"
                });
            }
            pack.Versions = versions.ToArray();

            return(pack);
        }
Пример #2
0
        public static List <MinecraftModpacksBrowser> Search(string sortBy = "modpack/updated", string query = "", int page = 1, int pageSize = 10)
        {
            if (sortBy.StartsWith("curseforge/"))
            {
                var packs      = new List <MinecraftModpacksBrowser>();
                var sort       = sortBy.Split('/')[1];
                var cursepacks = Curse.CurseBrowser.Search(query: query, page: page, pageSize: pageSize, sectionId: "4471", sort: sort);
                foreach (var cursepack in cursepacks)
                {
                    packs.Add(FromCurseModpack(cursepack));
                }
                return(packs);
            }


            var search = ModPackSearchResult.Search(sortBy, query);

            if (search == null)
            {
                return(null);
            }

            var modinfos     = new List <MinecraftModpacksBrowser>();
            var skip         = (page - 1) * pageSize;
            var currentpacks = search.Packs.Concat(search.Curseforge).ToArray().Skip(skip).Take(pageSize).ToArray();

            var listOfActions = new List <Action>();
            var lockobj       = new object();

            currentpacks.ToList().ForEach(p => {
                if (search.Packs.Contains(p))
                {
                    listOfActions.Add(() =>
                    {
                        var modpack = MinecraftModpacksBrowser.GetPack(p);
                        lock (lockobj)
                        {
                            modinfos.Add(modpack);
                        }
                    });
                }
                else
                {
                    listOfActions.Add(() =>
                    {
                        var modpack = MinecraftModpacksBrowser.GetCurseforgePack(p);
                        lock (lockobj)
                        {
                            modinfos.Add(modpack);
                        }
                    });
                }
            }
                                          );

            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 10
            };

            Parallel.Invoke(options, listOfActions.ToArray());

            //Items could have wrong order. Order them again.
            var orderedmodinfos = new List <MinecraftModpacksBrowser>();

            for (int i = 0; i < currentpacks.Length; i++)
            {
                var packid = currentpacks[i].ToString();
                orderedmodinfos.Add(modinfos.SingleOrDefault(m => m.Id == packid));
            }
            return(orderedmodinfos);
        }