Пример #1
0
        /// <summary>
        /// process psxdatacenter DB for every system
        /// </summary>
        /// <returns></returns>
        public static List <DAT_Rom> Go()
        {
            // create empty list
            List <DAT_Rom> l = new List <DAT_Rom>();

            // get all psx games from debug database
            List <PSX_Games> games = PSX_Games.GetGames();

            // iterate through each game and parse the information into a new object
            foreach (var g in games)
            {
                DAT_Rom dr = new DAT_Rom();
                dr.country       = g.region;
                dr.datProviderId = 5;
                dr.developer     = g.developer;
                dr.language      = g.languages;
                dr.pid           = 10;
                dr.publisher     = g.publisher;
                dr.year          = g.year;
                dr.otherFlags    = g.serial;

                // names
                dr.romName = g.name;
                dr.name    = g.name
                             .Replace("[Disc 1]", "")
                             .Replace("[Disc 2]", "")
                             .Replace("[Disc 3]", "")
                             .Replace("[Disc 4]", "")
                             .Replace("[Disc 5]", "")
                             .Replace("[Disc 6]", "")
                             .Replace("[Disc 7]", "")
                             .Replace("[Disc 8]", "")
                             .Replace("[Disc 9]", "")
                             .Replace("[Disc 10]", "")
                             .Trim();

                l.Add(dr);
            }

            l.Distinct();
            return(l);
        }
Пример #2
0
        public static int[] SaveToDatabase(List <PSX_Games> games)
        {
            // get current rom list
            List <PSX_Games> current = PSX_Games.GetGames();

            int added   = 0;
            int updated = 0;

            // create temp objects pre-database actions
            List <PSX_Games> toAdd    = new List <PSX_Games>();
            List <PSX_Games> toUpdate = new List <PSX_Games>();

            // iterate through each incoming rom
            foreach (var g in games)
            {
                // attempt rom lookup in current
                var lo = (from a in current
                          where
                          a.serial == g.serial
                          select a).ToList();

                PSX_Games l = new PSX_Games();

                if (lo.Count == 1)
                {
                    l = lo.Single();
                }

                else
                {
                    // more than one serial number result - some multi-disc games share the same serial number
                    // match on name
                    l = lo.Where(a => a.name == g.name).FirstOrDefault();

                    if (l == null)
                    {
                        // give up
                        continue;
                    }
                }

                if (l == null)
                {
                    // no entry found
                    toAdd.Add(g);
                }
                else
                {
                    PSX_Games game = new PSX_Games();
                    game           = l;
                    game.infoUrl   = g.infoUrl;
                    game.name      = g.name;
                    game.languages = g.languages;
                    game.region    = g.region;

                    if (game.publisher == null)
                    {
                        game.publisher = g.publisher;
                    }
                    if (game.developer == null)
                    {
                        game.developer = g.developer;
                    }
                    if (game.year == null)
                    {
                        game.year = g.year;
                    }

                    // entry found

                    if (game != l)
                    {
                        toUpdate.Add(game);
                    }
                }
            }

            using (var db = new PsxDataCenterAdminDbContext())
            {
                // add new entries
                db.PSX_Games.AddRange(toAdd);

                // update existing entries
                db.PSX_Games.UpdateRange(toUpdate);


                db.SaveChanges();

                added   = toAdd.Count();
                updated = toUpdate.Count();

                return(new int[] { added, updated });
            }
        }
Пример #3
0
        public static async void GetExtraDetail()
        {
            PsxDc c = new PsxDc();

            var mySettings = new MetroDialogSettings()
            {
                NegativeButtonText = "Cancel",
                AnimateShow        = false,
                AnimateHide        = false
            };
            string output     = "Getting games that need additional info scraped...\n";
            var    controller = await c.mw.ShowProgressAsync("PSXDATACENTER Builder", output, true, settings : mySettings);

            controller.SetCancelable(true);
            controller.SetIndeterminate();
            await Task.Delay(1);

            await Task.Run(() =>
            {
                // load games
                List <PSX_Games> games = PSX_Games.GetGames()
                                         .Where(
                    a => a.infoUrl != null && a.infoUrl.Trim() != "" &&
                    (
                        a.publisher == null ||
                        a.developer == null ||
                        a.year == null
                    )
                    )
                                         .OrderBy(x => x.id)
                                         .ToList();

                int totalGamesToProcess = games.Count();

                //List<PSX_Games> gWorking = new List<PSX_Games>();

                output = "Performing lookups...\n";

                // iterate through each game and get extra details
                for (int i = 0; i < totalGamesToProcess; i++)
                {
                    controller.SetMessage(output + "\nGame " + i + " of " + totalGamesToProcess);
                    var re = ScrapeIndividualInfo(games[i]);
                    if (re == null)
                    {
                        continue;
                    }

                    // some arbitrary wait time to not spam the server
                    //System.Threading.Thread.Sleep(1000);

                    // add/update the database
                    PSX_Games.SaveToDatabase(re);
                }
            });

            await controller.CloseAsync();

            if (controller.IsCanceled)
            {
                await c.mw.ShowMessageAsync("DAT Builder", "Linking Cancelled");
            }
            else
            {
                await c.mw.ShowMessageAsync("DAT Builder", "Linking Completed");
            }
        }