Esempio 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);
        }
Esempio 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);
        }
Esempio n. 3
0
        /// <summary>
        /// looks up and returns scrapeddataobject based on Internal GameId (not gamesdb id)
        /// </summary>
        /// <param name="GameId"></param>
        /// <param name="GdbId"></param>
        /// <returns></returns>
        public static ScrapedGameObject GetScrapedGameObject(int GameId, int GdbId)
        {
            //Game link = Game.GetGame(GameId);

            // we have a link record - proceed and generate object
            ScrapedGameObject sgo = new ScrapedGameObject();

            if (GdbId < 1)
            {
                return(null);
            }
            sgo.GdbId = GdbId;

            // attempt to load game data json
            string gPath = AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + sgo.GdbId.ToString() + @"\" + sgo.GdbId.ToString() + ".json";

            if (File.Exists(gPath))
            {
                ScrapedGameObjectWeb sgoweb = new ScrapedGameObjectWeb();
                ScrapedGameData      sg     = new ScrapedGameData();
                string jsonString           = File.ReadAllText(gPath);
                try
                {
                    sgoweb = JsonConvert.DeserializeObject <ScrapedGameObjectWeb>(jsonString);
                }
                catch (Exception e)
                {
                    // there was a problem with the file - do nothing
                    Console.WriteLine(e);
                }
                finally
                {
                    sgo.Data = sgoweb.Data;
                    if (sgo.Data.AlternateTitles == null)
                    {
                        sgo.Data.AlternateTitles = new List <string>();
                    }
                    if (sgo.Data.Genres == null)
                    {
                        sgo.Data.AlternateTitles = new List <string>();
                    }
                }
            }
            else
            {
                sgo.Data = new ScrapedGameData();
            }

            // populate lists in object
            string baseGameDir = AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + sgo.GdbId.ToString();

            sgo.BackCovers  = GetAllFolderFiles(baseGameDir + @"\BackCover");
            sgo.Banners     = GetAllFolderFiles(baseGameDir + @"\Banners");
            sgo.FanArts     = GetAllFolderFiles(baseGameDir + @"\FanArt");
            sgo.FrontCovers = GetAllFolderFiles(baseGameDir + @"\FrontCover");
            sgo.Manuals     = GetAllFolderFiles(baseGameDir + @"\Manual");
            sgo.Medias      = GetAllFolderFiles(baseGameDir + @"\Media");
            sgo.Screenshots = GetAllFolderFiles(baseGameDir + @"\Screenshots");

            // return object
            return(sgo);
        }