private string GetExportIds(PropertyType propType, XElement value)
        {
            // (need to strip cdata from value)
            var val = GetImportXml(value);

            if (!string.IsNullOrWhiteSpace(val))
            {
                var mapping = uSyncCoreContext.Instance.Configuration.Settings.ContentMappings
                              .SingleOrDefault(x => x.EditorAlias == propType.PropertyEditorAlias);


                if (mapping != null)
                {
                    LogHelper.Debug <Events>("Mapping Content Export: {0} {1}", () => mapping.EditorAlias, () => mapping.MappingType);

                    IContentMapper mapper = ContentMapperFactory.GetMapper(mapping);

                    if (mapper != null)
                    {
                        return(mapper.GetExportValue(propType.DataTypeDefinitionId, val));
                    }
                }
            }
            return(GetInnerXml(value));
        }
        private string GetValue(string value, bool exporting)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(value);
            }

            var items = JsonConvert.DeserializeObject <EmbeddedContentItem[]>(value);

            foreach (EmbeddedContentItem item in items)
            {
                IContentType contentType = _contentTypeService.GetContentType(item.ContentTypeAlias);
                if (contentType == null)
                {
                    continue;
                }

                foreach (KeyValuePair <string, object> property in item.Properties.ToList())
                {
                    PropertyType propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(_ => _.Alias == property.Key);
                    if (propertyType == null)
                    {
                        continue;
                    }
                    IDataTypeDefinition dataType = _dataTypeService.GetDataTypeDefinitionById(propertyType.DataTypeDefinitionId);

                    IContentMapper mapper = ContentMapperFactory.GetMapper(new uSyncContentMapping {
                        EditorAlias = dataType.PropertyEditorAlias
                    });
                    if (mapper != null)
                    {
                        string newValue;
                        if (exporting)
                        {
                            newValue = mapper.GetExportValue(dataType.Id, property.Value.ToString());
                        }
                        else
                        {
                            newValue = mapper.GetImportValue(dataType.Id, property.Value.ToString());
                        }
                        item.Properties[property.Key] = newValue;
                    }
                }
            }

            return(JsonConvert.SerializeObject(items, Formatting.Indented));
        }
        internal string GetImportIds(PropertyType propType, string content)
        {
            var mapping = uSyncCoreContext.Instance.Configuration.Settings.ContentMappings
                          .SingleOrDefault(x => x.EditorAlias == propType.PropertyEditorAlias);

            if (mapping != null)
            {
                LogHelper.Debug <Events>("Mapping Content Import: {0} {1}", () => mapping.EditorAlias, () => mapping.MappingType);

                IContentMapper mapper = ContentMapperFactory.GetMapper(mapping);

                if (mapper != null)
                {
                    return(mapper.GetImportValue(propType.DataTypeDefinitionId, content));
                }
            }

            return(content);
        }
示例#4
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());
        }