Exemplo n.º 1
0
        private Player ParsePlayerNode(XmlNode playerNode)
        {
            try
            {
                Player player = new Player();

                if (playerNode.ChildNodes != null)
                {
                    foreach (XmlNode xmlNode in playerNode.ChildNodes)
                    {
                        switch (xmlNode.Name)
                        {
                        case Tags.PlayerID:
                            player.playerIdField = GenericFunctions.ConvertStringToUInt(xmlNode.InnerText);
                            break;

                        case Tags.RoleID:
                            player.roleIdField = (Role)Convert.ToInt32(xmlNode.InnerText);
                            break;

                        case Tags.PlayerName:
                            player.playerNameField = xmlNode.InnerText;
                            break;

                        case Tags.RatingStars:
                            player.ratingStarsField = GenericFunctions.ConvertStringToDecimal(xmlNode.InnerText);
                            break;

                        case Tags.RatingStarsEndOfMatch:
                            player.ratingStarsEndOfMatchField = GenericFunctions.ConvertStringToDecimal(xmlNode.InnerText);
                            break;

                        case Tags.PositionCode:
                            player.positionCodeField = (PositionCode)Convert.ToInt32(xmlNode.InnerText);
                            break;

                        case Tags.Behaviour:
                            player.behaviourField = (Behaviour)Convert.ToInt32(xmlNode.InnerText);
                            break;
                        }
                    }
                }

                return(player);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Reads the xml document and populates internal state with its data.
        /// </summary>
        /// <param name="xmlDocument">Xml document</param>
        public void ReadXml(XmlDocument xmlDocument)
        {
            if (xmlDocument.DocumentElement.ChildNodes != null)
            {
                //Iterates thru each node in HattrickData node
                foreach (XmlNode xmlNode in xmlDocument.DocumentElement.ChildNodes)
                {
                    bool generalNode = false;
                    switch (xmlNode.Name)
                    {
                    case Tags.FileName: {
                        this.fileNameField = xmlNode.InnerText;
                        generalNode        = true;
                        break;
                    }

                    case Tags.Version: {
                        this.versionField = GenericFunctions.ConvertStringToDecimal(xmlNode.InnerText);
                        generalNode       = true;
                        break;
                    }

                    case Tags.UserID: {
                        this.userIdField = GenericFunctions.ConvertStringToUInt(xmlNode.InnerText);
                        generalNode      = true;
                        break;
                    }

                    case Tags.FetchedDate: {
                        this.fetchedDateField = GenericFunctions.ConvertStringToDateTime(xmlNode.InnerText);
                        generalNode           = true;
                        break;
                    }
                    }

                    if (!generalNode)
                    {
                        // Not one of the general nodes,
                        // try reading it as a specific node
                        //ReadSpecificNode(xmlNode);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private Country ParseCountryNode(XmlNode countryNode)
        {
            try
            {
                Country country = new Country();

                foreach (XmlNode xmlNode in countryNode.ChildNodes)
                {
                    switch (xmlNode.Name)
                    {
                    case Tags.CountryID:
                    {
                        country.countryIdField = GenericFunctions.ConvertStringToUInt(xmlNode.InnerText);
                        break;
                    }

                    case Tags.CountryName:
                    {
                        country.countryNameField = xmlNode.InnerText;
                        break;
                    }

                    case Tags.CurrencyName:
                    {
                        country.currencyNameField = xmlNode.InnerText;
                        break;
                    }

                    case Tags.CurrencyRate:
                    {
                        country.currencyRateField = GenericFunctions.ConvertStringToDecimal(xmlNode.InnerText);
                        break;
                    }
                    }
                }

                return(country);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses given XmlDocument and populates a HattrickBase object with data from it.
        /// </summary>
        /// <param name="xmlDocument">XmlDocument to parse</param>
        /// <returns>Populated entity, a HattrickBase (or derived) object</returns>
        public HattrickBase ParseXmlDocument(XmlDocument xmlDocument)
        {
            HattrickBase entity = CreateEntity();

            if (xmlDocument.DocumentElement.ChildNodes != null)
            {
                // Iterates through each node in HattrickData node
                foreach (XmlNode xmlNode in xmlDocument.DocumentElement.ChildNodes)
                {
                    switch (xmlNode.Name)
                    {
                    case Tags.FileName:
                        entity.fileNameField = xmlNode.InnerText;
                        break;

                    case Tags.Version:
                        entity.versionField = GenericFunctions.ConvertStringToDecimal(xmlNode.InnerText);
                        break;

                    case Tags.UserID:
                        entity.userIdField = GenericFunctions.ConvertStringToUInt(xmlNode.InnerText);
                        break;

                    case Tags.FetchedDate:
                        entity.fetchedDateField = GenericFunctions.ConvertStringToDateTime(xmlNode.InnerText);
                        break;

                    default:
                        ParseSpecificNode(xmlNode, entity);
                        break;
                    }
                }
            }

            return(entity);
        }