Ejemplo n.º 1
0
        private bool AddOtherContent(XmlReader reader)
        {
            int lineNumber;
            int linePosition;

            GetPositionInfo(reader, out lineNumber, out linePosition);

            MetadataProperty property;

            if (reader.NodeType
                == XmlNodeType.Element)
            {
                if (_schema.SchemaVersion == XmlConstants.EdmVersionForV1
                    ||
                    _schema.SchemaVersion == XmlConstants.EdmVersionForV1_1)
                {
                    // skip this element
                    // we don't support element annotations in v1 and v1.1
                    return(true);
                }

                // in V1 and V1.1 the codegen can only appear as the attribute annotation and we want to maintain
                // the same behavior for V2, thus we throw if we encounter CodeGen namespace
                // in structural annotation in V2 and furthur version
                if (_schema.SchemaVersion >= XmlConstants.EdmVersionForV2 &&
                    reader.NamespaceURI == XmlConstants.CodeGenerationSchemaNamespace)
                {
                    Debug.Assert(
                        XmlConstants.SchemaVersionLatest == XmlConstants.EdmVersionForV3,
                        "Please add checking for the latest namespace");

                    AddError(
                        ErrorCode.NoCodeGenNamespaceInStructuralAnnotation, EdmSchemaErrorSeverity.Error, lineNumber, linePosition,
                        Strings.NoCodeGenNamespaceInStructuralAnnotation(XmlConstants.CodeGenerationSchemaNamespace));
                    return(true);
                }

                Debug.Assert(
                    !Schema.IsParseableXmlNamespace(reader.NamespaceURI, false),
                    "Structural annotation cannot use any edm reserved namespaces");

                // using this subtree aproach because when I call
                // reader.ReadOuterXml() it positions me at the Node beyond
                // the end of the node I am starting on
                // which doesn't work with the parsing logic
                using (var subtree = reader.ReadSubtree())
                {
                    subtree.Read();
                    using (var stringReader = new StringReader(subtree.ReadOuterXml()))
                    {
                        var element = XElement.Load(stringReader);

                        property = CreateMetadataPropertyFromOtherNamespaceXmlArtifact(
                            element.Name.NamespaceName, element.Name.LocalName, element);
                    }
                }
            }
            else
            {
                if (reader.NamespaceURI == XmlNamespaceNamespace)
                {
                    // we don't bring in namespace definitions
                    return(true);
                }

                Debug.Assert(reader.NodeType == XmlNodeType.Attribute, "called an attribute function when not on an attribute");
                property = CreateMetadataPropertyFromOtherNamespaceXmlArtifact(reader.NamespaceURI, reader.LocalName, reader.Value);
            }

            if (!OtherContent.Exists(mp => mp.Identity == property.Identity))
            {
                OtherContent.Add(property);
            }
            else
            {
                AddError(
                    ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, lineNumber, linePosition,
                    Strings.DuplicateAnnotation(property.Identity, FQName));
            }
            return(false);
        }