Exemple #1
0
 public static Type GetEnvelopeMap(this ISchemaMetadata schemaMetadata)
 {
     if (schemaMetadata == null)
     {
         throw new ArgumentNullException(nameof(schemaMetadata));
     }
     return(schemaMetadata.Annotations.Find <EnvelopeMapAnnotation>().EnvelopeMapType);
 }
Exemple #2
0
 internal static ISchemaAnnotationCollection Create(ISchemaMetadata schemaMetadata)
 {
     if (schemaMetadata == null)
     {
         throw new ArgumentNullException(nameof(schemaMetadata));
     }
     return(new SchemaAnnotationCollection(() => SchemaAnnotationReader.Create(schemaMetadata)));
 }
Exemple #3
0
 public static PropertyExtractorCollection GetPropertyExtractors(this ISchemaMetadata schemaMetadata)
 {
     if (schemaMetadata == null)
     {
         throw new ArgumentNullException(nameof(schemaMetadata));
     }
     return(schemaMetadata.Annotations.Find <PropertyExtractorAnnotation>().Extractors);
 }
 internal static ISchemaAnnotationReader Create(ISchemaMetadata schemaMetadata)
 {
     if (schemaMetadata == null)
     {
         throw new ArgumentNullException(nameof(schemaMetadata));
     }
     return(schemaMetadata is Schema.SchemaMetadata.RootlessSchemaMetadata or Schema.SchemaMetadata.UnknownSchemaMetadata ||
            schemaMetadata.Type.Assembly.FullName.StartsWith("Microsoft.", StringComparison.Ordinal)
                                 ? new EmptySchemaAnnotationReader(schemaMetadata)
                                 : new SchemaAnnotationReader(schemaMetadata));
 }
 public static ISchemaAnnotations Create(ISchemaMetadata schemaMetadata)
 {
     if (schemaMetadata == null)
     {
         throw new ArgumentNullException(nameof(schemaMetadata));
     }
     if (schemaMetadata.Type.Assembly.FullName.StartsWith("Microsoft.", StringComparison.Ordinal) ||
         !schemaMetadata.HasAnnotations())
     {
         return(Empty);
     }
     return(new SchemaAnnotations(schemaMetadata));
 }
        private static IEnumerable <XElement> SelectAnnotations(ISchemaMetadata metadata)
        {
            var schema = (SchemaBase)Activator.CreateInstance(metadata.Type);

            var xdoc             = XDocument.Load(new StringReader(schema.XmlContent));
            var namespaceManager = new XmlNamespaceManager(new NameTable());

            namespaceManager.AddNamespace("xs", XmlSchema.Namespace);
            namespaceManager.AddNamespace("san", NAMESPACE);
            var annotations = xdoc.XPathSelectElements(
                string.Format("/*/xs:element[@name='{0}']/xs:annotation//san:*", metadata.RootElementName),
                namespaceManager);

            return(annotations);
        }
Exemple #7
0
        internal static IEnumerable <XElement> GetAnnotations(this ISchemaMetadata schemaMetadata)
        {
            if (schemaMetadata == null)
            {
                throw new ArgumentNullException(nameof(schemaMetadata));
            }
            var schema = (SchemaBase)Activator.CreateInstance(schemaMetadata.Type);

            using (var stringReader = new StringReader(schema.XmlContent))
            {
                var document         = XDocument.Load(stringReader);
                var namespaceManager = new XmlNamespaceManager(new NameTable());
                namespaceManager.AddNamespace("xs", XmlSchema.Namespace);
                namespaceManager.AddNamespace("san", SchemaAnnotations.NAMESPACE);
                var annotationXmlElements = document.XPathSelectElements(
                    $"/*/xs:element[@name='{schemaMetadata.RootElementName}']/xs:annotation/xs:appinfo/san:*",
                    namespaceManager);
                return(annotationXmlElements);
            }
        }
        public static ISchemaAnnotations Create(ISchemaMetadata metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            if (metadata.Type.Assembly.FullName.StartsWith("Microsoft.", StringComparison.Ordinal))
            {
                return(Empty);
            }

            var annotations = SelectAnnotations(metadata);

            if (!annotations.Any())
            {
                return(Empty);
            }

            var envelopeMap = metadata.IsEnvelopeSchema
                                ? annotations
                              .SingleOrDefault(e => e.Name.LocalName == "EnvelopeMapSpecName")
                              .IfNotNull(e => e.Value)
                              .IfNotNull(n => Type.GetType(n, true))
                                : null;

            var extractors = annotations
                             .SingleOrDefault(e => e.Name.LocalName == "Properties")
                             .IfNotNull(
                p => {
                var extractorCollection = new PropertyExtractorCollection();
                extractorCollection.ReadXml(p.CreateReader());
                return(extractorCollection);
            })
                             ?? PropertyExtractorCollection.Empty;

            return(new SchemaAnnotations {
                EnvelopingMap = envelopeMap,
                Extractors = extractors
            });
        }
 private SchemaAnnotationReader(ISchemaMetadata schemaMetadata)
 {
     SchemaMetadata = schemaMetadata;
 }
 internal EmptySchemaAnnotationReader(ISchemaMetadata schemaMetadata)
 {
     SchemaMetadata = schemaMetadata;
 }
 private SchemaAnnotations(ISchemaMetadata metadata)
 {
     _metadata = metadata;
 }
Exemple #12
0
 public static bool HasAnnotations(this ISchemaMetadata schemaMetadata)
 {
     return(schemaMetadata.GetAnnotations().Any());
 }