Beispiel #1
0
        private void AddMissingSkillErrors(ElementAttribute abilitySelector, ElementAttribute skillSelector)
        {
            var abilitySkillIDs =
                doc.Root.Descendants(abilitySelector.Element, true)
                .Attributes(abilitySelector.Attribute, true);

            var skillIDs =
                doc.Root.Descendants(skillSelector.Element, true)
                .Attributes(skillSelector.Attribute, true);

            var missingSkills =
                from abilitySkill in abilitySkillIDs
                join skill in skillIDs
                on abilitySkill.Value equals skill.Value into skillGroup
                from skill in skillGroup.DefaultIfEmpty()
                where skill == null
                select abilitySkill;

            result.Errors.AddRange(
                missingSkills.Select(
                    attribute => CreateError(
                        attribute,
                        "The skill with {0} '{1}' was not found.",
                        skillSelector.Attribute,
                        attribute.Value
                        )
                    )
                );
        }
Beispiel #2
0
        /// <summary>
        /// Finds all attributes of elements where some other attribute has one of a number of values.
        /// </summary>
        /// <param name="ea">The <see cref="ElementAttribute"/> expressing the attributes you want to select</param>
        /// <param name="relatedAttributeSelector">A Func that returns the related attribute.</param>
        /// <param name="relatedAttributeValues">A list of values that the related attribute's value must be amongst.</param>
        /// <returns></returns>
        protected IEnumerable <XAttribute> FindAttributesWhereRelatedAttributeMatchesList(ElementAttribute ea, Func <XAttribute, XAttribute> relatedAttributeSelector, params string[] relatedAttributeValues)
        {
            var matchingAttributes =
                doc.Root.Descendants(ea.Element, true)
                .Attributes(ea.Attribute, true)
                .Where(
                    p =>
            {
                var type = relatedAttributeSelector.Invoke(p);

                if (type != null)
                {
                    var value = type.Value.ToLower();

                    return(relatedAttributeValues.Any(q => q.ToLower() == value));
                }

                return(false);
            }
                    );

            return(matchingAttributes);
        }
        private void AddMissingSkillErrors( ElementAttribute abilitySelector, ElementAttribute skillSelector )
        {
            var abilitySkillIDs =
                doc.Root.Descendants( abilitySelector.Element, true )
                .Attributes( abilitySelector.Attribute, true );

            var skillIDs =
                doc.Root.Descendants( skillSelector.Element, true )
                .Attributes( skillSelector.Attribute, true );

            var missingSkills =
                from abilitySkill in abilitySkillIDs
                join skill in skillIDs
                on abilitySkill.Value equals skill.Value into skillGroup
                from skill in skillGroup.DefaultIfEmpty()
                where skill == null
                select abilitySkill;

            result.Errors.AddRange(
                missingSkills.Select(
                    attribute => CreateError(
                        attribute,
                        "The skill with {0} '{1}' was not found.",
                        skillSelector.Attribute,
                        attribute.Value
                    )
                )
            );
        }
        /// <summary>
        /// Finds all attributes of elements where some other attribute has one of a number of values.
        /// </summary>
        /// <param name="ea">The <see cref="ElementAttribute"/> expressing the attributes you want to select</param>
        /// <param name="relatedAttributeSelector">A Func that returns the related attribute.</param>
        /// <param name="relatedAttributeValues">A list of values that the related attribute's value must be amongst.</param>
        /// <returns></returns>
        protected IEnumerable<XAttribute> FindAttributesWhereRelatedAttributeMatchesList( ElementAttribute ea, Func<XAttribute, XAttribute> relatedAttributeSelector, params string[] relatedAttributeValues )
        {
            var matchingAttributes =
                doc.Root.Descendants( ea.Element, true )
                .Attributes( ea.Attribute, true )
                .Where(
                    p =>
                    {
                        var type = relatedAttributeSelector.Invoke( p );

                        if ( type != null )
                        {
                            var value = type.Value.ToLower();

                            return relatedAttributeValues.Any( q => q.ToLower() == value );
                        }

                        return false;
                    }
                );
            return matchingAttributes;
        }