Пример #1
0
        private bool Verify(TagNode parent, TagNode tag, SchemaNode schema)
        {
            if (tag == null)
            {
                return(OnMissingTag(new TagEventArgs(schema.Name)));
            }

            SchemaNodeScaler scaler = schema as SchemaNodeScaler;

            if (scaler != null)
            {
                return(VerifyScaler(tag, scaler));
            }

            SchemaNodeString str = schema as SchemaNodeString;

            if (str != null)
            {
                return(VerifyString(tag, str));
            }

            SchemaNodeArray array = schema as SchemaNodeArray;

            if (array != null)
            {
                return(VerifyArray(tag, array));
            }

            SchemaNodeIntArray intarray = schema as SchemaNodeIntArray;

            if (intarray != null)
            {
                return(VerifyIntArray(tag, intarray));
            }

            SchemaNodeList list = schema as SchemaNodeList;

            if (list != null)
            {
                return(VerifyList(tag, list));
            }

            SchemaNodeCompound compound = schema as SchemaNodeCompound;

            if (compound != null)
            {
                return(VerifyCompound(tag, compound));
            }

            return(OnInvalidTagType(new TagEventArgs(schema.Name, tag)));
        }
Пример #2
0
        /// <summary>
        /// Copies all the elements of this <see cref="SchemaNodeCompound"/> into <paramref name="tree"/>.
        /// </summary>
        /// <param name="tree">The destination <see cref="SchemaNodeCompound"/> to copy <see cref="SchemaNode"/> elements into.</param>
        /// <returns>A reference to <paramref name="tree"/>.</returns>
        public SchemaNodeCompound MergeInto(SchemaNodeCompound tree)
        {
            foreach (SchemaNode node in _subnodes)
            {
                SchemaNode f = tree._subnodes.Find(n => n.Name == node.Name);
                if (f != null)
                {
                    continue;
                }
                tree.Add(node);
            }

            return(tree);
        }
Пример #3
0
        /// <summary>
        /// Constructs a new <see cref="SchemaNodeCompound"/> with additional options.
        /// </summary>
        /// <param name="name">The name of the corresponding <see cref="TagNodeCompound"/>.</param>
        /// <param name="subschema">A <see cref="SchemaNodeCompound"/> representing a schema to verify against the corresponding <see cref="TagNodeCompound"/>.</param>
        /// <param name="options">One or more option flags modifying the processing of this node.</param>
        public SchemaNodeCompound(string name, SchemaNode subschema, SchemaOptions options)
            : base(name, options)
        {
            _subnodes = new List <SchemaNode>();

            SchemaNodeCompound schema = subschema as SchemaNodeCompound;

            if (schema == null)
            {
                return;
            }

            foreach (SchemaNode node in schema._subnodes)
            {
                _subnodes.Add(node);
            }
        }
Пример #4
0
        private bool VerifyCompound(TagNode tag, SchemaNodeCompound schema)
        {
            TagNodeCompound ctag = tag as TagNodeCompound;

            if (ctag == null)
            {
                if (!OnInvalidTagType(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }

            bool pass = true;

            foreach (SchemaNode node in schema)
            {
                TagNode value;
                ctag.TryGetValue(node.Name, out value);

                if (value == null)
                {
                    if ((node.Options & SchemaOptions.CREATE_ON_MISSING) == SchemaOptions.CREATE_ON_MISSING)
                    {
                        _scratch[node.Name] = node.BuildDefaultTree();
                        continue;
                    }
                    else if ((node.Options & SchemaOptions.OPTIONAL) == SchemaOptions.OPTIONAL)
                    {
                        continue;
                    }
                }

                pass = Verify(tag, value, node) && pass;
            }

            foreach (KeyValuePair <string, TagNode> item in _scratch)
            {
                ctag[item.Key] = item.Value;
            }

            _scratch.Clear();

            return(pass);
        }