Пример #1
0
        public static void ScrapeBasicGamesList(ProgressDialogController controller)
        {
            List <GDBPlatformGame> gs = new List <GDBPlatformGame>();
            int count    = 0;
            int sysCount = GSystem.GetSystems().Count - 3;

            if (controller != null)
            {
                controller.Minimum = 0;
                controller.Maximum = sysCount;
            }

            foreach (GSystem sys in GSystem.GetSystems())
            {
                if (controller.IsCanceled)
                {
                    controller.CloseAsync();
                    return;
                }
                // skip systems that are not needed
                if (sys.systemId == 16 || sys.systemId == 17 || sys.systemId == 18)
                {
                    continue;
                }
                count++;
                List <GDBNETGameSearchResult> merged = new List <GDBNETGameSearchResult>();

                if (controller != null)
                {
                    controller.SetProgress(Convert.ToDouble(count));
                    controller.SetMessage("Retrieving Game List for Platform: " + sys.systemName);
                    //controller.SetIndeterminate();
                }


                // perform lookups
                foreach (int gid in sys.theGamesDBPlatformId)
                {
                    if (controller.IsCanceled)
                    {
                        controller.CloseAsync();
                        return;
                    }
                    List <GDBNETGameSearchResult> result = GDBNETGamesDB.GetPlatformGames(gid).ToList();
                    if (result.Count == 0)
                    {
                        // nothing returned
                        if (controller != null)
                        {
                            controller.SetMessage("No results returned.\n Maybe an issue connecting to thegamesdb.net...");
                            Task.Delay(2000);
                        }
                    }

                    foreach (var r in result)
                    {
                        if (controller.IsCanceled)
                        {
                            controller.CloseAsync();
                            return;
                        }
                        GDBPlatformGame gsingle = new GDBPlatformGame();
                        gsingle.id              = r.ID;
                        gsingle.SystemId        = sys.systemId;
                        gsingle.GameTitle       = r.Title;
                        gsingle.GDBPlatformName = GSystem.ReturnGamesDBPlatformName(gid);
                        gsingle.ReleaseDate     = r.ReleaseDate;

                        gs.Add(gsingle);
                    }
                }
                // remove duplicates
                gs.Distinct();

                // now we have a complete list of games for our platforms from thegamesdb.net - update the local json file
                if (controller != null)
                {
                    controller.SetMessage("Saving to file...");
                }
                if (controller.IsCanceled)
                {
                    return;
                }

                string filePath = @"..\..\Data\System\TheGamesDB.json";
                string json     = JsonConvert.SerializeObject(gs, Formatting.Indented);
                File.WriteAllText(filePath, json);
            }
        }