Пример #1
0
        /// <summary>
        ///     Load field data.
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <remarks>
        ///     Data sources MUST:
        ///     - ensure that bits are represented as Booleans
        ///     - ensure that XML is transformed so that entityRefs contain Upgrade ids
        ///     - or where XML contains an alias, translate it to uprgadeId|alias   (as the alias may be changed in the target)
        ///     - ensure that aliases export their namespace and direction marker.
        /// </remarks>
        public IEnumerable <DataEntry> GetFieldData(string dataTable, IProcessingContext context)
        {
            if (!FieldData.ContainsKey(dataTable))
            {
                return(Enumerable.Empty <DataEntry>( ));
            }

            Dictionary <Entity, List <FieldData> > typedValues = FieldData[dataTable];

            if (dataTable == "Alias")
            {
                Alias aliasMarkerIdField = Aliases.CoreAlias("aliasMarkerId");

                return(from pair in typedValues
                       from field in pair.Value
                       let alias = SchemaResolver.GetAliasFieldValue(pair.Key, field.Field.Alias)
                                   let intFieldValue = SchemaResolver.GetIntFieldValue(field.Field, aliasMarkerIdField)
                                                       where intFieldValue != null
                                                       where pair.Key.Members != null && pair.Key.Members.Any(m => m.MemberDefinition.Alias.Namespace == "core" && m.MemberDefinition.Alias.Value == "inSolution" && m.Value == ActiveSolution)
                                                       let markerId = intFieldValue.Value
                                                                      select new DataEntry
                {
                    AliasMarkerId = markerId,
                    Data = alias.Value,
                    EntityId = pair.Key.Guid,
                    FieldId = field.Field.Guid,
                    Namespace = alias.Namespace,
                    State = DataState.Added
                });
            }

            /////
            // Non-Alias
            /////
            return(from pair in typedValues
                   from field in pair.Value
                   where pair.Key.Members != null && pair.Key.Members.Any(m => m.MemberDefinition.Alias.Namespace == "core" && m.MemberDefinition.Alias.Value == "inSolution" && m.Value == ActiveSolution)
                   select new DataEntry
            {
                Data = FormatData(field),
                EntityId = pair.Key.Guid,
                FieldId = field.Field.Guid,
                State = DataState.Added
            });
        }
Пример #2
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;
            }
        }