Exemplo n.º 1
0
        private Node ProcessNode(ParsedNode node, DocumentProcessorState state)
        {
            if (IsIgnoredNode(node))
            {
                return(null);
            }

            NodeProcessor nodeProcessor = FindProcessorForNode(node);

            if (null == nodeProcessor)
            {
                state.AddWarning("Processor not found (sectionType={0}, {1})", node.SectionType, node.AttributeBag.ToString());

                return(null);
            }

            if (!Validate(node, nodeProcessor, state))
            {
                return(null);
            }

            List <Node> children = new List <Node>();

            foreach (ParsedNode childNode in node.Children.Nodes)
            {
                Node child = ProcessNode(childNode, state);

                if (null != child)
                {
                    children.Add(child);
                }
            }

            return(nodeProcessor.Convert(node, children.ToArray()));
        }
Exemplo n.º 2
0
        private bool ValidatePresenceOfProperties(string nodeName, ParsedPropertyBag propertyBag, PropertyDefinition[] propertyDefinitions, string[] ignoredPropertyNames, DocumentProcessorState state)
        {
            IEnumerable <string> providedKeys        = propertyBag.Properties.Select(property => property.Name);
            IEnumerable <string> allDefinedKeys      = propertyDefinitions.Select(property => property.Name);
            IEnumerable <string> requiredDefinedKeys = propertyDefinitions.Where(attribute => attribute.IsRequired).Select(property => property.Name);

            string[] missingPropertiesInMaterial = providedKeys.Except(allDefinedKeys).ToList().Except(ignoredPropertyNames).ToArray();
            string[] missingRequiredProperties   = requiredDefinedKeys.Except(providedKeys).ToArray();

            foreach (string s in missingPropertiesInMaterial)
            {
                state.AddWarning("Unknown property found (property={0}, node={1})", s, nodeName);
            }

            foreach (string s in missingRequiredProperties)
            {
                state.AddError("Required property is missing (property={0}, node={1})", s, nodeName);
            }

            return(missingRequiredProperties.Length == 0);
        }