private static WhereRule GetTypeAssignedRule(EntityDefinition entity, SchemaRules rules) { const string ruleName = "CorrectTypeAssigned"; while (true) { if (entity == null) { return(null); } var rule = entity.WhereRules.FirstOrDefault(r => r.Label == ruleName); if (rule == null && entity.PersistanceName == "IfcElement") { return(null); } if (rule == null) { entity = entity.Supertypes.FirstOrDefault(); continue; } var typeRules = rules.TypeRulesSet.FirstOrDefault(r => r.Type == entity.PersistanceName); return(typeRules != null?typeRules.WhereRules.FirstOrDefault(r => r.Name == ruleName) : null); } }
private static void ProcessSchema(SchemaRules schema, ProjectRootElement project) { if (schema == null) { throw new ArgumentNullException("schema"); } if (project == null) { throw new ArgumentNullException("project"); } foreach (var rules in schema.TypeRulesSet) { var wrTemplate = new WhereError(rules, schema.Schema); ProcessTemplate(wrTemplate, project); var rTemplate = new SchemaRule(rules, schema.Schema); ProcessTemplate(rTemplate, project); } var schErrsTmpl = new SchemaErrors(schema); ProcessTemplate(schErrsTmpl, project); }
public SchemaErrors(SchemaRules schema) { Schema = schema; }
private static void Main() { const string rootDir = @"c:\CODE\IFC4_ADD1\schema"; const string expressFile = @"C:\CODE\XbimGit\XbimExpress\Xbim.ExpressParser\ExpressDefinitions\IFC4_ADD1.txt"; const string schema = "IFC4"; //const string rootDir = @"c:\CODE\IFC2x3_TC1"; //const string expressFile = @"C:\CODE\XbimGit\XbimExpress\Xbim.ExpressParser\ExpressDefinitions\IFC2X3_TC1.txt"; //const string schema = "IFC2X3"; var sRules = new SchemaRules { Schema = schema, TypeRulesSet = new List <TypeRules>() }; var expressData = File.ReadAllText(expressFile); foreach ( var dir in Directory.GetDirectories(rootDir, "*", SearchOption.TopDirectoryOnly)) { var subdir = Path.Combine(dir, "lexical"); if (!Directory.Exists(subdir)) { continue; } foreach ( var file in Directory.GetFiles(subdir, "*.htm", SearchOption.TopDirectoryOnly)) { var data = File.ReadAllText(file); //remove all end lines and multiple spaces data = data.Replace("\r", " ").Replace("\n", " "); data = new Regex("\\s{2,50}", RegexOptions.IgnoreCase).Replace(data, " "); var tName = new Regex("<title>(?<title>.+?)</title>").Match(data).Groups["title"].Value.Trim(); var wrTableExp = new Regex("(?<rules><table class=\"propositions\".+?</table>)", RegexOptions.Singleline); var rules = wrTableExp.Match(data).Groups["rules"].Value; if (string.IsNullOrWhiteSpace(rules)) { wrTableExp = new Regex("Formal Propositions:</a></p>.+?(?<rules><table.+?</table>)", RegexOptions.Singleline | RegexOptions.IgnoreCase); rules = wrTableExp.Match(data).Groups["rules"].Value; } if (string.IsNullOrWhiteSpace(rules)) { continue; } var tRules = new TypeRules { Type = tName, WhereRules = new List <WhereRule>() }; sRules.TypeRulesSet.Add(tRules); var rowsMatches = new Regex("<tr.*?>(?<row>.+?)</tr>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Matches(rules); foreach (Match rowMatch in rowsMatches) { var row = rowMatch.Groups["row"].Value; if (string.IsNullOrWhiteSpace(row)) { continue; } var cellMatches = new Regex("<td.*?>(?<cell>.*?)</td>").Matches(row); if (cellMatches.Count < 2) { continue; } var name = cellMatches.Cast <Match>().First().Groups["cell"].Value.Trim(); var description = cellMatches.Cast <Match>().Last().Groups["cell"].Value.Trim(); //Insert new lines instead of block HTML elements (<ol.*?>|<ul.*?>) description = (new Regex( "(<p.*?>|<div.*?>|<blockquote.*?>|<h.*?>|<dd.*?>|<dt.*?>|<hr.*?>|<pre.*?>)", RegexOptions.IgnoreCase)) .Replace(description, "\n\n"); //keep lists var listExpr = new Regex("<li.*?>", RegexOptions.IgnoreCase); description = listExpr.Replace(description, "\n• "); //replace HTML tags to create simple pure text var tagExp = new Regex("(<.*?>)", RegexOptions.IgnoreCase); description = tagExp.Replace(description, ""); //remove Figure xxx - ... description = (new Regex("Figure\\s*[0-9]+.*", RegexOptions.IgnoreCase)).Replace( description, ""); //remove HISTORY description = (new Regex("HISTORY.*", RegexOptions.IgnoreCase)).Replace(description, ""); description = (new Regex("IFC.*?CHANGE.*")).Replace(description, ""); //replace HTML entities to create simple pure text description = HttpUtility.HtmlDecode(description); ////replace < and > //description = description // .Replace(">", ">") // .Replace("<", "<"); tRules.WhereRules.Add(new WhereRule { Name = name, Description = description.Trim(), Definition = GetDefinition(expressData, tName, name) }); } } } var serializer = new XmlSerializer(typeof(SchemaRules)); using (var w = File.CreateText("..\\..\\..\\..\\XbimExpress\\XbimValidationGenerator\\Data\\" + schema + "_rules.xml")) { serializer.Serialize(w, sRules); w.Close(); } }