Exemplo n.º 1
0
        public bool Check(IModel model)
        {
            ILogger log = XbimLogging.CreateLogger <IfcValidator>();

            // check for parser exceptions
            var v = new Validator
            {
                ValidateLevel         = ValidationFlags.All,
                CreateEntityHierarchy = true
            };

            SchemaErrors   = v.Validate(model.Instances).ToList();
            TemplateErrors = CheckPropertyTemplateTypesAndUnits(model).ToList();
            PropertyErrors = CheckPropertyUnits(model).ToList();

            foreach (var err in
                     SchemaErrors
                     .Concat(TemplateErrors)
                     .Concat(PropertyErrors))
            {
                var identity = err.Item.GetType().Name;
                if (err.Item is IPersistEntity entity)
                {
                    identity = $"#{entity.EntityLabel}={entity.ExpressType.ExpressName}";
                }
                var msg = new StringBuilder();
                msg.AppendLine($"{identity} is invalid.");
                var details = new Stack <ValidationResult>(err.Details);
                while (details.Any())
                {
                    var detail = details.Pop();
                    foreach (var d in detail.Details)
                    {
                        details.Push(d);
                    }

                    var report = detail.Message;
                    if (string.IsNullOrWhiteSpace(report))
                    {
                        report = detail.Report();
                    }
                    msg.AppendLine("    " + report);

                    if (detail.IssueType == ValidationFlags.EntityWhereClauses || detail.IssueType == ValidationFlags.TypeWhereClauses)
                    {
                        var source = detail.IssueSource.Split('.')[0].ToLower();
                        msg.AppendLine($"http://www.buildingsmart-tech.org/ifc/IFC4/Add2/html/link/{source}.htm");
                    }
                }
                log.LogError(msg.ToString());
            }

            return(!SchemaErrors.Any() && !TemplateErrors.Any() && !PropertyErrors.Any());
        }