コード例 #1
0
        /// <summary>
        /// Converts this match into its XML representation.
        /// </summary>
        /// <param name="writer"></param>
        void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteAttributeString("ID", ID.ToString());
            writer.WriteAttributeString("Location", Location);
            writer.WriteAttributeString("LogLevel", LogLevel.ToString());
            writer.WriteAttributeString("Surface", MatchSurface.ToString());
            writer.WriteAttributeString("Type", Type.ToString());

            //Rules
            writer.WriteStartElement("Rules");
            writer.WriteAttributeString("BestOutOf", BestOutOf.ToString());
            writer.WriteAttributeString("DeuceSuddenDeath", DeuceSuddenDeath.ToString());
            writer.WriteAttributeString("FinalSetIsTiebreak", FinalSetIsTiebreak.ToString());
            writer.WriteAttributeString("FinalSetTieBreakLength", FinalSetTieBreakLength.ToString());
            writer.WriteAttributeString("NumberGamesPerSet", NumberGamesPerSet.ToString());
            writer.WriteAttributeString("TieBreakAtSameScoreOf", TieBreakAtSameScoreOf.ToString());
            writer.WriteAttributeString("TieBreakFinalSet", TieBreakFinalSet.ToString());
            writer.WriteAttributeString("TieBreakLength", TieBreakLength.ToString());
            writer.WriteEndElement();

            //Status
            writer.WriteStartElement("Status");
            writer.WriteAttributeString("NextContestantToServe", NextContestantToServe.ContestantNr.ToString());
            writer.WriteAttributeString("Status", Status.ToString());
            writer.WriteAttributeString("Winner", Winner.ToString());
            writer.WriteEndElement();

            //Contestants
            writer.WriteStartElement("Contestant1");
            Contestant1.WriteXml(writer);
            writer.WriteEndElement();
            writer.WriteStartElement("Contestant2");
            Contestant2.WriteXml(writer);
            writer.WriteEndElement();

            //Duration
            writer.WriteStartElement("Duration");
            Duration.WriteXml(writer);
            writer.WriteEndElement();

            //Statistics
            writer.WriteStartElement("Statistics");
            Statistics.WriteXml(writer);
            writer.WriteEndElement();

            //Sets
            writer.WriteStartElement("Sets");
            foreach (var item in Sets)
            {
                item.WriteXml(writer);
            }
            writer.WriteEndElement();
        }
コード例 #2
0
        /// <summary>
        /// Generates a match object from its XML representation.
        /// </summary>
        /// <param name="reader"></param>
        void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            try
            {
                reader.MoveToContent();

                String _ID       = reader.GetAttribute("ID");
                String _LogLevel = reader.GetAttribute("LogLevel");
                String _Surface  = reader.GetAttribute("Surface");
                String _Type     = reader.GetAttribute("Type");

                ID           = System.Guid.Parse(_ID);
                LogLevel     = (LogLevelEnum)System.Enum.Parse(typeof(LogLevelEnum), _LogLevel);
                Location     = reader.GetAttribute("Location");
                MatchSurface = (Surface)System.Enum.Parse(typeof(Surface), _Surface);
                Type         = (MatchType)System.Enum.Parse(typeof(MatchType), _Type);

                while (!reader.EOF)
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                        case "Rules":
                        {
                            String _BestOutOf              = reader.GetAttribute("BestOutOf");
                            String _DeuceSuddendDeath      = reader.GetAttribute("DeuceSuddenDeath");
                            String _FinalSetIsTiebreak     = reader.GetAttribute("FinalSetIsTiebreak");
                            String _FinalSetTiebreakLength = reader.GetAttribute("FinalSetTieBreakLength");
                            String _NumberGamesPerSet      = reader.GetAttribute("NumberGamesPerSet");
                            String _TieBreakSameScoreOf    = reader.GetAttribute("TieBreakAtSameScoreOf");
                            String _TieBreakFinalSet       = reader.GetAttribute("TieBreakFinalSet");
                            String _TieBreakLength         = reader.GetAttribute("TieBreakLength");

                            BestOutOf              = int.Parse(_BestOutOf);
                            DeuceSuddenDeath       = bool.Parse(_DeuceSuddendDeath);
                            FinalSetIsTiebreak     = bool.Parse(_FinalSetIsTiebreak);
                            FinalSetTieBreakLength = int.Parse(_FinalSetTiebreakLength);
                            NumberGamesPerSet      = int.Parse(_NumberGamesPerSet);
                            TieBreakAtSameScoreOf  = int.Parse(_TieBreakSameScoreOf);
                            TieBreakFinalSet       = bool.Parse(_TieBreakFinalSet);
                            TieBreakLength         = int.Parse(_TieBreakLength);

                            reader.Read();

                            break;
                        }

                        case "Status":
                        {
                            String _Status = reader.GetAttribute("Status");
                            String _NextContestantToServe = reader.GetAttribute("NextContestantToServe");
                            String _Winner = reader.GetAttribute("Winner");

                            NextContestantToServe = (_NextContestantToServe == "1") ? Contestant1 : Contestant2;
                            Winner = int.Parse(_Winner);
                            Status = (MatchStatus)System.Enum.Parse(typeof(MatchStatus), _Status);

                            reader.Read();

                            break;
                        }

                        case "Duration":
                        {
                            Duration.ReadXml(reader);

                            break;
                        }

                        case "Contestant1":
                        {
                            Contestant1.ReadXml(reader);

                            break;
                        }

                        case "Contestant2":
                        {
                            Contestant2.ReadXml(reader);

                            break;
                        }

                        case "Statistics":
                        {
                            Statistics.ReadXml(reader);

                            break;
                        }

                        case "Sets":
                        {
                            while (reader.Read() && !(reader.Name == "Sets" && reader.NodeType == System.Xml.XmlNodeType.EndElement))
                            {
                                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                                {
                                    if (reader.Name == "Set")
                                    {
                                        TennisSet _newSet = new TennisSet(this);
                                        _newSet.ReadXml(reader);

                                        Sets.Add(_newSet);
                                    }
                                }
                            }

                            break;
                        }

                        default:

                            reader.Read();

                            break;
                        }
                    }
                    else
                    {
                        reader.Read();
                    }
                }
            }
            catch (Exception e)
            {
            }
        }