Ejemplo n.º 1
0
 public BlockDataPropertyHandler(
     IPropertyManager propertyManager,
     IContentSerializerSettings contentSerializerSettings)
 {
     _propertyManager           = propertyManager ?? throw new ArgumentNullException(nameof(propertyManager));
     _contentSerializerSettings = contentSerializerSettings;
 }
        public Dictionary <string, object> GetStructuredData(
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            var properties     = this._propertyResolver.GetProperties(contentData);
            var structuredData = new Dictionary <string, object>();

            foreach (var property in properties)
            {
                var propertyHandler = this._propertyHandlerService.GetPropertyHandler(property);
                if (propertyHandler == null)
                {
                    Trace.WriteLine($"No PropertyHandler was found for type '{property.PropertyType}'");
                    continue;
                }

                var method = GetMethodInfo(propertyHandler);

                var key    = this._propertyNameStrategy.GetPropertyName(property);
                var value  = property.GetValue(contentData);
                var result = method.Invoke(propertyHandler, new[] { value, property, contentData, settings });
                structuredData.Add(key, result);
            }
            return(structuredData);
        }
Ejemplo n.º 3
0
 public object Handle(int value,
                      PropertyInfo property,
                      IContentData contentData,
                      IContentSerializerSettings settings)
 {
     return(value);
 }
Ejemplo n.º 4
0
 public ContentReferenceListPropertyHandler(
     IPropertyHandler <ContentReference> contentReferencePropertyHandler,
     IContentSerializerSettings contentSerializerSettings)
 {
     _contentReferencePropertyHandler = contentReferencePropertyHandler ?? throw new ArgumentNullException(nameof(contentReferencePropertyHandler));
     _contentSerializerSettings       = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings));
 }
Ejemplo n.º 5
0
        public object Handle(
            Url url,
            PropertyInfo property,
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            if (url == null)
            {
                return(null);
            }

            if (url.Scheme == MailTo)
            {
                return(url.OriginalString);
            }

            if (url.IsAbsoluteUri)
            {
                if (settings.UrlSettings.UseAbsoluteUrls)
                {
                    return(url.OriginalString);
                }

                return(url.PathAndQuery);
            }

            return(this._urlHelper.ContentUrl(url, settings.UrlSettings));
        }
Ejemplo n.º 6
0
        public object Handle(LinkItemCollection linkItemCollection,
                             PropertyInfo property,
                             IContentData contentData,
                             IContentSerializerSettings settings)
        {
            if (linkItemCollection == null)
            {
                return(null);
            }
            var links = new List <LinkItem>();

            foreach (var link in linkItemCollection)
            {
                string prettyUrl = null;
                if (link.ReferencedPermanentLinkIds.Any())
                {
                    var url = new Url(link.Href);
                    prettyUrl = this._urlHelper.ContentUrl(url, settings.UrlSettings);
                }
                links.Add(new LinkItem
                {
                    Text   = link.Text,
                    Target = link.Target,
                    Title  = link.Title,
                    Href   = prettyUrl ?? link.Href
                });
            }

            return(links);
        }
        private static bool WrapItems(ContentArea contentArea, IContentSerializerSettings contentSerializerSettings)
        {
            var wrapItemsAttribute = contentArea.GetType().GetCustomAttribute <ContentSerializerWrapItemsAttribute>();
            var wrapItems          = wrapItemsAttribute?.WrapItems ?? contentSerializerSettings.WrapContentAreaItems;

            return(wrapItems);
        }
 public LinkItemCollectionPropertyHandlerTests()
 {
     this._contentSerializerSettings             = Substitute.For <IContentSerializerSettings>();
     this._contentSerializerSettings.UrlSettings = new UrlSettings();
     this._urlHelper = Substitute.For <IUrlHelper>();
     this._sut       = new LinkItemCollectionPropertyHandler(this._urlHelper, this._contentSerializerSettings);
 }
        public Dictionary <string, object> GetStructuredData(
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            var contentSerializerSettings = settings ?? _contentSerializerSettings;
            var properties     = this._propertyResolver.GetProperties(contentData);
            var structuredData = new Dictionary <string, object>();

            foreach (var property in properties)
            {
                var propertyHandler = this._propertyHandlerService.GetPropertyHandler(property);
                if (propertyHandler == null)
                {
                    Trace.WriteLine($"No PropertyHandler was found for type '{property.PropertyType}'");
                    continue;
                }

                var method = propertyHandler.GetType().GetMethod(nameof(IPropertyHandler <object> .Handle));
                if (method != null)
                {
                    var key   = this._propertyNameStrategy.GetPropertyName(property);
                    var value = property.GetValue(contentData);

                    var result = method.Invoke(propertyHandler, new[] { value, property, contentData });
                    if (result != null || !contentSerializerSettings.IgnoreEmptyValues)
                    {
                        structuredData.Add(key, result);
                    }
                }
            }
            return(structuredData);
        }
 public ContentReferencePropertyHandlerTests()
 {
     this._contentSerializerSettings             = Substitute.For <IContentSerializerSettings>();
     this._contentSerializerSettings.UrlSettings = new UrlSettings();
     this._urlHelper = Substitute.For <IUrlHelper>();
     this._sut       = new ContentReferencePropertyHandler(this._urlHelper, this._contentSerializerSettings);
 }
 public object Handle(
     TimeSpan?value,
     PropertyInfo property,
     IContentData contentData,
     IContentSerializerSettings settings)
 {
     return(value?.ToString());
 }
Ejemplo n.º 12
0
 public object Handle(
     IEnumerable <string> value,
     PropertyInfo property,
     IContentData contentData,
     IContentSerializerSettings settings)
 {
     return(value);
 }
Ejemplo n.º 13
0
 public object Handle(
     PageReference value,
     PropertyInfo property,
     IContentData contentData,
     IContentSerializerSettings settings)
 {
     return(this._contentReferencePropertyHandler.Handle(value, property, contentData, settings));
 }
Ejemplo n.º 14
0
 public object Handle(
     BlockData value,
     PropertyInfo property,
     IContentData contentData,
     IContentSerializerSettings settings)
 {
     return(this._propertyManager.GetStructuredData(value, settings));
 }
Ejemplo n.º 15
0
 public object Handle(
     PageType value,
     PropertyInfo property,
     IContentData contentData,
     IContentSerializerSettings settings)
 {
     return(value == null ? null : new PageTypeModel(value.Name, value.ID));
 }
Ejemplo n.º 16
0
 public StringPropertyHandler(
     ISelectOneStrategy selectOneStrategy,
     ISelectManyStrategy selectManyStrategy,
     IContentSerializerSettings contentSerializerSettings)
 {
     _selectOneStrategy         = selectOneStrategy ?? throw new ArgumentNullException(nameof(selectOneStrategy));
     _selectManyStrategy        = selectManyStrategy ?? throw new ArgumentNullException(nameof(selectManyStrategy));
     _contentSerializerSettings = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings));
 }
 public ContentAreaPropertyHandler(
     IContentLoader contentLoader,
     IPropertyManager propertyManager,
     IContentSerializerSettings contentSerializerSettings)
 {
     _contentLoader             = contentLoader ?? throw new ArgumentNullException(nameof(contentLoader));
     _propertyManager           = propertyManager ?? throw new ArgumentNullException(nameof(propertyManager));
     _contentSerializerSettings = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings));
 }
        private string Execute(IContentData contentData, IContentSerializerSettings settings)
        {
            var result = this._propertyManager.GetStructuredData(contentData, settings);

            return(JsonConvert.SerializeObject(result, new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
 public object Handle(
     XhtmlString value,
     PropertyInfo property,
     IContentData contentData,
     IContentSerializerSettings settings)
 {
     //TODO Fix parsing of images/blocks/links etc so we can provide pretty links.
     return(value?.ToHtmlString());
 }
Ejemplo n.º 20
0
 public UrlHelperAdapter(
     UrlHelper urlHelper,
     ISiteDefinitionResolver siteDefinitionResolver,
     IRequestHostResolver requestHostResolver,
     IContentSerializerSettings contentSerializerSettings)
 {
     _requestHostResolver       = requestHostResolver ?? throw new ArgumentNullException(nameof(requestHostResolver));
     _urlHelper                 = urlHelper ?? throw new ArgumentNullException(nameof(urlHelper));
     _siteDefinitionResolver    = siteDefinitionResolver ?? throw new ArgumentNullException(nameof(siteDefinitionResolver));
     _contentSerializerSettings = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings));
 }
 public PropertyManager(
     IPropertyNameStrategy propertyNameStrategy,
     IPropertyResolver propertyResolver,
     IPropertyHandlerService propertyHandlerService,
     IContentSerializerSettings contentSerializerSettings
     )
 {
     _propertyNameStrategy      = propertyNameStrategy ?? throw new ArgumentNullException(nameof(propertyNameStrategy));
     _propertyResolver          = propertyResolver ?? throw new ArgumentNullException(nameof(propertyResolver));
     _contentSerializerSettings = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings));
     _propertyHandlerService    = propertyHandlerService;
 }
 public PropertyManagerTests()
 {
     this._contentSerializerSettings             = Substitute.For <IContentSerializerSettings>();
     this._contentSerializerSettings.UrlSettings = new UrlSettings();
     this._contentLoader = Substitute.For <IContentLoader>();
     SetupContentLoader(this._contentLoader);
     this._sut = new PropertyManager(
         new PropertyNameStrategy(),
         new PropertyResolver(),
         new PropertyHandlerService()
         );
     this._page = new StandardPageBuilder().Build();
 }
        public object Handle(
            ContentArea contentArea,
            PropertyInfo property,
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            if (contentArea == null)
            {
                return(null);
            }
            var contentAreaItems = GetContentAreaItems(contentArea);

            if (WrapItems(contentArea, settings))
            {
                var items = new Dictionary <string, List <object> >();
                foreach (var item in contentAreaItems)
                {
                    var result   = this._propertyManager.GetStructuredData(item, settings);
                    var typeName = item.GetOriginalType().Name;
                    result.Add(settings.BlockTypePropertyName, typeName);
                    if (items.ContainsKey(typeName))
                    {
                        items[typeName].Add(result);
                    }
                    else
                    {
                        items[typeName] = new List <object> {
                            result
                        };
                    }
                }

                return(items);
            }
            else
            {
                var items = new List <object>();
                foreach (var item in contentAreaItems)
                {
                    var result = this._propertyManager.GetStructuredData(item, settings);
                    result.Add(settings.BlockTypePropertyName, item.GetOriginalType().Name);
                    items.Add(result);
                }

                return(items);
            }
        }
        public object Handle(
            ContentReference contentReference,
            PropertyInfo property,
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            if (contentReference == null || contentReference == ContentReference.EmptyReference)
            {
                return(null);
            }

            var url = new Uri(this._urlHelper.ContentUrl(contentReference, settings.UrlSettings));

            if (settings.UrlSettings.UseAbsoluteUrls && url.IsAbsoluteUri)
            {
                return(url.AbsoluteUri);
            }

            return(url.PathAndQuery);
        }
Ejemplo n.º 25
0
        public object Handle(
            IEnumerable <ContentReference> contentReferences,
            PropertyInfo property,
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            if (contentReferences == null)
            {
                return(null);
            }
            var links = new List <object>();

            foreach (var contentReference in contentReferences)
            {
                var result = this._contentReferencePropertyHandler.Handle(
                    contentReference,
                    property,
                    contentData,
                    settings);
                links.Add(result);
            }

            return(links);
        }
Ejemplo n.º 26
0
        public static string ToJson(this IContentData contentData, IContentSerializerSettings contentSerializerSettings)
        {
            var contentSerializer = GetContentJsonSerializer();

            return(contentSerializer.Serialize(contentData, contentSerializerSettings));
        }
Ejemplo n.º 27
0
 public StringListPropertyHandler(IContentSerializerSettings contentSerializerSettings)
 {
     _contentSerializerSettings = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings));
 }
 public string ToJson(IContentData contentData, IContentSerializerSettings settings)
 {
     return(this._contentSerializer.Serialize(contentData, settings));
 }
Ejemplo n.º 29
0
 public UrlPropertyHandler(IUrlHelper urlHelper, IContentSerializerSettings contentSerializerSettings)
 {
     _urlHelper = urlHelper ?? throw new ArgumentNullException(nameof(urlHelper));
     _contentSerializerSettings = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings));
 }
Ejemplo n.º 30
0
        public static string Serialize(this IContentData contentData, IContentSerializerSettings contentSerializerSettings)
        {
            var contentSerializer = ServiceLocator.Current.GetInstance <IContentSerializer>();

            return(contentSerializer.Serialize(contentData, contentSerializerSettings));
        }