public void It_Validates_Correctly()
        {
            NHibernateFileVerifier verifier = new NHibernateFileVerifier();

            bool valid = verifier.IsValidConfigFile(XDocument.Load(ConfigPath));

            Assert.That(valid, Is.True);
        }
Esempio n. 2
0
        private static NHConfigFile GetConfigFromXmlFile(ref string cfgXmlFile, ref bool invalidSchemaFound, string configFilePath)
        {
            NHConfigFile nhConfigFile = null;

            using (var streamReader = new StreamReader(configFilePath))
            {
                XDocument document = XDocument.Load(streamReader);

                if (configFilePath.EndsWith(".cfg.xml", StringComparison.OrdinalIgnoreCase))
                {
                    if (Verifier.IsValidConfigFile(document))
                    {
                        cfgXmlFile                  = configFilePath;
                        nhConfigFile                = new NHConfigFile();
                        nhConfigFile.FilePath       = cfgXmlFile;
                        nhConfigFile.ConfigLocation = NHConfigFile.ConfigLocations.NHConfigFile;
                    }
                    else
                    {
                        var schemas = NHibernateFileVerifier.GetSchemasInFile(document).Select(x => x.Value);
                        var file    = schemas.FirstOrDefault(s => s.Contains("nhibernate-configuration"));
                        if (file != null)
                        {
                            invalidSchemaFound = true;
                            log.WarnFormat("Found an NHibernate Configuration file that uses an unsupported schema");
                        }
                        else
                        {
                            log.WarnFormat("Possible NHibernate configuration file \"{0}\" failed schema validation");
                        }
                    }
                }
                else if (FileHasNHibernateConfig(configFilePath))                 //(FileHasNHibernateConfig(document))
                {
                    cfgXmlFile            = configFilePath;
                    nhConfigFile          = new NHConfigFile();
                    nhConfigFile.FilePath = cfgXmlFile;

                    if (configFilePath.EndsWith("web.config", StringComparison.OrdinalIgnoreCase))
                    {
                        nhConfigFile.ConfigLocation = NHConfigFile.ConfigLocations.WebConfigFile;
                    }
                    else if (configFilePath.EndsWith(".config", StringComparison.OrdinalIgnoreCase))
                    {
                        nhConfigFile.ConfigLocation = NHConfigFile.ConfigLocations.AppConfigFile;
                    }
                    else
                    {
                        nhConfigFile.ConfigLocation = NHConfigFile.ConfigLocations.Other;
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(nhConfigFile);
        }
Esempio n. 3
0
        public EntityLoader(IFileController fileController)
        {
            _fileController = fileController;
            var assembly = typeof(EntityLoader).Assembly;
            var xsdStream = assembly.GetManifestResourceStream("ArchAngel.NHibernateHelper.supported-nhibernate-mapping.xsd");

            mappingSchemaSet = new XmlSchemaSet();
            mappingSchemaSet.Add(XmlSchema.Read(xsdStream, (s, e) => log.Error(e.Message)));

            nhibernateFileVerifier = new NHibernateFileVerifier();
        }