Esempio n. 1
0
        public ICollection <GDBPlatformGame> SearchGameLocal(string gameName, int systemId, int gameId)
        {
            SearchString            = gameName;
            LocalIterationCount     = 0;
            WorkingSearchCollection = new List <GDBPlatformGame>();
            SearchCollection        = new List <GDBPlatformGame>();

            // get a list with all games for this system
            SystemCollection = PlatformGames.Where(a => a.SystemId == systemId).ToList();

            // remove [anything inbetween] or (anything inbetween) from in the incoming string and remove it

            // remove any symbols
            string gName = StripSymbols(gameName);

            // Pass to search method for fuzzy searching
            StartFuzzySearch(gName, 0);

            // if there is only one entry in searchcollection - match has been found - add it to the database for scraping later
            if (WorkingSearchCollection.Count == 1)
            {
                GDBPlatformGame g  = WorkingSearchCollection.FirstOrDefault();
                GDBGameData     gd = new GDBGameData();

                gd.GameId      = gameId;
                gd.GDBGameId   = g.id;
                gd.Title       = g.GameTitle;
                gd.ReleaseDate = g.ReleaseDate;
            }
            //return SearchCollection;
            return(WorkingSearchCollection);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        private void StartFuzzySearch(string searchStr, int manualIterator)
        {
            // start iterator
            if (manualIterator > 0)
            {
            }
            else
            {
                LocalIterationCount++;
                manualIterator = LocalIterationCount;
            }

            // setup fuzzystring options based on iteration
            List <FuzzyStringComparisonOptions> fuzzOptions = new List <FuzzyStringComparisonOptions>();
            FuzzyStringComparisonTolerance      tolerance;

            switch (manualIterator)
            {
            /* Iterations to widen the selection */
            // first auto iteration - strong matching using substring, subsequence and overlap coefficient
            case 1:
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseNormalizedLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroDistance);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubsequence);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroWinklerDistance);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubstring);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseOverlapCoefficient);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseRatcliffObershelpSimilarity);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseSorensenDiceDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseTanimotoCoefficient);
                tolerance = FuzzyStringComparisonTolerance.Strong;
                break;

            // second iteration - same as the first but with normal matching
            case 2:
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseNormalizedLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroDistance);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubsequence);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroWinklerDistance);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubstring);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseOverlapCoefficient);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseRatcliffObershelpSimilarity);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseSorensenDiceDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseTanimotoCoefficient);
                tolerance = FuzzyStringComparisonTolerance.Normal;
                break;

            // 3rd auto iteration - same as the first but with weak matching
            case 3:
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseNormalizedLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroDistance);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubsequence);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroWinklerDistance);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubstring);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseOverlapCoefficient);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseRatcliffObershelpSimilarity);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseSorensenDiceDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseTanimotoCoefficient);
                tolerance = FuzzyStringComparisonTolerance.Weak;
                break;

            /* Iterations to narrow down selection */
            // first manual iteration
            case 100:
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseNormalizedLevenshteinDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubsequence);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaccardDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseHammingDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseJaroWinklerDistance);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseLongestCommonSubstring);
                //fuzzOptions.Add(FuzzyStringComparisonOptions.UseOverlapCoefficient);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseRatcliffObershelpSimilarity);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseSorensenDiceDistance);
                fuzzOptions.Add(FuzzyStringComparisonOptions.UseTanimotoCoefficient);
                tolerance = FuzzyStringComparisonTolerance.Strong;
                break;

            default:
                // end and return
                return;
            }

            // Check whether the actual game name matches the search - if so return
            GDBPlatformGame gp = SystemCollection.Where(a => StripSymbols(a.GameTitle.ToLower()).Contains(searchStr)).FirstOrDefault();

            if (gp == null)
            {
            }
            else
            {
                SearchCollection = new List <GDBPlatformGame>();
                SearchCollection.Add(gp);
                WorkingSearchCollection = new List <GDBPlatformGame>();
                WorkingSearchCollection.Add(gp);
                return;
            }

            // iterate through each gamesdb game in the list
            foreach (GDBPlatformGame g in SystemCollection)
            {
                bool result = searchStr.ApproximatelyEquals(g.GameTitle, tolerance, fuzzOptions.ToArray());
                if (result == true)
                {
                    // match found - add to searchcollection
                    SearchCollection.Add(g);
                }
                else
                {
                    // match not found
                }
            }

            // check how many matches we have
            if (SearchCollection.Count == 1)
            {
                WorkingSearchCollection = new List <GDBPlatformGame>();
                WorkingSearchCollection.Add(SearchCollection.Single());
                return;
            }

            if (SearchCollection.Count > 1)
            {
                // add to working search collection
                WorkingSearchCollection.AddRange(SearchCollection.ToList());
                // clear SearchCollection
                //SearchCollection = new List<GDBPlatformGame>();

                // try the first word
                string[] arr     = BuildArray(searchStr);
                int      i       = 0;
                string   builder = "";
                while (i < arr.Length)
                {
                    if (i == 0)
                    {
                        builder += arr[i];
                    }
                    else
                    {
                        builder += " " + arr[i];
                    }
                    string b = StripSymbols(builder).ToLower();


                    var s = SystemCollection.Where(a => a.GameTitle.ToLower().Contains(b)).ToList();
                    if (s.Count == 1)
                    {
                        // one entry returned - this is the one to keep
                        WorkingSearchCollection = new List <GDBPlatformGame>();
                        //SearchCollection = new List<GDBPlatformGame>();
                        WorkingSearchCollection.Add(s.Single());
                        return;
                    }
                    if (s.Count > 1)
                    {
                        // still multiple entries returned - single match not found - continue
                        WorkingSearchCollection = new List <GDBPlatformGame>();
                        WorkingSearchCollection.AddRange(s);
                    }
                    if (s.Count == 0)
                    {
                        // no matches returned - this should never happen
                    }
                    i++;
                }

                // multiple matches found - run search again from the beginning but remove FIRST substring
                //StartFuzzySearch(searchStr, 100);
                return;

                /*
                 * string[] arr = BuildArray(searchStr);
                 * StartFuzzySearch(BuildSearchString(arr.Take(0).ToArray()), 1);
                 * // multiple matches found - run search again from the beginning but remove last substring
                 * StartFuzzySearch(BuildSearchString(arr.Take(arr.Count() - 1).ToArray()), 1);
                 */
            }
            if (SearchCollection.Count == 0)
            {
                // no matches found - run this method again with the next iterator (slightly weaker tolerance)
                StartFuzzySearch(searchStr, 0);
            }
        }
Esempio n. 4
0
 public static void SavePlatformGamesToDisk()
 {
     var g = GDBPlatformGame.GetGames();
 }
Esempio n. 5
0
        // Update database with all platform games
        public static List <GDBPlatformGame> DatabasePlatformGamesImport(ProgressDialogController controller)
        {
            // create a new object for database import
            List <GDBPlatformGame> gs = new List <GDBPlatformGame>();
            int count    = 0;
            int sysCount = GSystem.GetSystems().Count - 3;

            controller.Minimum = 0;
            controller.Maximum = sysCount;
            foreach (GSystem sys in GSystem.GetSystems())
            {
                // skip systems that are not needed
                if (sys.systemId == 16 || sys.systemId == 17 || sys.systemId == 18)
                {
                    continue;
                }
                count++;
                List <GameSearchResult> merged = new List <GameSearchResult>();
                controller.SetProgress(Convert.ToDouble(count));
                controller.SetMessage("Retrieving Game List for Platform: " + sys.systemName);
                //controller.SetIndeterminate();

                // perform lookups
                foreach (int gid in sys.theGamesDBPlatformId)
                {
                    List <GameSearchResult> result = TheGamesDBAPI.GamesDB.GetPlatformGames(gid).ToList();
                    if (result.Count == 0)
                    {
                        // nothing returned
                        controller.SetMessage("No results returned.\n Maybe an issue connecting to thegamesdb.net...");
                        Task.Delay(2000);
                    }
                    merged.AddRange(result);
                }

                // remove duplicates
                List <GameSearchResult> nodupe = merged.Distinct().ToList();

                // convert to GDBPlatformGame format and add to top list
                foreach (var n in nodupe)
                {
                    GDBPlatformGame gsingle = new GDBPlatformGame();
                    gsingle.id          = n.ID;
                    gsingle.SystemId    = sys.systemId;
                    gsingle.GameTitle   = n.Title;
                    gsingle.ReleaseDate = n.ReleaseDate;

                    gs.Add(gsingle);
                }
            }

            // now we have a complete list of games for our platforms from thegamesdb.net - add or update the database
            controller.SetMessage("Saving to Database...");

            return(gs);



            // first get the current data
            //List<GDBPlatformGame> current = GDBPlatformGame.GetGames();
        }
Esempio n. 6
0
 // refresh platformgames from db
 public void RefreshPlatformGamesFromDb()
 {
     PlatformGames = GDBPlatformGame.GetGames();
 }