Beispiel #1
0
        /// <summary>
        /// Initializes a new object from the the <see cref="RatingBox"/> class.
        /// </summary>
        /// <param name="typeName">The name of the <see cref="RatingBox"/> instance in the workflow.</param>
        /// <param name="elementName">The name of the element in the workflow.</param>
        /// <param name="schema">The schema xml that describe the IntBox type.</param>
        public RatingBox(String typeName, String elementName, XmlSchemaSet schema)
        {
            this.TypeName  = typeName;
            this.FieldName = elementName;
            this.Schema    = schema;

            List <String> values = new List <string>();

            //Instatiate all the possible values
            XmlSchemaComplexType             myType = schema.GlobalTypes[new XmlQualifiedName(typeName)] as XmlSchemaComplexType;
            XmlSchemaComplexContentExtension ext    = myType.ContentModel.Content as XmlSchemaComplexContentExtension;
            XmlSchemaSequence seq = ext.Particle as XmlSchemaSequence;

            foreach (XmlSchemaObject subf in seq.Items)
            {
                XmlSchemaElement               element     = subf as XmlSchemaElement;
                XmlSchemaSimpleType            type        = element.SchemaType as XmlSchemaSimpleType;
                XmlSchemaSimpleTypeRestriction restriction = type.Content as XmlSchemaSimpleTypeRestriction;
                XmlSchemaMinInclusiveFacet     min         = restriction.Facets[0] as XmlSchemaMinInclusiveFacet;
                XmlSchemaMaxInclusiveFacet     max         = restriction.Facets[1] as XmlSchemaMaxInclusiveFacet;
                int minValue = Int32.Parse(min.Value);
                int maxValue = Int32.Parse(max.Value);

                for (int i = minValue; i <= maxValue; i++)
                {
                    values.Add(i.ToString());
                }

                Values = values.ToArray();

                selectedIndex = 0;
            }
        }
        internal XSMinInclusiveFacet(XmlSchemaMinInclusiveFacet minInclusiveFacet)
        {
            _facet = minInclusiveFacet;
            _value = ValueFactory.Create(_facet.Value);

            if (_facet.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }
        }
        public override XmlSchemaSimpleType GetSimpleType(string attributeDataType)
        {
            var retVal      = base.GetSimpleType(attributeDataType);
            var restriction = (XmlSchemaSimpleTypeRestriction)retVal.Content;

            var minFacet = new XmlSchemaMinInclusiveFacet {
                Value = TimeSpan.Zero.ToString()
            };

            restriction.Facets.Add(minFacet);

            return(retVal);
        }
Beispiel #4
0
        public bool MinimumDateConstraint(string minDate)
        {
            DateTime min;

            if (!DateTime.TryParse(minDate, out min))
            {
                return(false);
            }
            else
            {
                XmlSchemaMinInclusiveFacet facet = new XmlSchemaMinInclusiveFacet();
                facet.Value = min.ToString("u").Substring(0, 10);
                Common.addFacet(facet, Common.getElementFromSchema(baseSchema));
                return(true);
            }
        }
Beispiel #5
0
        public bool AddGreaterThanConstraint(string minVal)
        {
            int min;

            if (int.TryParse(minVal, out min))
            {
                XmlSchemaMinInclusiveFacet facet = new XmlSchemaMinInclusiveFacet();
                facet.Value = min.ToString();
                Common.addFacet(facet, Common.getElementFromSchema(baseSchema));
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
        public Rating()
        {
            baseSchema = new XmlSchema();

            //<xs:complexType name="RatingN"> first time is empty
            XmlSchemaComplexType newType = new XmlSchemaComplexType();

            newType.Name = "";
            baseSchema.Items.Add(newType);

            //<xs:complexContent>
            XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();

            newType.ContentModel = complexContent;

            //<xs:extension base="Rating">
            XmlSchemaComplexContentExtension complexContentExtension = new XmlSchemaComplexContentExtension();

            complexContent.Content = complexContentExtension;
            complexContentExtension.BaseTypeName = new XmlQualifiedName("Rating");

            //<xs:sequence>
            XmlSchemaSequence seq = new XmlSchemaSequence();

            complexContentExtension.Particle = seq;

            //<xs:element name="Value" type="xs:integer"/>
            XmlSchemaElement elem = new XmlSchemaElement();

            seq.Items.Add(elem);
            elem.Name           = "Value";
            elem.SchemaTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");

            //to Check
            XmlSchemaMinInclusiveFacet minFacet = new XmlSchemaMinInclusiveFacet();

            minFacet.Value = "0";
            Common.addFacet(minFacet, Common.getElementFromSchema(baseSchema));

            maxRateFacet.Value = "5";
            Common.addFacet(maxRateFacet, Common.getElementFromSchema(baseSchema));
        }
Beispiel #7
0
        public override XmlSchemaSimpleType GetSimpleType(string attributeDataType)
        {
            var retVal      = base.GetSimpleType(attributeDataType);
            var restriction = (XmlSchemaSimpleTypeRestriction)retVal.Content;

            var iva = (IntegerValidatorAttribute)Attribute;

            var minFacet = new XmlSchemaMinInclusiveFacet {
                Value = iva.MinValue.ToString()
            };

            restriction.Facets.Add(minFacet);

            var maxFacet = new XmlSchemaMaxInclusiveFacet {
                Value = iva.MaxValue.ToString()
            };

            restriction.Facets.Add(maxFacet);

            return(retVal);
        }
Beispiel #8
0
        public bool RangeDateConstraint(string minDate, string maxDate)
        {
            DateTime max, min;

            if (!DateTime.TryParse(maxDate, out max) || !DateTime.TryParse(minDate, out min))
            {
                return(false);
            }
            if (min.CompareTo(max) > 0)
            {
                return(false);
            }
            XmlSchemaMinInclusiveFacet facmin = new XmlSchemaMinInclusiveFacet();

            facmin.Value = min.ToString("u").Substring(0, 10);
            XmlSchemaMaxInclusiveFacet facmax = new XmlSchemaMaxInclusiveFacet();

            facmax.Value = max.ToString("u").Substring(0, 10);
            Common.addFacet(facmax, Common.getElementFromSchema(baseSchema));
            Common.addFacet(facmin, Common.getElementFromSchema(baseSchema));
            return(true);
        }
Beispiel #9
0
        public bool AddIntervalConstraint(string minVal, string maxVal)
        {
            int min, max;

            if (!int.TryParse(minVal, out min) ||
                !int.TryParse(maxVal, out max) ||
                min > max)
            {
                return(false);
            }

            //max facet
            XmlSchemaMaxInclusiveFacet maxFacet = new XmlSchemaMaxInclusiveFacet();

            maxFacet.Value = max.ToString();
            Common.addFacet(maxFacet, Common.getElementFromSchema(baseSchema));
            //min facet
            XmlSchemaMinInclusiveFacet minFacet = new XmlSchemaMinInclusiveFacet();

            minFacet.Value = min.ToString();
            Common.addFacet(minFacet, Common.getElementFromSchema(baseSchema));

            return(true);
        }
Beispiel #10
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

        // <xs:simpleType name="LotteryNumber">
        XmlSchemaSimpleType LotteryNumberType = new XmlSchemaSimpleType();

        LotteryNumberType.Name = "LotteryNumber";

        // <xs:restriction base="xs:int">
        XmlSchemaSimpleTypeRestriction LotteryNumberRestriction = new XmlSchemaSimpleTypeRestriction();

        LotteryNumberRestriction.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");

        // <xs:minInclusive value="1"/>
        XmlSchemaMinInclusiveFacet minInclusive = new XmlSchemaMinInclusiveFacet();

        minInclusive.Value = "1";
        LotteryNumberRestriction.Facets.Add(minInclusive);

        // <xs:maxInclusive value="99"/>
        XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();

        maxInclusive.Value = "99";
        LotteryNumberRestriction.Facets.Add(maxInclusive);

        LotteryNumberType.Content = LotteryNumberRestriction;
        schema.Items.Add(LotteryNumberType);

        // <xs:simpleType name="LotteryNumberList">
        XmlSchemaSimpleType LotteryNumberListType = new XmlSchemaSimpleType();

        LotteryNumberListType.Name = "LotteryNumberList";

        // <xs:list itemType="LotteryNumber"/>
        XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();

        list.ItemTypeName             = new XmlQualifiedName("LotteryNumber", "");
        LotteryNumberListType.Content = list;

        schema.Items.Add(LotteryNumberListType);

        // <xs:simpleType name="LotteryNumbers">
        XmlSchemaSimpleType LotteryNumbersType = new XmlSchemaSimpleType();

        LotteryNumbersType.Name = "LotteryNumbers";

        // <xs:restriction base="LotteryNumberList">
        XmlSchemaSimpleTypeRestriction LotteryNumbersRestriction = new XmlSchemaSimpleTypeRestriction();

        LotteryNumbersRestriction.BaseTypeName = new XmlQualifiedName("LotteryNumberList", "");

        // <xs:length value="5"/>
        XmlSchemaLengthFacet length = new XmlSchemaLengthFacet();

        length.Value = "5";
        LotteryNumbersRestriction.Facets.Add(length);

        LotteryNumbersType.Content = LotteryNumbersRestriction;

        schema.Items.Add(LotteryNumbersType);

        // <xs:element name="TodaysLottery" type="LotteryNumbers">
        XmlSchemaElement TodaysLottery = new XmlSchemaElement();

        TodaysLottery.Name           = "TodaysLottery";
        TodaysLottery.SchemaTypeName = new XmlQualifiedName("LotteryNumbers", "");

        schema.Items.Add(TodaysLottery);

        XmlSchemaSet schemaSet = new XmlSchemaSet();

        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }
        private XmlSchemaSimpleType SetSchemaFacets(XmlSchemaSimpleType simpleType, List <MessagePart> MessageParts)
        {
            Debug.Assert(!(simpleType.Content is XmlSchemaSimpleTypeUnion), "Cannot apply restrictions to unions.");
            Debug.Assert(!(simpleType.Content is XmlSchemaSimpleTypeList), "Cannot apply restrictions to lists.");

            XmlSchemaSimpleTypeRestriction oldRestriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;
            XmlSchemaSimpleTypeRestriction restriction    = new XmlSchemaSimpleTypeRestriction();

            //preserve existing facets
            if (oldRestriction != null)
            {
                foreach (XmlSchemaObject restrictionFacet in oldRestriction.Facets)
                {
                    if (!(restrictionFacet is XmlSchemaMaxLengthFacet) && !(restrictionFacet is XmlSchemaMinLengthFacet))
                    {
                        restriction.Facets.Add(restrictionFacet);
                    }
                }
            }

            foreach (MessagePart messagePart in MessageParts)
            {
                StringLengthMessagePart stringLengthMessagePart = messagePart as StringLengthMessagePart;
                RegexMessagePart        regexMessagePart        = messagePart as RegexMessagePart;
                RangeMessagePart        rangeMessagePart        = messagePart as RangeMessagePart;

                if (stringLengthMessagePart != null)
                {
                    if (stringLengthMessagePart.MaxLength > 0)
                    {
                        XmlSchemaMaxLengthFacet maxLengthFacet = new XmlSchemaMaxLengthFacet();
                        maxLengthFacet.Value = stringLengthMessagePart.MaxLength.ToString();
                        restriction.Facets.Add(maxLengthFacet);
                    }
                    if (stringLengthMessagePart.MinLength > 0)
                    {
                        XmlSchemaMinLengthFacet minLengthFacet = new XmlSchemaMinLengthFacet();
                        minLengthFacet.Value = stringLengthMessagePart.MinLength.ToString();
                        restriction.Facets.Add(minLengthFacet);
                    }
                }

                if (regexMessagePart != null)
                {
                    XmlSchemaPatternFacet patternFacet = new XmlSchemaPatternFacet();
                    patternFacet.Value = regexMessagePart.Regex;
                    restriction.Facets.Add(patternFacet);
                }

                if (rangeMessagePart != null)
                {
                    XmlSchemaMinInclusiveFacet minInclusiveFacet = new XmlSchemaMinInclusiveFacet();
                    minInclusiveFacet.Value = rangeMessagePart.Min.ToString();
                    restriction.Facets.Add(minInclusiveFacet);

                    XmlSchemaMaxInclusiveFacet maxInclusiveFacet = new XmlSchemaMaxInclusiveFacet();
                    maxInclusiveFacet.Value = rangeMessagePart.Max.ToString();
                    restriction.Facets.Add(maxInclusiveFacet);
                }
            }

            restriction.BaseTypeName = simpleType.QualifiedName;

            XmlSchemaSimpleType newType = new XmlSchemaSimpleType();

            newType.Content = restriction;

            return(newType);
        }
        private static XmlSchemaSimpleTypeRestriction ExtractNumberAndIntegerFacets(JsonSchema jSchema, TypeKeyword type)
        {
            XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction();
            double? minValue = GetterExtensions.Minimum(jSchema);
            double? minExclusiveValue = GetterExtensions.ExclusiveMinimum(jSchema);

            if (type.Value == JsonSchemaType.Number)
            {
                content.BaseTypeName = new XmlQualifiedName("decimal", XML_SCHEMA_NS);
            }
            else if (type.Value == JsonSchemaType.Integer)
            {
                if (minValue != null && minValue == 0.0)
                {
                    content.BaseTypeName = new XmlQualifiedName("positiveInteger", XML_SCHEMA_NS);
                }
                else
                {
                    content.BaseTypeName = new XmlQualifiedName("integer", XML_SCHEMA_NS);
                }
            }

            if (minValue != null || minExclusiveValue != null)
            {
                if (minValue != null)
                {
                    XmlSchemaMinInclusiveFacet facet = new XmlSchemaMinInclusiveFacet
                    {
                        Value = FormatDouble((double)minValue),
                    };
                    content.Facets.Add(facet);
                }
                else
                {
                    XmlSchemaMinExclusiveFacet facet = new XmlSchemaMinExclusiveFacet
                    {
                        Value = FormatDouble((double)minExclusiveValue),
                    };
                    content.Facets.Add(facet);
                }
            }

            double? maxValue = GetterExtensions.Maximum(jSchema);
            double? maxExclusiveValue = GetterExtensions.ExclusiveMaximum(jSchema);

            if (maxValue != null || maxExclusiveValue != null)
            {
                if (maxValue != null)
                {
                    XmlSchemaMaxInclusiveFacet maxInclusiveFacet = new XmlSchemaMaxInclusiveFacet
                    {
                        Value = FormatDouble((double)maxValue),
                    };
                    content.Facets.Add(maxInclusiveFacet);
                }
                else
                {
                    XmlSchemaMaxExclusiveFacet maxExclusiveFacet = new XmlSchemaMaxExclusiveFacet
                    {
                        Value = FormatDouble((double)maxExclusiveValue),
                    };
                    content.Facets.Add(maxExclusiveFacet);
                }
            }

            return content;
        }
        static XmlQualifiedName AddAttributeTypeToXmlSchema(SchemaInfo schemaInfo, UxmlAttributeDescription description, IUxmlFactory factory, FactoryProcessingHelper processingData)
        {
            if (description.name == null)
            {
                return(null);
            }

            string attrTypeName = factory.uxmlQualifiedName + "_" + description.name + "_" + k_TypeSuffix;
            string attrTypeNameInBaseElement = factory.substituteForTypeQualifiedName + "_" + description.name + "_" + k_TypeSuffix;

            FactoryProcessingHelper.AttributeRecord attrRecord;
            if (processingData.attributeTypeNames.TryGetValue(attrTypeNameInBaseElement, out attrRecord))
            {
                // If restriction != baseElement.restriction, we need to declare a new type.
                // Note: we do not support attributes having a less restrictive restriction than its base type.
                if ((description.restriction == null && attrRecord.desc.restriction == null) ||
                    (description.restriction != null && description.restriction.Equals(attrRecord.desc.restriction)))
                {
                    // Register attrTypeName -> attrRecord for potential future derived elements.
                    processingData.attributeTypeNames.Add(attrTypeName, attrRecord);
                    return(attrRecord.name);
                }
            }

            XmlQualifiedName xqn;

            FactoryProcessingHelper.AttributeRecord attributeRecord;

            if (description.restriction == null)
            {
                // Type is a built-in type.
                xqn             = new XmlQualifiedName(description.type, description.typeNamespace);
                attributeRecord = new FactoryProcessingHelper.AttributeRecord {
                    name = xqn, desc = description
                };
                processingData.attributeTypeNames.Add(attrTypeName, attributeRecord);
                return(xqn);
            }

            string attrTypeNameForSchema = factory.uxmlName + "_" + description.name + "_" + k_TypeSuffix;

            xqn = new XmlQualifiedName(attrTypeNameForSchema, schemaInfo.schema.TargetNamespace);

            XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();

            simpleType.Name = attrTypeNameForSchema;

            UxmlEnumeration enumRestriction = description.restriction as UxmlEnumeration;

            if (enumRestriction != null)
            {
                XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                simpleType.Content       = restriction;
                restriction.BaseTypeName = new XmlQualifiedName(description.type, description.typeNamespace);

                foreach (var v in enumRestriction.values)
                {
                    XmlSchemaEnumerationFacet enumValue = new XmlSchemaEnumerationFacet();
                    enumValue.Value = v;
                    restriction.Facets.Add(enumValue);
                }
            }
            else
            {
                UxmlValueMatches regexRestriction = description.restriction as UxmlValueMatches;
                if (regexRestriction != null)
                {
                    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                    simpleType.Content       = restriction;
                    restriction.BaseTypeName = new XmlQualifiedName(description.type, description.typeNamespace);

                    XmlSchemaPatternFacet pattern = new XmlSchemaPatternFacet();
                    pattern.Value = regexRestriction.regex;
                    restriction.Facets.Add(pattern);
                }
                else
                {
                    UxmlValueBounds bounds = description.restriction as UxmlValueBounds;
                    if (bounds != null)
                    {
                        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                        simpleType.Content       = restriction;
                        restriction.BaseTypeName = new XmlQualifiedName(description.type, description.typeNamespace);

                        XmlSchemaFacet facet;
                        if (bounds.excludeMin)
                        {
                            facet = new XmlSchemaMinExclusiveFacet();
                        }
                        else
                        {
                            facet = new XmlSchemaMinInclusiveFacet();
                        }
                        facet.Value = bounds.min;
                        restriction.Facets.Add(facet);

                        if (bounds.excludeMax)
                        {
                            facet = new XmlSchemaMaxExclusiveFacet();
                        }
                        else
                        {
                            facet = new XmlSchemaMaxInclusiveFacet();
                        }
                        facet.Value = bounds.max;
                        restriction.Facets.Add(facet);
                    }
                    else
                    {
                        Debug.Log("Unsupported restriction type.");
                    }
                }
            }

            schemaInfo.schema.Items.Add(simpleType);
            attributeRecord = new FactoryProcessingHelper.AttributeRecord {
                name = xqn, desc = description
            };
            processingData.attributeTypeNames.Add(attrTypeName, attributeRecord);
            return(xqn);
        }
Beispiel #14
0
        public static IEnumerable <XmlSchemaFacet> createXmlFacets(IEnumerable <ICctsFacet> facets)
        {
            var xmlFacets = new List <XmlSchemaFacet>();

            foreach (var facet in facets)
            {
                XmlSchemaFacet xmlFacet = null;
                switch (facet.name)
                {
                case "fractionDigit":
                    xmlFacet = new XmlSchemaFractionDigitsFacet();
                    break;

                case "length":
                    xmlFacet = new XmlSchemaLengthFacet();
                    break;

                case "maxExclusive":
                    xmlFacet = new XmlSchemaMaxExclusiveFacet();
                    break;

                case "maxInclusive":
                    xmlFacet = new XmlSchemaMaxInclusiveFacet();
                    break;

                case "maxLength":
                    xmlFacet = new XmlSchemaMaxLengthFacet();
                    break;

                case "minExclusive":
                    xmlFacet = new XmlSchemaMinExclusiveFacet();
                    break;

                case "minInclusive":
                    xmlFacet = new XmlSchemaMinInclusiveFacet();
                    break;

                case "minLength":
                    xmlFacet = new XmlSchemaMinLengthFacet();
                    break;

                case "pattern":
                    xmlFacet = new XmlSchemaPatternFacet();
                    break;

                case "totalDigits":
                    xmlFacet = new XmlSchemaTotalDigitsFacet();
                    break;

                case "whiteSpace":
                    xmlFacet = new XmlSchemaWhiteSpaceFacet();
                    break;

                case "enumeration":
                    foreach (var enumValue in facet.content.Split('|'))
                    {
                        var enumerationFacet = new XmlSchemaEnumerationFacet();
                        enumerationFacet.Value = enumValue;
                        xmlFacets.Add(enumerationFacet);
                    }
                    break;
                }
                if (xmlFacet != null)
                {
                    xmlFacet.Value = facet.content;
                    xmlFacets.Add(xmlFacet);
                }
            }
            return(xmlFacets);
        }
Beispiel #15
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

        // <xs:simpleType name="OrderQuantityType">
        XmlSchemaSimpleType OrderQuantityType = new XmlSchemaSimpleType();

        OrderQuantityType.Name = "OrderQuantityType";

        // <xs:restriction base="xs:int">
        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();

        restriction.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");

        // <xs:minInclusive value="5"/>
        XmlSchemaMinInclusiveFacet minInclusive = new XmlSchemaMinInclusiveFacet();

        minInclusive.Value = "5";
        restriction.Facets.Add(minInclusive);

        OrderQuantityType.Content = restriction;

        schema.Items.Add(OrderQuantityType);

        // <xs:element name="item">
        XmlSchemaElement element = new XmlSchemaElement();

        element.Name = "item";

        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();

        // <xs:attribute name="OrderQuantity" type="OrderQuantityType"/>
        XmlSchemaAttribute OrderQuantityAttribute = new XmlSchemaAttribute();

        OrderQuantityAttribute.Name           = "OrderQuantity";
        OrderQuantityAttribute.SchemaTypeName = new XmlQualifiedName("OrderQuantityType", "");
        complexType.Attributes.Add(OrderQuantityAttribute);

        element.SchemaType = complexType;

        schema.Items.Add(element);

        XmlSchemaSet schemaSet = new XmlSchemaSet();

        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }
 protected override void Visit(XmlSchemaMinInclusiveFacet facet)
 {
     AddLeaf(SimpleTypeStructureNodeType.FacetMinInclusive, facet);
 }
 protected virtual void Visit(XmlSchemaMinInclusiveFacet facet)
 {
 }
Beispiel #18
0
        private List <AttributeRule> GetRules(XmlSchemaSimpleTypeRestriction restriction)
        {
            List <AttributeRule> rules = new List <AttributeRule>();

            List <string> enumValues = null;

            foreach (XmlSchemaFacet facet in restriction.Facets)
            {
                XmlSchemaEnumerationFacet enumFacet = facet as XmlSchemaEnumerationFacet;
                if (enumFacet != null)
                {
                    if (enumValues == null)
                    {
                        enumValues = new List <string>();
                    }
                    enumValues.Add(enumFacet.Value);
                    continue;
                }

                XmlSchemaMinExclusiveFacet minExclusiveFacet = facet as XmlSchemaMinExclusiveFacet;
                if (minExclusiveFacet != null)
                {
                    double minExclusive;
                    if (Double.TryParse(minExclusiveFacet.Value, out minExclusive))
                    {
                        rules.Add(new NumericMinRule(minExclusive, false));
                    }
                    continue;
                }

                XmlSchemaMinInclusiveFacet minInclusiveFacet = facet as XmlSchemaMinInclusiveFacet;
                if (minInclusiveFacet != null)
                {
                    double minInclusive;
                    if (Double.TryParse(minInclusiveFacet.Value, out minInclusive))
                    {
                        rules.Add(new NumericMinRule(minInclusive, true));
                    }
                    continue;
                }

                XmlSchemaMaxExclusiveFacet maxExclusiveFacet = facet as XmlSchemaMaxExclusiveFacet;
                if (maxExclusiveFacet != null)
                {
                    double maxExclusive;
                    if (Double.TryParse(maxExclusiveFacet.Value, out maxExclusive))
                    {
                        rules.Add(new NumericMaxRule(maxExclusive, false));
                    }
                    continue;
                }

                XmlSchemaMaxInclusiveFacet maxInclusiveFacet = facet as XmlSchemaMaxInclusiveFacet;
                if (maxInclusiveFacet != null)
                {
                    double maxInclusive;
                    if (Double.TryParse(maxInclusiveFacet.Value, out maxInclusive))
                    {
                        rules.Add(new NumericMaxRule(maxInclusive, true));
                    }
                    continue;
                }
            }

            if (enumValues != null && enumValues.Count > 0)
            {
                rules.Add(new StringEnumRule(enumValues.ToArray()));
            }

            return(rules);
        }
Beispiel #19
0
        private static XmlSchemaSimpleTypeRestriction ExtractNumberAndIntegerFacets(JsonSchema jSchema, TypeKeyword type)
        {
            XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction();
            double?minValue          = GetterExtensions.Minimum(jSchema);
            double?minExclusiveValue = GetterExtensions.ExclusiveMinimum(jSchema);

            if (type.Value == JsonSchemaType.Number)
            {
                content.BaseTypeName = new XmlQualifiedName("decimal", XML_SCHEMA_NS);
            }
            else if (type.Value == JsonSchemaType.Integer)
            {
                if (minValue != null && minValue == 1)
                {
                    content.BaseTypeName = new XmlQualifiedName("positiveInteger", XML_SCHEMA_NS);
                }
                else
                {
                    content.BaseTypeName = new XmlQualifiedName("integer", XML_SCHEMA_NS);
                }
            }

            double?maxValue          = GetterExtensions.Maximum(jSchema);
            double?maxExclusiveValue = GetterExtensions.ExclusiveMaximum(jSchema);

            Regex regex = new Regex("^[9]+$");

            if ((minValue != null && maxValue != null) && Math.Abs((double)minValue).Equals(maxValue) && regex.IsMatch(maxValue.ToString()))
            {
                XmlSchemaTotalDigitsFacet facet = new XmlSchemaTotalDigitsFacet
                {
                    Value = FormatDouble(maxValue.ToString().Length),
                };
                content.Facets.Add(facet);
            }
            else
            {
                if (minValue != null || minExclusiveValue != null)
                {
                    if (minValue != null)
                    {
                        XmlSchemaMinInclusiveFacet facet = new XmlSchemaMinInclusiveFacet
                        {
                            Value = FormatDouble((double)minValue),
                        };
                        content.Facets.Add(facet);
                    }
                    else
                    {
                        XmlSchemaMinExclusiveFacet facet = new XmlSchemaMinExclusiveFacet
                        {
                            Value = FormatDouble((double)minExclusiveValue),
                        };
                        content.Facets.Add(facet);
                    }
                }

                if (maxValue != null || maxExclusiveValue != null)
                {
                    if (maxValue != null)
                    {
                        XmlSchemaMaxInclusiveFacet maxInclusiveFacet = new XmlSchemaMaxInclusiveFacet
                        {
                            Value = FormatDouble((double)maxValue),
                        };
                        content.Facets.Add(maxInclusiveFacet);
                    }
                    else
                    {
                        XmlSchemaMaxExclusiveFacet maxExclusiveFacet = new XmlSchemaMaxExclusiveFacet
                        {
                            Value = FormatDouble((double)maxExclusiveValue),
                        };
                        content.Facets.Add(maxExclusiveFacet);
                    }
                }
            }

            return(content);
        }
Beispiel #20
0
        /// <summary>
        /// Render field-criteria such as max length and patterns.
        /// </summary>
        /// <param name="restrictions">XSD restriction object to receive the facets.</param>
        /// <param name="fieldEntity">The field being described.</param>
        /// <param name="fieldTypeAlias">The XSD type string for the field type. E.g. 'string'.</param>
        private void AddFieldRestrictions(XmlSchemaSimpleTypeRestriction restrictions, Entity fieldEntity, string fieldTypeAlias)
        {
            switch (fieldTypeAlias)
            {
            // Int constraints
            case "intField":
                int?minValue = _schemaManager.GetIntFieldValue(fieldEntity, Aliases2.MinInt);
                if (minValue != null)
                {
                    var minFacet = new XmlSchemaMinInclusiveFacet()
                    {
                        Value = minValue.ToString()
                    };
                    restrictions.Facets.Add(minFacet);
                }
                int?maxValue = _schemaManager.GetIntFieldValue(fieldEntity, Aliases2.MaxInt);
                if (maxValue != null)
                {
                    var maxFacet = new XmlSchemaMaxInclusiveFacet()
                    {
                        Value = maxValue.ToString()
                    };
                    restrictions.Facets.Add(maxFacet);
                }
                break;

            // String constraints
            case "stringField":
                int?minLength = _schemaManager.GetIntFieldValue(fieldEntity, Aliases2.MinLength);
                if (minLength != null)
                {
                    var minFacet = new XmlSchemaMinLengthFacet()
                    {
                        Value = minLength.ToString()
                    };
                    restrictions.Facets.Add(minFacet);
                }
                int?maxLength = _schemaManager.GetIntFieldValue(fieldEntity, Aliases2.MaxLength);
                if (maxLength != null)
                {
                    var maxFacet = new XmlSchemaMaxLengthFacet()
                    {
                        Value = maxLength.ToString()
                    };
                    restrictions.Facets.Add(maxFacet);
                }
                var stringPattern = _schemaManager.GetRelationshipsFromEntity(fieldEntity, A(Aliases2.Pattern)).FirstOrDefault();
                if (stringPattern != null)
                {
                    string sRegex = _schemaManager.GetStringFieldValue(stringPattern, Aliases2.Regex);
                    if (sRegex != null)
                    {
                        var regexFacet = new XmlSchemaPatternFacet()
                        {
                            Value = sRegex
                        };
                        restrictions.Facets.Add(regexFacet);
                    }
                }
                break;

            // String constraints
            case "aliasField":
                // optional namespace prefix, followed by lower-case alpha, alphanumeric
                string aliasRegex      = @"([_a-zA-Z][_a-zA-Z0-9]*\:)?[_a-zA-Z][_a-zA-Z0-9]{0,99}";
                var    aliasRegexFacet = new XmlSchemaPatternFacet()
                {
                    Value = aliasRegex
                };
                restrictions.Facets.Add(aliasRegexFacet);
                break;
            }
        }
Beispiel #21
0
        public XsdSimpleRestrictionType(RelaxngDatatype primitive, RelaxngParamList parameters)
        {
            type = new XmlSchemaSimpleType();
            XmlSchemaSimpleTypeRestriction r =
                new XmlSchemaSimpleTypeRestriction();

            type.Content = r;
            string ns = primitive.NamespaceURI;

            // Remap XML Schema datatypes namespace -> XML Schema namespace.
            if (ns == "http://www.w3.org/2001/XMLSchema-datatypes")
            {
                ns = XSchema.Namespace;
            }
            r.BaseTypeName = new XmlQualifiedName(primitive.Name, ns);
            foreach (RelaxngParam p in parameters)
            {
                XmlSchemaFacet f     = null;
                string         value = p.Value;
                switch (p.Name)
                {
                case "maxExclusive":
                    f = new XmlSchemaMaxExclusiveFacet();
                    break;

                case "maxInclusive":
                    f = new XmlSchemaMaxInclusiveFacet();
                    break;

                case "minExclusive":
                    f = new XmlSchemaMinExclusiveFacet();
                    break;

                case "minInclusive":
                    f = new XmlSchemaMinInclusiveFacet();
                    break;

                case "pattern":
                    f = new XmlSchemaPatternFacet();
                    // .NET/Mono Regex has a bug that it does not support "IsLatin-1Supplement"
                    // (it somehow breaks at '-').
                    value = value.Replace("\\p{IsLatin-1Supplement}", "[\\x80-\\xFF]");
                    break;

                case "whiteSpace":
                    f = new XmlSchemaWhiteSpaceFacet();
                    break;

                case "length":
                    f = new XmlSchemaLengthFacet();
                    break;

                case "maxLength":
                    f = new XmlSchemaMaxLengthFacet();
                    break;

                case "minLength":
                    f = new XmlSchemaMinLengthFacet();
                    break;

                case "fractionDigits":
                    f = new XmlSchemaFractionDigitsFacet();
                    break;

                case "totalDigits":
                    f = new XmlSchemaTotalDigitsFacet();
                    break;

                default:
                    throw new RelaxngException(String.Format("XML Schema facet {0} is not recognized or not supported.", p.Name));
                }
                f.Value = value;
                r.Facets.Add(f);
            }

            // Now we create XmlSchema to handle simple-type
            // based validation (since there is no other way,
            // because of sucky XmlSchemaSimpleType design).
            schema = new XSchema();
            XmlSchemaElement el = new XmlSchemaElement();

            el.Name       = "root";
            el.SchemaType = type;
            schema.Items.Add(el);
            schema.Compile(null);
        }