예제 #1
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;
            }
        }