コード例 #1
0
        /// <summary>
        /// Processes the SQL map element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessSqlMapElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_URI))
            {
                string    uri      = element.Attributes[ConfigConstants.ATTRIBUTE_URI];
                IResource resource = ResourceLoaderRegistry.GetResource(uri);

                Contract.Assert.That(resource, Is.Not.Null).When("process Resource in ConfigurationInterpreter");

                using (resource)
                {
                    IConfiguration setting = configurationStore.Settings[ConfigConstants.ATTRIBUTE_VALIDATE_SQLMAP];
                    if (setting != null)
                    {
                        bool mustValidate = false;
                        Boolean.TryParse(setting.Value, out mustValidate);
                        if (mustValidate)
                        {
                            XmlDocument document = new XmlDocument();
                            document.Load(resource.Stream);
                            SchemaValidator.Validate(document.ChildNodes[1], "SqlMap.xsd");
                        }
                    }

                    resource.Stream.Position = 0;
                    using (XmlTextReader reader = new XmlTextReader(resource.Stream))
                    {
                        using (XmlMappingProcessor processor = new XmlMappingProcessor())
                        {
                            processor.Process(reader, configurationStore);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Processes the SQL map element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessSqlMapElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_URI))
            {
                string uri = element.Attributes[ConfigConstants.ATTRIBUTE_URI];
                IResource resource = ResourceLoaderRegistry.GetResource(uri);

                Contract.Assert.That(resource, Is.Not.Null).When("process Resource in ConfigurationInterpreter");

                using (resource)
                {
                    IConfiguration setting = configurationStore.Settings[ConfigConstants.ATTRIBUTE_VALIDATE_SQLMAP];
                    if (setting != null)
                    {
                        bool mustValidate = false;
                        Boolean.TryParse(setting.Value, out mustValidate);
                        if (mustValidate)
                        {
                            XmlDocument document = new XmlDocument();
                            document.Load(resource.Stream);
                            SchemaValidator.Validate(document.ChildNodes[1], "SqlMap.xsd");
                        }
                    }

                    resource.Stream.Position = 0; 
                    using (XmlTextReader reader = new XmlTextReader(resource.Stream))
                    {
                        using (XmlMappingProcessor processor = new XmlMappingProcessor())
                        {
                            processor.Process(reader, configurationStore);
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Adds an XML sql map configuration item.
        /// </summary>
        /// <param name="uri">A URI to XML data.</param>
        /// <param name="validate">Validate the XML sqlMap file using SqlMap.xsd</param>
        /// <example>
        /// <code>
        /// &lt;sqlMaps&gt;
        ///  &lt;sqlMap uri="file://../../Maps/Account.xml"/&gt;
        /// &lt;/sqlMaps&gt;
        /// </code>
        /// </example>
        public void AddSqlMap(string uri, bool validate)
        {
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            using (resource)
            {
                if (validate)
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(resource.Stream);
                    SchemaValidator.Validate(document.ChildNodes[1], "SqlMap.xsd");
                }

                resource.Stream.Position = 0;
                using (XmlTextReader reader = new XmlTextReader(resource.Stream))
                {
                    using (XmlMappingProcessor processor = new XmlMappingProcessor())
                    {
                        processor.Process(reader, configurationStore);
                    }
                }
            }
        }