Ejemplo n.º 1
0
        /*
         *
         * public async void StartGameScrape(ProgressDialogController controller)
         * {
         *   if (controller == null)
         *   {
         *       // create UI dialog
         *       var mySettings = new MetroDialogSettings()
         *       {
         *           NegativeButtonText = "Cancel Scraping",
         *           AnimateShow = false,
         *           AnimateHide = false
         *       };
         *       controller = await mw.ShowProgressAsync("Scraping Data", "Initialising...", true, settings: mySettings);
         *       controller.SetCancelable(true);
         *       await Task.Delay(100);
         *   }
         *
         *   await Task.Run(() =>
         *   {
         *       ScrapeGame(controller);
         *   });
         */
        /*
         * await controller.CloseAsync();
         *
         * if (controller.IsCanceled)
         * {
         *  await mw.ShowMessageAsync("MedLaunch Scraper", "Scraping Cancelled");
         * }
         * else
         * {
         *  await mw.ShowMessageAsync("MedLaunch Scraper", "Scraping Completed");
         * }
         *
         * await Task.Delay(300);
         */
        //GamesLibraryVisualHandler.RefreshGamesLibrary();

        // }
        /// <summary>
        /// Extension method to handle no controller being passed
        /// </summary>
        ///

        /*
         * public void StartGameScrape()
         * {
         *  StartGameScrape(null);
         * }
         */



        /// <summary>
        /// Creates a new entry in the GDBLink table (linking MedLaunch gameId to scraped data (thegamesdb.net) ID)
        /// also deletes any rows that have the same GameId (so that duplicates are not possible)
        /// </summary>
        /// <param name="gameId"></param>
        /// <param name="gamesDbId"></param>
        ///

        /*
         * public static void CreateDatabaseLink(int gameId, int gamesDbId)
         * {
         *  GDBLink link = new GDBLink();
         *  link.GameId = gameId;
         *  link.GdbId = gamesDbId;
         *  // delete any existing links with the same GameId
         *  GDBLink l = GDBLink.GetRecord(gameId);
         *  if (l != null)
         *  {
         *      GDBLink.DeleteRecord(l);
         *  }
         *  GDBLink.SaveToDatabase(link);
         *  PopulateLibraryData(link);
         *  GameListBuilder.UpdateFlag();
         * }
         */

        /// <summary>
        /// create data in the LibraryDataGDBLink table
        /// </summary>
        /// <param name="link"></param>
        public static void PopulateLibraryData(int gameId, int gdbId)
        {
            var data = LibraryDataGDBLink.GetLibraryData(gdbId);

            if (data == null)
            {
                data = new LibraryDataGDBLink();
            }

            GamesLibraryScrapedContent gd = new GamesLibraryScrapedContent();
            ScrapedGameObject          o  = gd.GetScrapedGameObject(gameId, gdbId);

            data.GDBId     = o.GdbId;
            data.Coop      = o.Data.Coop;
            data.Developer = o.Data.Developer;
            data.ESRB      = o.Data.ESRB;
            data.Players   = o.Data.Players;
            data.Publisher = o.Data.Publisher;
            data.Year      = o.Data.Released;

            // save library data
            LibraryDataGDBLink.SaveToDataBase(data);

            // set isScraped flag in Game table
            Game ga = Game.GetGame(gameId);

            ga.isScraped = true;
            ga.gdbId     = gdbId;
            Game.SetGame(ga);
        }
Ejemplo n.º 2
0
        /*
         *
         * public async void StartGameScrape(ProgressDialogController controller)
         * {
         *   if (controller == null)
         *   {
         *       // create UI dialog
         *       var mySettings = new MetroDialogSettings()
         *       {
         *           NegativeButtonText = "Cancel Scraping",
         *           AnimateShow = false,
         *           AnimateHide = false
         *       };
         *       controller = await mw.ShowProgressAsync("Scraping Data", "Initialising...", true, settings: mySettings);
         *       controller.SetCancelable(true);
         *       await Task.Delay(100);
         *   }
         *
         *   await Task.Run(() =>
         *   {
         *       ScrapeGame(controller);
         *   });
         */
        /*
         * await controller.CloseAsync();
         *
         * if (controller.IsCanceled)
         * {
         *  await mw.ShowMessageAsync("MedLaunch Scraper", "Scraping Cancelled");
         * }
         * else
         * {
         *  await mw.ShowMessageAsync("MedLaunch Scraper", "Scraping Completed");
         * }
         *
         * await Task.Delay(300);
         */
        //GamesLibraryVisualHandler.RefreshGamesLibrary();

        // }
        /// <summary>
        /// Extension method to handle no controller being passed
        /// </summary>
        ///

        /*
         * public void StartGameScrape()
         * {
         *  StartGameScrape(null);
         * }
         */



        /// <summary>
        /// Creates a new entry in the GDBLink table (linking MedLaunch gameId to scraped data (thegamesdb.net) ID)
        /// also deletes any rows that have the same GameId (so that duplicates are not possible)
        /// </summary>
        /// <param name="gameId"></param>
        /// <param name="gamesDbId"></param>
        ///

        /*
         * public static void CreateDatabaseLink(int gameId, int gamesDbId)
         * {
         *  GDBLink link = new GDBLink();
         *  link.GameId = gameId;
         *  link.GdbId = gamesDbId;
         *  // delete any existing links with the same GameId
         *  GDBLink l = GDBLink.GetRecord(gameId);
         *  if (l != null)
         *  {
         *      GDBLink.DeleteRecord(l);
         *  }
         *  GDBLink.SaveToDatabase(link);
         *  PopulateLibraryData(link);
         *  GameListBuilder.UpdateFlag();
         * }
         */

        /// <summary>
        /// create data in the LibraryDataGDBLink table
        /// </summary>
        /// <param name="link"></param>
        public static void PopulateLibraryData(int gameId, int gdbId)
        {
            var data = LibraryDataGDBLink.GetLibraryData(gdbId);

            if (data == null)
            {
                data = new LibraryDataGDBLink();
            }

            //ScrapeDB gd = new ScrapeDB();
            ScrapedGameObject o = ScrapeDB.GetScrapedGameObject(gameId, gdbId);

            data.GDBId     = o.GdbId;
            data.Coop      = o.Data.Coop;
            data.Developer = o.Data.Developer;
            data.ESRB      = o.Data.ESRB;
            data.Players   = o.Data.Players;
            data.Publisher = o.Data.Publisher;
            data.Year      = o.Data.Released;

            // save library data
            LibraryDataGDBLink.SaveToDataBase(data);

            // set isScraped flag in Game table
            Game ga = Game.GetGame(gameId);

            // ignore if manual editing is set
            if (ga.ManualEditSet == true)
            {
                return;
            }

            ga.isScraped = true;
            ga.gdbId     = gdbId;

            // populate new extended fields
            ga.Coop      = o.Data.Coop;
            ga.Developer = o.Data.Developer;
            ga.ESRB      = o.Data.ESRB;
            ga.Overview  = o.Data.Overview;
            ga.Players   = o.Data.Players;
            ga.Publisher = o.Data.Publisher;
            ga.Year      = o.Data.Released;

            StringBuilder sbAT = new StringBuilder();

            for (int i = 0; i < o.Data.AlternateTitles.Count(); i++)
            {
                sbAT.Append(o.Data.AlternateTitles[i]);
                if (i < (o.Data.AlternateTitles.Count() - 1))
                {
                    sbAT.Append(", ");
                }
            }
            ga.AlternateTitles = sbAT.ToString();

            StringBuilder sbGE = new StringBuilder();

            for (int i = 0; i < o.Data.AlternateTitles.Count(); i++)
            {
                sbGE.Append(o.Data.AlternateTitles[i]);
                if (i < (o.Data.AlternateTitles.Count() - 1))
                {
                    sbGE.Append(", ");
                }
            }
            ga.AlternateTitles = sbGE.ToString();

            Game.SetGame(ga);
        }
        public static List <DataGridGamesView> Update(List <DataGridGamesView> AllGames)
        {
            using (var cnt = new MyDbContext())
            {
                List <LibraryDataGDBLink> links = LibraryDataGDBLink.GetLibraryData().ToList();
                List <DataGridGamesView>  q     = new List <DataGridGamesView>();
                var games = (from g in cnt.Game
                             where g.hidden != true
                             select g).ToList();
                foreach (var game in games)
                {
                    DataGridGamesView d = new DataGridGamesView();
                    d.ID = game.gameId;

                    d.System     = GSystem.GetSystemName(game.systemId);
                    d.LastPlayed = DbEF.FormatDate(game.gameLastPlayed);
                    d.Favorite   = game.isFavorite;

                    d.Country = game.Country;

                    if (game.romNameFromDAT != null)
                    {
                        if (game.romNameFromDAT.Contains("(USA)"))
                        {
                            d.Country = "US";
                        }
                        if (game.romNameFromDAT.Contains("(Europe)"))
                        {
                            d.Country = "EU";
                        }
                    }


                    d.Flags     = game.OtherFlags;
                    d.Language  = game.Language;
                    d.Publisher = game.Publisher;
                    d.Year      = game.Year;

                    if (game.gameNameFromDAT != null && game.gameNameFromDAT != "")
                    {
                        d.Game = game.gameNameFromDAT;
                    }
                    else
                    {
                        d.Game = game.gameName;
                    }

                    //d.DatName = game.gameNameFromDAT;
                    d.DatRom = game.romNameFromDAT;

                    if (game.gdbId != null && game.gdbId > 0)
                    {
                        var link = links.Where(x => x.GDBId == game.gdbId).SingleOrDefault(); // LibraryDataGDBLink.GetLibraryData(game.gdbId.Value);
                        if (link != null)
                        {
                            if (link.Publisher != null && link.Publisher != "")
                            {
                                d.Publisher = link.Publisher;
                            }

                            d.Developer = link.Developer;

                            if (link.Year != null && link.Year != "")
                            {
                                d.Year = DbEF.ReturnYear(link.Year);
                            }
                            d.Players = link.Players;
                            d.Coop    = link.Coop;
                            d.ESRB    = link.ESRB;
                        }
                    }

                    q.Add(d);
                }


                return(q);

                //AllGames = ng;
            }
        }