public static IContentMapper GetMapper(uSyncContentMapping mapping)
 {
     switch (mapping.MappingType)
     {
         case ContentMappingType.Content:
             return new ContentIdMapper();
         case ContentMappingType.DataType:
             return new ContentDataTypeMapper();
         case ContentMappingType.DataTypeKeys:
             return new ContentDataTypeKeyMapper();
         case ContentMappingType.Custom:
             return ContentMapperFactory.GetCustomMapper(mapping.CustomMappingType);
         default:
             return null;
     }
 }
Esempio n. 2
0
        public static IContentMapper GetMapper(uSyncContentMapping mapping)
        {
            switch (mapping.MappingType)
            {
            case ContentMappingType.Content:
                return(new ContentIdMapper());

            case ContentMappingType.DataType:
                return(new ContentDataTypeMapper());

            case ContentMappingType.DataTypeKeys:
                return(new ContentDataTypeKeyMapper());

            case ContentMappingType.Custom:
                return(ContentMapperFactory.GetCustomMapper(mapping.CustomMappingType));

            default:
                return(null);
            }
        }
Esempio n. 3
0
        public string GetImportValue(int dataTypeDefinitionId, string content)
        {
            // We need to retrieve the datatype associated with the property so that we can parse the fieldset
            // then we will go through each item in the fieldset and if there is a mapper associated with that item's datatype
            // we should pull out the property value and map it

            string archetypeConfig = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinitionId).PreValuesAsDictionary["archetypeConfig"].Value;

            var config = JsonConvert.DeserializeObject <ArchetypePreValue>(archetypeConfig);

            var typedContent = JsonConvert.DeserializeObject <ArchetypeModel>(content);

            foreach (ArchetypePreValueFieldset fieldSet in config.Fieldsets)
            {
                foreach (ArchetypePreValueProperty property in fieldSet.Properties)
                {
                    IDataTypeDefinition dataType = _dataTypeService.GetDataTypeDefinitionById(property.DataTypeGuid);

                    uSyncContentMapping mapping =
                        uSyncCoreContext.Instance.Configuration.Settings.ContentMappings.SingleOrDefault(x => x.EditorAlias == dataType.PropertyEditorAlias);

                    if (mapping != null)
                    {
                        IContentMapper mapper = ContentMapperFactory.GetMapper(mapping);

                        if (mapper != null)
                        {
                            typedContent.Fieldsets.AsQueryable()
                            .SelectMany(fs => fs.Properties)
                            .Where(p => p.Alias == property.Alias)
                            .ForEach(pm => pm.Value = mapper.GetImportValue(dataType.Id, pm.Value.ToString()));
                        }
                    }
                }
            }

            return(typedContent.SerializeForPersistence());
        }