Ejemplo n.º 1
0
        void ParseExtendedOptionsElement(XElement extendedOptionsElement)
        {
            //Get version.
            XAttribute versionAttribute = extendedOptionsElement.Attribute("version");

            if (versionAttribute != null)
            {
                if (TryParseIntegerAttribute(extendedOptionsElement, versionAttribute, 0, SchemeTypes.MaximumExtendedOptionDataVersion, out int value))
                {
                    _schemeGenerator.ExtendedOptionsDataVersion = value;
                }
                else
                {
                    _errorCollection.AddAttributeValueNonNumber(extendedOptionsElement, versionAttribute);
                }
            }
            else
            {
                _errorCollection.AddAttributeNotFound("version", extendedOptionsElement);
            }

            FoundElements foundElements = new FoundElements();

            //Iterate through all elements.
            IEnumerable <XElement> elements = extendedOptionsElement.Elements();

            foreach (XElement element in elements)
            {
                //Handle setting element.
                ExtendedOptionTypes extendedOptionType;
                if (Enum.TryParse <ExtendedOptionTypes>(element.Name.LocalName, out extendedOptionType))
                {
                    if (extendedOptionType != ExtendedOptionTypes.DataVersion && extendedOptionType != ExtendedOptionTypes.Count)
                    {
                        if (!foundElements.Contains(extendedOptionType))
                        {
                            foundElements.Add(extendedOptionType, element);

                            ParseExtendedOptionElement(element, extendedOptionType);
                        }
                        else
                        {
                            _errorCollection.AddRepeatedElement(element, foundElements.Get(extendedOptionType));
                        }
                    }
                    else
                    {
                        _errorCollection.AddInvalidElement(element);
                    }
                }
                //Invalid element.
                else
                {
                    _errorCollection.AddInvalidElement(element);
                }
            }
        }
Ejemplo n.º 2
0
        public bool Parse(out XmlErrorCollection errorCollection, out SchemeGenerator schemeGenerator)
        {
            if (_xDoc == null)
            {
                throw new ArgumentNullException("XML document is not valid.");
            }

            //Store a reference to a new scheme generator and error collector for ease of use later on.
            //This object is not responsible for their lifetime once Parse() has finished!
            _schemeGenerator = new SchemeGenerator();
            _errorCollection = new XmlErrorCollection();

            FoundElements foundElements = new FoundElements();

            //Iterate through all elements.
            IEnumerable <XElement> elements = _xDoc.Elements();

            foreach (XElement element in elements)
            {
                //Handle scheme element.
                if (element.Name.LocalName == ElementTypes.Metascheme.ToString())
                {
                    if (!foundElements.Contains(ElementTypes.Metascheme))
                    {
                        foundElements.Add(ElementTypes.Metascheme, element);
                        ParseMetaschemeElement(element);
                    }
                    else
                    {
                        _errorCollection.AddRepeatedElement(element);
                    }
                }
                //Invalid element.
                else
                {
                    _errorCollection.AddInvalidElement(element);
                }
            }

            //If we didn't get the scheme element, we didn't do anything just now!
            if (!foundElements.Contains(ElementTypes.Metascheme))
            {
                _errorCollection.AddElementNotFound(ElementTypes.Metascheme.ToString());
            }

            //Set the out variables and lose our stored references to them.
            schemeGenerator  = _schemeGenerator;
            _schemeGenerator = null;

            errorCollection  = _errorCollection;
            _errorCollection = null;

            return(errorCollection.Errors.Count == 0);
        }
Ejemplo n.º 3
0
        void ParseWeaponElement(XElement weaponElement, WeaponTypes weaponType)
        {
            FoundElements foundElements = new FoundElements();

            //Iterate through all elements.
            IEnumerable <XElement> elements = weaponElement.Elements();

            foreach (XElement element in elements)
            {
                //Handle weapon setting element.
                WeaponSettings weaponSetting;

                if (Enum.TryParse <WeaponSettings>(element.Name.LocalName, out weaponSetting))
                {
                    if (weaponSetting != WeaponSettings.Count)
                    {
                        if (!foundElements.Contains(weaponSetting))
                        {
                            foundElements.Add(weaponSetting, element);

                            if (SchemeTypes.CanApplyWeaponSetting(weaponType, weaponSetting))
                            {
                                ParseWeaponSettingElement(element, weaponType, weaponSetting);
                            }
                            else
                            {
                                _errorCollection.AddSettingNotApplicableToWeapon(element, weaponType, weaponSetting);
                            }
                        }
                        else
                        {
                            _errorCollection.AddRepeatedElement(element, foundElements.Get(weaponSetting));
                        }
                    }
                    else
                    {
                        _errorCollection.AddInvalidElement(element);
                    }
                }
                //Invalid element.
                else
                {
                    _errorCollection.AddInvalidElement(element);
                }
            }
        }
Ejemplo n.º 4
0
        void ParseWeaponsElement(XElement weaponsElement)
        {
            FoundElements foundElements = new FoundElements();

            //Iterate through all elements.
            IEnumerable <XElement> elements = weaponsElement.Elements();

            foreach (XElement element in elements)
            {
                //Handle weapon element.
                WeaponTypes weapon;

                if (Enum.TryParse <WeaponTypes>(element.Name.LocalName, out weapon))
                {
                    if (weapon != WeaponTypes.Count)
                    {
                        if (!foundElements.Contains(weapon))
                        {
                            foundElements.Add(weapon, element);

                            ParseWeaponElement(element, weapon);
                        }
                        else
                        {
                            _errorCollection.AddRepeatedElement(element, foundElements.Get(weapon));
                        }
                    }
                    else
                    {
                        _errorCollection.AddInvalidElement(element);
                    }
                }
                //Invalid element.
                else
                {
                    _errorCollection.AddInvalidElement(element);
                }
            }
        }
Ejemplo n.º 5
0
        void ParseSettingsElement(XElement settingsElement)
        {
            FoundElements foundElements = new FoundElements();

            //Iterate through all elements.
            IEnumerable <XElement> elements = settingsElement.Elements();

            foreach (XElement element in elements)
            {
                //Handle setting element.
                SettingTypes settingType;

                if (Enum.TryParse <SettingTypes>(element.Name.LocalName, out settingType))
                {
                    if (settingType != SettingTypes.Version && settingType != SettingTypes.BountyMode && settingType != SettingTypes.Count)
                    {
                        if (!foundElements.Contains(settingType))
                        {
                            foundElements.Add(settingType, element);

                            ParseSettingElement(element, settingType);
                        }
                        else
                        {
                            _errorCollection.AddRepeatedElement(element, foundElements.Get(settingType));
                        }
                    }
                    else
                    {
                        _errorCollection.AddInvalidElement(element);
                    }
                }
                //Invalid element.
                else
                {
                    _errorCollection.AddInvalidElement(element);
                }
            }
        }