Ejemplo n.º 1
0
        /*static string LastSoundcloudLink = " "; // Stores the last match of a soundcloud link
         *
         * static void HandleSoundcloudMatch(MainForm parent, Match soundcloudMatch)
         * {
         *  LastSoundcloudLink = soundcloudMatch.Groups[1].Value;
         * }*/

        static void HandleScoreMatch(MainForm parent, Match scoreMatch, List <Song> songList)
        {
            Song songInfo;

            Song.Score scoreInfo = new Song.Score(); // Instantiate the new score

            string songTitle = scoreMatch.Groups[2].Value;
            string songScore = scoreMatch.Groups[1].Value;

            if (songList.Exists(song => song.Title == songTitle))                // If the song is already there add the score to it
            {
                var index = songList.FindIndex(song => song.Title == songTitle); // get the song index

                scoreInfo.Value = songScore;

                songInfo = songList[index];   // get the song object
                songInfo.AddScore(scoreInfo); // add the new score

                songList.RemoveAt(index);     // remove it from the old index
                songList.Add(songInfo);       // add it back at the last index to prevent data mismatch
            }
            else // Otherwise create the song and add it to the list
            {
                songInfo        = new Song();
                songInfo.Title  = songTitle;
                songInfo.Artist = " "; // Instantiate the artist field
                //songInfo.SoundcloudLink = LastSoundcloudLink;
                //LastSoundcloudLink = " "; //Reset the latest SC link
                scoreInfo.Value = songScore;
                songInfo.AddScore(scoreInfo);
                songList.Add(songInfo);
                parent.songBox.Items.Add(songInfo);
            }
        }
Ejemplo n.º 2
0
        static void HandleXmlMatch(StreamReader input, Match xmlStart, List <Song> songList)
        {
            string line     = "";
            Song   songInfo = songList.Last();

            Song.Score scoreInfo = songInfo.Scores.Last();
            Match      xmlInfo, nextEntry;
            bool       xmlEnd = false;

            Scoreboard scoreBoard = new Scoreboard();              // Instantiate the scoreboard

            scoreBoard.Global = new Scoreboard.Category();         // Instantiate the global entry
            Scoreboard.Category boardCategory = scoreBoard.Global; // Set the global entry
            Scoreboard.Entry    scoreEntry;

            songInfo.SongID     = xmlStart.Groups[7].Value; // Set the song ID
            songInfo.UserID     = xmlStart.Groups[1].Value; // Set the user
            songInfo.UserRegion = xmlStart.Groups[2].Value; // Set user region
            songInfo.UserEmail  = xmlStart.Groups[3].Value; // Set user email
            scoreInfo.Mode      = xmlStart.Groups[6].Value; // Set song mode

            songInfo.SetCanPost(xmlStart.Groups[4].Value);  // Set if cheats were detected

            while (!xmlEnd)                                 // While we aren't done parsing the scoreboard
            {
                line = input.ReadLine();                    // Read the next line of scoreboard

                nextEntry = Regex.Match(line, "</scoreboard>");

                if (nextEntry.Success) // Check if we need to change entries
                {
                    if (scoreBoard.Regional != null)
                    {
                        xmlEnd = true;                      // We're done parsing
                        songInfo.AddScoreboard(scoreBoard); // Add the scoreboard to the song
                        break;
                    }

                    if (boardCategory == scoreBoard.Global)
                    {
                        scoreBoard.Friends = new Scoreboard.Category(); // Instantiate the friends entry
                        boardCategory      = scoreBoard.Friends;        // Set the friends entry
                    }
                    else
                    {
                        scoreBoard.Regional = new Scoreboard.Category(); // Instantiate the regional entry
                        boardCategory       = scoreBoard.Regional;       // Set the regional entry
                    }

                    for (int i = 0; i < 2; i++)
                    {
                        line = input.ReadLine();
                        //Console.WriteLine(line);
                    }
                }

                xmlInfo = Regex.Match(line, "<ride userid='(.+)' steamid='(.+)' score='(.+)' charid='(.+)' ridetime='(.+)'>(<comment>(.+)</comment>)?<modename>(.+)</modename><username>(.+)</username>");

                scoreEntry = new Scoreboard.Entry();

                scoreEntry.UserID   = xmlInfo.Groups[1].Value;
                scoreEntry.SteamID  = xmlInfo.Groups[2].Value;
                scoreEntry.Score    = xmlInfo.Groups[3].Value;
                scoreEntry.RideTime = xmlInfo.Groups[5].Value;
                scoreEntry.Mode     = xmlInfo.Groups[8].Value;
                scoreEntry.Username = xmlInfo.Groups[9].Value;

                scoreEntry.Comment = " "; // Instantiate the comment field
                if (!String.IsNullOrEmpty(xmlInfo.Groups[7].Value))
                {
                    scoreEntry.Comment = xmlInfo.Groups[7].Value;
                }

                boardCategory.Entries.Add(scoreEntry);
            }
        }