private static string GetPageUrl(ContentItemSystemAttributes system) { // TODO: The URL generation logic should be adjusted to match your website var url = string.Empty; if (system.SitemapLocation.Any()) { url = $"/{system.SitemapLocation[0]}"; } url = $"{url}/{system.Codename.Replace("_", "-").TrimEnd('-')}"; return(url); }
/// <summary> /// Gets the codenames of <see cref="IEnumerable{Object}"/> content items using <see cref="System.Reflection"/>. /// </summary> /// <param name="contentItems">The shallow content items to be fetched again using their codenames</param> /// <returns>The codenames</returns> public static IEnumerable <string> GetContentItemCodenames(IEnumerable <object> contentItems) { if (contentItems == null) { throw new ArgumentNullException(nameof(contentItems)); } var codenames = new List <string>(); foreach (var item in contentItems) { ContentItemSystemAttributes system = item.GetType().GetTypeInfo().GetProperty("System", typeof(ContentItemSystemAttributes)).GetValue(item) as ContentItemSystemAttributes; codenames.Add(system.Codename); } return(codenames); }
private object CreateInstance(Type detectedModelType, ref ContentItemSystemAttributes itemSystemAttributes, ref Dictionary <string, object> processedItems) { if (detectedModelType == typeof(object)) { // Try to find a specific type detectedModelType = _typeProvider?.GetType(itemSystemAttributes.Type); } if (detectedModelType == null) { return(null); } var instance = Activator.CreateInstance(detectedModelType); if (!processedItems.ContainsKey(itemSystemAttributes.Codename)) { processedItems.Add(itemSystemAttributes.Codename, instance); } return(instance); }
private JObject GetElementData(JObject elementsData, PropertyInfo property, ContentItemSystemAttributes itemSystemAttributes) => (JObject)elementsData.Properties()?.FirstOrDefault(p => _propertyMapper.IsMatch(property, p.Name, itemSystemAttributes?.Type))?.Value;
private object GetPropertyValue(JObject elementsData, PropertyInfo property, JObject linkedItems, ResolvingContext context, ContentItemSystemAttributes itemSystemAttributes, ref Dictionary <string, object> processedItems, ref List <PropertyInfo> richTextPropertiesToBeProcessed) { var elementData = GetElementData(elementsData, property, itemSystemAttributes); var valueConverter = GetValueConverter(property); if (valueConverter != null) { return(valueConverter.GetPropertyValue(property, elementData, context)); } if (property.PropertyType == typeof(string)) { var(value, isRichText) = GetStringValue(elementData); if (isRichText) { richTextPropertiesToBeProcessed.Add(property); } return(value); } if (IsNonHierarchicalField(property.PropertyType)) { return(GetRawValue(elementData)?.ToObject(property.PropertyType)); } if (IsGenericHierarchicalField(property.PropertyType)) { return(GetLinkedItemsValue(elementData, linkedItems, property.PropertyType, ref processedItems)); } return(null); }
private object GetRichTextValue(string value, JObject elementsData, PropertyInfo property, JObject linkedItems, ResolvingContext context, ContentItemSystemAttributes itemSystemAttributes, ref Dictionary <string, object> processedItems, ref HashSet <RichTextContentElements> currentlyResolvedRichStrings) { var currentlyProcessedString = new RichTextContentElements(itemSystemAttributes?.Codename, property.Name); if (currentlyResolvedRichStrings.Contains(currentlyProcessedString)) { // If this element is already being processed it's necessary to use it as is (with removed inline content items) // otherwise resolving would be stuck in an infinite loop return(RemoveInlineContentItems(value)); } currentlyResolvedRichStrings.Add(currentlyProcessedString); var elementData = GetElementData(elementsData, property, itemSystemAttributes); var linkedItemsInRichText = GetLinkedItemsInRichText(elementData); value = ProcessInlineContentItems(linkedItems, processedItems, value, linkedItemsInRichText, currentlyResolvedRichStrings); currentlyResolvedRichStrings.Remove(currentlyProcessedString); return(value); }