Exemple #1
0
        static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schemaUri == null)
            {
                throw new ArgumentNullException("schemaUri");
            }

            var resolver = new XmlDynamicResolver(callingAssembly);

            if (!schemaUri.IsAbsoluteUri)
            {
                schemaUri = resolver.ResolveUri(null, schemaUri.OriginalString);
            }

            if (processor == null)
            {
                processor = Processors.Xslt.DefaultProcessor;
            }

            ConcurrentDictionary <Uri, SchematronValidator> cache =
                uriCache.GetOrAdd(processor, p => new ConcurrentDictionary <Uri, SchematronValidator>());

            SchematronValidator validator = cache.GetOrAdd(schemaUri, u => {
                using (var schemaSource = (Stream)resolver.GetEntity(schemaUri, null, typeof(Stream))) {
                    IXPathNavigable schemaDoc = processor.ItemFactory.CreateNodeReadOnly(schemaSource, new XmlParsingOptions {
                        BaseUri     = schemaUri,
                        XmlResolver = resolver
                    });

                    return(processor.CreateSchematronValidator(schemaDoc));
                }
            });

            return(new SchematronInvoker(validator, resolver));
        }
Exemple #2
0
        static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }

            if (processor == null)
            {
                processor = Processors.Xslt.DefaultProcessor;
            }

            int hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(schema.CreateNavigator());

            ConcurrentDictionary <int, SchematronValidator> cache =
                inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary <int, SchematronValidator>());

            SchematronValidator validator = cache.GetOrAdd(hashCode, i => processor.CreateSchematronValidator(schema));
            var resolver = new XmlDynamicResolver(callingAssembly);

            return(new SchematronInvoker(validator, resolver));
        }
        static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schema == null) throw new ArgumentNullException("schema");

             if (processor == null) {
            processor = Processors.Xslt.DefaultProcessor;
             }

             int hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(schema.CreateNavigator());

             ConcurrentDictionary<int, SchematronValidator> cache =
            inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary<int, SchematronValidator>());

             SchematronValidator validator = cache.GetOrAdd(hashCode, i => processor.CreateSchematronValidator(schema));
             var resolver = new XmlDynamicResolver(callingAssembly);

             return new SchematronInvoker(validator, resolver);
        }
        static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schemaUri == null) throw new ArgumentNullException("schemaUri");

             var resolver = new XmlDynamicResolver(callingAssembly);

             if (!schemaUri.IsAbsoluteUri) {
            schemaUri = resolver.ResolveUri(null, schemaUri.OriginalString);
             }

             if (processor == null) {
            processor = Processors.Xslt.DefaultProcessor;
             }

             ConcurrentDictionary<Uri, SchematronValidator> cache =
            uriCache.GetOrAdd(processor, p => new ConcurrentDictionary<Uri, SchematronValidator>());

             SchematronValidator validator = cache.GetOrAdd(schemaUri, u => {

            using (var schemaSource = (Stream)resolver.GetEntity(schemaUri, null, typeof(Stream))) {

               IXPathNavigable schemaDoc = processor.ItemFactory.CreateNodeReadOnly(schemaSource, new XmlParsingOptions {
                  BaseUri = schemaUri,
                  XmlResolver = resolver
               });

               return processor.CreateSchematronValidator(schemaDoc);
            }
             });

             return new SchematronInvoker(validator, resolver);
        }