Ejemplo n.º 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
            });
        }