/// <summary>
        /// Creates a new scoreboard session and returns a reference to the caller, so they can add to the session.
        /// </summary>
        /// <returns></returns>
        public MPAiSoundScoreBoardSession NewScoreBoardSession()
        {
            MPAiSoundScoreBoardSession session = new MPAiSoundScoreBoardSession(DateTime.Now);

            sessions.Add(session);
            return(session);
        }
        /// <summary>
        /// Creates a new scoreboard session based on the parameters and returns a reference to the caller, so they can add to the session.
        /// </summary>
        /// <param name="dateAndTime"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public MPAiSoundScoreBoardSession NewScoreBoardSession(DateTime dateAndTime, List <MPAiSoundScoreBoardItem> content)
        {
            MPAiSoundScoreBoardSession session = new MPAiSoundScoreBoardSession(dateAndTime, content);

            sessions.Add(session);
            return(session);
        }
Beispiel #3
0
        /// <summary>
        /// This method loads the scoreboard for the specified user. It does this by reading the html-style file created by SaveScoreboard.
        /// The nested nature of the file is why this method is also deeply nested.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static MPAiSoundScoreBoard LoadScoreboard(MPAiUser user)
        {
            MPAiSoundScoreBoard scoreboard = new MPAiSoundScoreBoard(user);

            if (File.Exists(SoundScoreboardFileAddress(scoreboard.User)))
            {
                using (FileStream fs = new FileStream(SoundScoreboardFileAddress(scoreboard.User), FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string line;
                        line = sr.ReadLine();
                        //MPAiMessageBoxFactory.Show(line + ": <Scoreboard> expected");
                        if (line.Equals("<Scoreboard>"))
                        {
                            //MPAiMessageBoxFactory.Show("Success, entered <Scoreboard>");
                            while (!line.Equals("</Scoreboard>"))
                            {
                                line = sr.ReadLine();
                                while (line.Equals("<Session>"))
                                {
                                    line = sr.ReadLine();
                                    while (!line.Equals("</Session>"))
                                    {
                                        DateTime dateAndTime = new DateTime();;
                                        if (line.Equals("<Date>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</Date>"))
                                            {
                                                dateAndTime = new DateTime();
                                                if (!DateTime.TryParse(line, out dateAndTime))
                                                {
                                                    throw new FileLoadException("Date could not be read");
                                                }
                                                line = sr.ReadLine();
                                            }
                                            line = sr.ReadLine();
                                        }

                                        float overallCorrectnessPercentage = -1;
                                        if (line.Equals("<OverallCorrectnessPercentage>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</OverallCorrectnessPercentage>"))
                                            {
                                                if (!float.TryParse(line, out overallCorrectnessPercentage))
                                                {
                                                    throw new FileLoadException("Overall Correctness Percentage could not be read");
                                                }
                                                line = sr.ReadLine();
                                            }
                                            line = sr.ReadLine();
                                        }

                                        List <MPAiSoundScoreBoardItem> content = new List <MPAiSoundScoreBoardItem>();
                                        if (line.Equals("<Content>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</Content>"))
                                            {
                                                string vowel = "";
                                                float  correctnessPercentage = -1;

                                                if (line.Equals("<Vowel>"))
                                                {
                                                    bool firstline = true;
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</Vowel>"))
                                                    {
                                                        if (firstline)
                                                        {
                                                            firstline = false;
                                                            vowel    += line;
                                                        }
                                                        else
                                                        {
                                                            vowel += String.Format(@"{0}", Environment.NewLine) + line;
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }

                                                if (line.Equals("<CorrectnessPercentage>"))
                                                {
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</CorrectnessPercentage>"))
                                                    {
                                                        if (!float.TryParse(line, out correctnessPercentage))
                                                        {
                                                            throw new FileLoadException("Correctness Percentage could not be read");
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }
                                                content.Add(new MPAiSoundScoreBoardItem(vowel, correctnessPercentage));
                                            }
                                            line = sr.ReadLine();
                                        }
                                        MPAiSoundScoreBoardSession session = scoreboard.NewScoreBoardSession(dateAndTime, content);
                                        session.OverallCorrectnessPercentage = overallCorrectnessPercentage;
                                    }
                                    line = sr.ReadLine();
                                }
                            }
                        }
                    }
                }
            }
            return(scoreboard);
        }
 /// <summary>
 /// Returns an int indicating the ordering of two scoreboard sessions, by date.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static int ComparisionByDate(MPAiSoundScoreBoardSession x, MPAiSoundScoreBoardSession y)
 {
     return(DateTime.Compare(y.DateAndTime, x.DateAndTime));
 }