コード例 #1
0
        private static void OnSelectedEntityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // if any UI event should happen it needs to be specified here
            var ctrl = d as ValidationWindow;

            if (ctrl == null)
            {
                return;
            }
            if (e.Property.Name != "SelectedEntity")
            {
                return;
            }
            var newValue = e.NewValue as IPersistEntity;

            if (newValue == null)
            {
                return;
            }
            if (ctrl.IgnoreNextSelectionChange)
            {
                ctrl.IgnoreNextSelectionChange = false;
                return;
            }
            var validator = new IfcValidator()
            {
                CreateEntityHierarchy = true,
                ValidateLevel         = ValidationFlags.All
            };

            var ret = validator.Validate(newValue);

            ctrl.Report(ret);
        }
コード例 #2
0
        private bool CheckInternal(IModel model, Dictionary <int, string> idMap)
        {
            // check for parser exceptions
            var v = new IfcValidator
            {
                ValidateLevel         = ValidationFlags.All,
                CreateEntityHierarchy = true
            };
            var schemaErrors   = v.Validate(model.Instances);
            var templateErrors = CheckPropertyTemplateTypesAndUnits(model);
            var propErrors     = CheckPropertyUnits(model);

            foreach (var err in
                     schemaErrors
                     .Concat(templateErrors)
                     .Concat(propErrors))
            {
                var identity = err.Item.GetType().Name;
                if (err.Item is IPersistEntity entity)
                {
                    // use XML entity id if available
                    if (idMap.TryGetValue(entity.EntityLabel, out string xmlId))
                    {
                        identity = $"XML entity '{xmlId}' ({entity.ExpressType.ExpressName})";
                    }
                    else
                    {
                        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.Error(msg.ToString());
            }

            return(!schemaErrors.Any());
        }
コード例 #3
0
        private void ValidateModel(object sender, RoutedEventArgs e)
        {
            using (var cursor = new WaitCursor())
            {
                var validator = new IfcValidator()
                {
                    CreateEntityHierarchy = true,
                    ValidateLevel         = ValidationFlags.All
                };

                var ret = validator.Validate(Model.Instances);
                Report(ret);
            }
        }