コード例 #1
0
        private void populateSubRootMaps(ModelData dto, IEnumerable <ClarifyGenericMapEntry> childMapsForDtoType, ClarifyDataRow parentRecord)
        {
            var childSubRootMaps = childMapsForDtoType.Where(map => map.IsNewRoot());

            foreach (var childMap in childSubRootMaps)
            {
                var subRootGeneric = childMap.ClarifyGeneric;
                var rootKeyField   = childMap.NewRoot.RootKeyField;
                var parentKeyField = childMap.NewRoot.ParentKeyField;

                var childRecord = findRelatedSubRecord(parentRecord, parentKeyField, subRootGeneric, rootKeyField);
                if (childRecord == null)
                {
                    continue;
                }

                populateDTOForGenericRecord(childMap, childRecord, dto);
            }
        }
コード例 #2
0
        private ModelData[] createDtosForMap(ClarifyGenericMapEntry genericMap, IEnumerable <ClarifyDataRow> records)
        {
            var rows = new List <ModelData>();

            foreach (var record in records)
            {
                var row = new ModelData {
                    Name = genericMap.Model.ModelName, Entity = genericMap.Entity
                };

                populateDTOForGenericRecord(genericMap, record, row);

                genericMap.Tags.Each(_ => row.AddTag(_));

                if (!row.Has("entity") && genericMap.Entity.IsNotEmpty())
                {
                    row["entity"] = genericMap.Entity;
                }

                rows.Add(row);
            }

            return(rows.ToArray());
        }
コード例 #3
0
        private void populateDataWithFieldValues(FieldMap[] fieldMaps, ClarifyDataRow record, ModelData model)
        {
            var tableName = record.Table.TableName;

            if (tableName.Contains(":"))
            {
                tableName = tableName.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries).Last();
            }

            var tableMetadata = _metadata.MetadataFor(tableName);

            foreach (var fieldMap in fieldMaps)
            {
                if (fieldMap.Key.IsEmpty())
                {
                    continue;
                }

                try
                {
                    var fieldMetadata = fieldMap.FieldNames.Length == 1
                                                ? tableMetadata.MetadataFor(fieldMap.FieldNames[0])
                                                : new FieldSchemaMetadata();

                    var propertyValue = GetFieldValueForRecord(fieldMap, record);

                    if (propertyValue is string && fieldMap.ShouldEncode)
                    {
                        propertyValue = _encoder.Encode((string)propertyValue);
                    }

                    if (fieldMap.PropertyType == typeof(int))
                    {
                        propertyValue = Convert.ToInt32(propertyValue);
                    }

                    if (fieldMap.PropertyType == typeof(DateTime))
                    {
                        var dateTime = Convert.ToDateTime(propertyValue);
                        if (fieldMetadata.IsDateOnlyField())
                        {
                            propertyValue = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, DateTimeKind.Utc);
                        }
                        else
                        {
                            var utcDateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc);
                            propertyValue = utcDateTime;
                        }
                    }

                    model[fieldMap.Key] = propertyValue;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Could not set property on type {0}. Field: {1}".ToFormat(model.GetType().Name, fieldMap.ToString()), ex);
                }
            }
        }
コード例 #4
0
 private void populateDTOWithFieldValues(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData model)
 {
     populateDataWithFieldValues(genericMap.FieldMaps, record, model);
     populateDataWithFieldValues(genericMap.Model.FieldMaps, record, model);
 }
コード例 #5
0
        private void populateDTOWithRelatedGenericRecords(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData model)
        {
            var childMapsForDtoType = genericMap.ChildGenericMaps.Where(child => model.Name == child.Model.ModelName).ToArray();

            populateSubRootMaps(model, childMapsForDtoType, record);

            populateBasedOnRelatedGenerics(model, childMapsForDtoType, record);
        }
コード例 #6
0
        private void populateDTOWithRelatedDTOs(ClarifyGenericMapEntry parentGenericMap, ClarifyDataRow parentRecord, ModelData parentModel)
        {
            var childMapsForChildDtos = parentGenericMap.ChildGenericMaps.Where(child => parentModel.Name != child.Model.ModelName);

            foreach (var childMap in childMapsForChildDtos)
            {
                if (childMap.Model.IsCollection)
                {
                    var children = new List <ModelData>();
                    foreach (var childRecord in parentRecord.RelatedRows(childMap.ClarifyGeneric))
                    {
                        var childModel = new ModelData {
                            Name = childMap.Model.ModelName
                        };

                        populateDTOForGenericRecord(childMap, childRecord, childModel);

                        if (!childModel.IsEmpty())
                        {
                            children.Add(childModel);
                        }
                    }

                    parentModel[childMap.Model.ParentProperty] = children;
                }
                else if (parentGenericMap.ClarifyGeneric == childMap.ClarifyGeneric)
                {
                    var childModel = new ModelData {
                        Name = childMap.Model.ModelName
                    };
                    populateDTOForGenericRecord(childMap, parentRecord, childModel);

                    if (!childModel.IsEmpty())
                    {
                        parentModel[childMap.Model.ParentProperty] = childModel;
                    }
                    else if (childMap.Model.AllowEmpty)
                    {
                        parentModel[childMap.Model.ParentProperty] = null;
                    }
                }
                else
                {
                    var relatedChildRows = parentRecord.RelatedRows(childMap.ClarifyGeneric);
                    if (relatedChildRows.Any())
                    {
                        var childRecord = relatedChildRows.First();
                        var childModel  = new ModelData {
                            Name = childMap.Model.ModelName
                        };
                        populateDTOForGenericRecord(childMap, childRecord, childModel);

                        if (!childModel.IsEmpty())
                        {
                            parentModel[childMap.Model.ParentProperty] = childModel;
                        }
                        else if (childMap.Model.AllowEmpty)
                        {
                            parentModel[childMap.Model.ParentProperty] = null;
                        }
                    }
                    else
                    {
                        parentModel[childMap.Model.ParentProperty] = null;
                    }
                }
            }
        }
コード例 #7
0
        private void populateDTOForGenericRecord(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData dto)
        {
            populateDTOWithFieldValues(genericMap, record, dto);

            populateDTOWithRelatedGenericRecords(genericMap, record, dto);

            populateDTOWithRelatedDTOs(genericMap, record, dto);

            foreach (var transform in genericMap.Transforms)
            {
                transform.Execute(dto, _services);
            }
        }
 public VariableExpansionContext(IServiceLocator services, string key, ModelData data)
 {
     _services = services;
     _key      = key;
     _data     = data;
 }
コード例 #9
0
 public VariableExpanderContext(ModelData data, IDictionary <string, object> values)
 {
     _data   = data;
     _values = values;
 }