예제 #1
0
        public IEnterspeedProperty Convert(IPublishedProperty property, string culture)
        {
            var value = property.GetValue <HtmlString>(culture).ToString();

            value = PrefixRelativeImagesWithDomain(value, _enterspeedConfigurationService.GetConfiguration().MediaDomain);
            return(new StringEnterspeedProperty(property.Alias, value));
        }
예제 #2
0
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var value = property.GetValue <string>();

            value = PrefixRelativeImagesWithDomain(value);
            return(new StringEnterspeedProperty(property.PropertyTypeAlias, value));
        }
예제 #3
0
        private string TdMntp(IPublishedProperty Property, bool FancyFormat)
        {
            var tableData = new StringBuilder();

            var items = Property.GetValue <IEnumerable <IPublishedContent> >().ToList();

            tableData.AppendLine($"<td>");

            if (items.Any())
            {
                //start list
                tableData.AppendLine($"<ol>");

                foreach (var item in items)
                {
                    tableData.AppendLine($"<li>{item.Name} ({item.DocumentTypeAlias})</li>");
                }

                //end list
                tableData.AppendLine($"</ol>");
            }
            else
            {
                tableData.AppendLine($"<i>No items added</i>");
            }

            tableData.AppendLine($"</td>");

            return(tableData.ToString());
        }
예제 #4
0
 public SerializableProperty(IPublishedProperty property)
 {
     this.DataValue = property.DataValue;
     //this.Value = property.Value;
     this.HasValue          = property.HasValue;
     this.PropertyTypeAlias = property.PropertyTypeAlias;
 }
        /// <inheritdoc />
        public bool TryGetValue <T>(IPublishedProperty property, string culture, string segment, Fallback fallback, T defaultValue, out T value)
        {
            _variationContextAccessor.ContextualizeVariation(property.PropertyType.Variations, ref culture, ref segment);

            foreach (var f in fallback)
            {
                switch (f)
                {
                case Fallback.None:
                    continue;

                case Fallback.DefaultValue:
                    value = defaultValue;
                    return(true);

                case Fallback.Language:
                    if (TryGetValueWithLanguageFallback(property, culture, segment, defaultValue, out value))
                    {
                        return(true);
                    }
                    break;

                default:
                    throw NotSupportedFallbackMethod(f, "property");
                }
            }

            value = defaultValue;
            return(false);
        }
예제 #6
0
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var value = property.GetValue <string>();

            value = _mediaUrlProvider.GetUrl(value);
            return(new StringEnterspeedProperty(property.PropertyTypeAlias, value));
        }
예제 #7
0
        public IEnterspeedProperty Convert(IPublishedProperty property, string culture)
        {
            var isMultiple = property.PropertyType.DataType.ConfigurationAs <MediaPickerConfiguration>().Multiple;
            var arrayItems = new List <IEnterspeedProperty>();

            if (isMultiple)
            {
                var items = property.GetValue <IEnumerable <IPublishedContent> >(culture);
                foreach (var item in items)
                {
                    var mediaObject = ConvertToEnterspeedProperty(item);
                    if (mediaObject != null)
                    {
                        arrayItems.Add(mediaObject);
                    }
                }
            }
            else
            {
                var item        = property.GetValue <IPublishedContent>(culture);
                var mediaObject = ConvertToEnterspeedProperty(item);
                if (mediaObject != null)
                {
                    arrayItems.Add(mediaObject);
                }
            }

            return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray()));
        }
        /// <summary>
        /// Handles the content service unpublished event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e"> The <see cref="PublishEventArgs{IContent}"/> containing information about the event.</param>
        private void ContentServiceUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            string        alias  = BloodhoundPropertyEditor.PropertyEditorAlias;
            UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);

            // Loop through the items and remove the url, value pair from the cache.
            foreach (IContent content in e.PublishedEntities)
            {
                IPublishedContent publishedVersion = helper.TypedContent(content.Id);

                IPublishedProperty rewriteProperties =
                    publishedVersion
                    .Properties
                    .FirstOrDefault(p => publishedVersion.ContentType.GetPropertyType(p.PropertyTypeAlias).PropertyEditorAlias.Equals(alias));

                if (rewriteProperties != null)
                {
                    List <BloodhoundUrlRewrite> rewrites = rewriteProperties.GetValue <List <BloodhoundUrlRewrite> >();
                    foreach (BloodhoundUrlRewrite rewrite in rewrites)
                    {
                        UrlRewriteCache.RemoveItem(rewrite.RewriteUrl);
                    }
                }
            }
        }
예제 #9
0
        public IEnterspeedProperty Convert(IPublishedProperty property, string culture)
        {
            var colorValue = string.Empty;
            var colorLabel = string.Empty;

            if (UseLabel(property.PropertyType))
            {
                var colorPickerValue = property.GetValue <ColorPickerValueConverter.PickedColor>(culture);
                colorValue = colorPickerValue.Color;
                colorLabel = colorPickerValue.Label;
            }
            else
            {
                colorValue = property.GetValue <string>(culture);
                colorLabel = colorValue;
            }

            var colorPickerProperties = new List <IEnterspeedProperty>
            {
                new StringEnterspeedProperty("color", colorValue),
                new StringEnterspeedProperty("label", colorLabel)
            };

            var properties = colorPickerProperties.ToDictionary(x => x.Name, x => x);

            return(new ObjectEnterspeedProperty(property.Alias, properties));
        }
예제 #10
0
 public SerializableProperty(IPublishedProperty property)
 {
     this.DataValue = property.DataValue;
     //this.Value = property.Value;
     this.HasValue = property.HasValue;
     this.PropertyTypeAlias = property.PropertyTypeAlias;
 }
예제 #11
0
		internal PropertyResult(IPublishedProperty source, PropertyResultType type)
        {
    		if (source == null) throw new ArgumentNullException("source");
            
            _type = type;
            _source = source;
        }
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var nodeIds    = property.GetValue <string>()?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var arrayItems = new List <IEnterspeedProperty>();

            if (nodeIds != null)
            {
                var umbracoHelper = UmbracoContextHelper.GetUmbracoHelper();
                foreach (var nodeId in nodeIds)
                {
                    var node = umbracoHelper.TypedContent(nodeId);

                    if (node == null)
                    {
                        node = umbracoHelper.TypedMember(nodeId);
                    }

                    if (node == null)
                    {
                        node = umbracoHelper.TypedMedia(nodeId);
                    }

                    var convertedNode = ConvertToEnterspeedProperty(node);
                    if (convertedNode != null)
                    {
                        arrayItems.Add(convertedNode);
                    }
                }
            }

            return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray()));
        }
예제 #13
0
        public IEnterspeedProperty Convert(IPublishedProperty property, string culture)
        {
            var value     = property.GetValue <IPublishedContent>(culture);
            var contentId = _entityIdentityService.GetId(value, culture);

            return(new StringEnterspeedProperty(property.Alias, contentId));
        }
예제 #14
0
 public JsonProjectModel(IPublishedProperty title, IPublishedProperty description, IPublishedProperty image, string url)
 {
     this.Title = title != null ? title.Value.ToString() : "";
     this.Description = description != null ? description.Value.ToString() : "";
     this.ImageUrl = image != null ? image.Value.ToString() : "";
     this.ProjectUrl = url;
 }
예제 #15
0
        public PublishedContent(
            ContentNode contentNode,
            ContentData contentData,
            IPublishedSnapshotAccessor publishedSnapshotAccessor,
            IVariationContextAccessor variationContextAccessor)
        {
            _contentNode = contentNode ?? throw new ArgumentNullException(nameof(contentNode));
            ContentData  = contentData ?? throw new ArgumentNullException(nameof(contentData));
            _publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
            VariationContextAccessor   = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));

            _urlSegment  = ContentData.UrlSegment;
            IsPreviewing = ContentData.Published == false;

            var properties = new IPublishedProperty[_contentNode.ContentType.PropertyTypes.Count()];
            int i          = 0;

            foreach (var propertyType in _contentNode.ContentType.PropertyTypes)
            {
                // add one property per property type - this is required, for the indexing to work
                // if contentData supplies pdatas, use them, else use null
                contentData.Properties.TryGetValue(propertyType.Alias, out var pdatas); // else will be null
                properties[i++] = new Property(propertyType, this, pdatas, _publishedSnapshotAccessor);
            }
            PropertiesArray = properties;
        }
    public async Task Lookup_By_Url_Alias(
        string relativeUrl,
        int nodeMatch,
        [Frozen] IPublishedContentCache publishedContentCache,
        [Frozen] IUmbracoContextAccessor umbracoContextAccessor,
        [Frozen] IUmbracoContext umbracoContext,
        [Frozen] IVariationContextAccessor variationContextAccessor,
        IFileService fileService,
        ContentFinderByUrlAlias sut,
        IPublishedContent[] rootContents,
        IPublishedProperty urlProperty)
    {
        // Arrange
        var absoluteUrl      = "http://localhost" + relativeUrl;
        var variationContext = new VariationContext();

        var contentItem = rootContents[0];

        Mock.Get(umbracoContextAccessor).Setup(x => x.TryGetUmbracoContext(out umbracoContext)).Returns(true);
        Mock.Get(umbracoContext).Setup(x => x.Content).Returns(publishedContentCache);
        Mock.Get(publishedContentCache).Setup(x => x.GetAtRoot(null)).Returns(rootContents);
        Mock.Get(contentItem).Setup(x => x.Id).Returns(nodeMatch);
        Mock.Get(contentItem).Setup(x => x.GetProperty(Constants.Conventions.Content.UrlAlias)).Returns(urlProperty);
        Mock.Get(urlProperty).Setup(x => x.GetValue(null, null)).Returns(relativeUrl);

        Mock.Get(variationContextAccessor).Setup(x => x.VariationContext).Returns(variationContext);
        var publishedRequestBuilder = new PublishedRequestBuilder(new Uri(absoluteUrl, UriKind.Absolute), fileService);

        // Act
        var result = await sut.TryFindContent(publishedRequestBuilder);

        Assert.IsTrue(result);
        Assert.AreEqual(publishedRequestBuilder.PublishedContent.Id, nodeMatch);
    }
        // tries to get a value, recursing the tree
        private static bool TryGetValueWithRecursiveFallback <T>(IPublishedContent content, string alias, string culture, string segment, T defaultValue, out T value)
        {
            IPublishedProperty property        = null; // if we are here, content's property has no value
            IPublishedProperty noValueProperty = null;

            do
            {
                content  = content.Parent;
                property = content?.GetProperty(alias);
                if (property != null)
                {
                    noValueProperty = property;
                }
            }while (content != null && (property == null || property.HasValue(culture, segment) == false));

            // if we found a content with the property having a value, return that property value
            if (property != null && property.HasValue(culture, segment))
            {
                value = property.Value <T>(culture, segment);
                return(true);
            }

            // if we found a property, even though with no value, return that property value
            // because the converter may want to handle the missing value. ie if defaultValue is default,
            // either specified or by default, the converter may want to substitute something else.
            if (noValueProperty != null)
            {
                value = noValueProperty.Value <T>(culture, segment, defaultValue: defaultValue);
                return(true);
            }

            value = defaultValue;
            return(false);
        }
예제 #18
0
        public IEnterspeedProperty Convert(IPublishedProperty property, string culture)
        {
            var isMultiple = property.PropertyType.DataType.ConfigurationAs <MultiUrlPickerConfiguration>().MaxNumber != 1;
            var arrayItems = new List <IEnterspeedProperty>();

            using (var context = _umbracoContextFactory.EnsureUmbracoContext())
            {
                if (isMultiple)
                {
                    var items = property.GetValue <IEnumerable <Link> >(culture);
                    if (items != null)
                    {
                        foreach (var item in items)
                        {
                            var linkObject = ConvertToEnterspeedProperty(item, context.UmbracoContext, culture);
                            if (linkObject != null)
                            {
                                arrayItems.Add(linkObject);
                            }
                        }
                    }
                }
                else
                {
                    var item       = property.GetValue <Link>(culture);
                    var linkObject = ConvertToEnterspeedProperty(item, context.UmbracoContext, culture);
                    if (linkObject != null)
                    {
                        arrayItems.Add(linkObject);
                    }
                }
            }

            return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray()));
        }
예제 #19
0
        public virtual bool HasValue(IPublishedProperty property, string culture, string segment)
        {
            // the default implementation uses the old magic null & string comparisons,
            // other implementations may be more clever, and/or test the final converted object values
            var value = property.GetSourceValue(culture, segment);

            return(value != null && (!(value is string) || string.IsNullOrWhiteSpace((string)value) == false));
        }
 void IPublishedContentExtended.AddProperty(IPublishedProperty property)
 {
     if (_properties == null)
     {
         _properties = new Collection <IPublishedProperty>();
     }
     _properties.Add(property);
 }
        public static T GetValue <T>(this IPublishedProperty property, string culture)
        {
            if (!property.PropertyType.VariesByCulture())
            {
                culture = null;
            }

            return((T)property.GetValue(culture));
        }
예제 #22
0
        private bool IsDashboardProperty(IPublishedProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            return(property.HasValue && property.Value.ToString().Contains("focusKeyword"));
        }
예제 #23
0
        internal PropertyResult(IPublishedProperty source, PropertyResultType type)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            _type   = type;
            _source = source;
        }
예제 #24
0
        private string GetFocusKeywordFromDashboardProperty(IPublishedProperty property)
        {
            var dashboardSettings = _javascriptSerializer.Deserialize <DashboardSettings>(property.Value.ToString());

            if (dashboardSettings != null && !string.IsNullOrEmpty(dashboardSettings.FocusKeyword))
            {
                return(dashboardSettings.FocusKeyword);
            }
            return(null);
        }
예제 #25
0
 public static NodeProperty ToNodeProperty(IPublishedProperty prop)
 {
     return(new NodeProperty
     {
         DataValue = prop.DataValue?.ToString(),
         HasValue = prop.HasValue,
         PropertyTypeAlias = prop.PropertyTypeAlias,
         Value = prop.Value?.ToString()
     });
 }
        public override IPublishedProperty GetProperty(string alias, bool recurse)
        {
            IPublishedProperty property = GetProperty(alias);

            if (recurse && Parent != null && (property == null || false == property.HasValue))
            {
                return(Parent.GetProperty(alias, true));
            }
            return(property);
        }
예제 #27
0
    public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedProperty property, string framework = "bootstrap3")
    {
        if (property.GetValue() is string asString && string.IsNullOrEmpty(asString))
        {
            return(new HtmlString(string.Empty));
        }

        var view = "grid/" + framework;

        return(html.Partial(view, property.GetValue()));
    }
예제 #28
0
        public static MvcHtmlString LayoutEditor(this HtmlHelper html, IPublishedContent model, string alias)
        {
            IPublishedProperty property = model.GetProperty(alias);

            if (property == null || !property.HasValue)
            {
                return(null);
            }

            return(html.Partial("LayoutEditor/_Layout", property.Value));
        }
예제 #29
0
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var value = property.GetValue <string>();

            if (DateTime.TryParse(value, out var date) && date == default)
            {
                value = null;
            }

            return(new StringEnterspeedProperty(property.PropertyTypeAlias, value));
        }
예제 #30
0
        public IPublishedProperty GetProperty(string alias, bool recurse)
        {
            IPublishedProperty prop = this.Properties.SingleOrDefault(p => p.PropertyTypeAlias.InvariantEquals(alias));

            if (prop == null && recurse && this.Parent != null)
            {
                return(this.Parent.GetProperty(alias, true));
            }

            return(prop);
        }
    public static object?Value(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string?culture = null, string?segment = null, Fallback fallback = default, object?defaultValue = default)
    {
        if (property.HasValue(culture, segment))
        {
            return(property.GetValue(culture, segment));
        }

        return(publishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var value)
            ? value
            : property.GetValue(culture, segment)); // give converter a chance to return it's own vision of "no value"
    }
        public IEnterspeedProperty Convert(IPublishedProperty property, string culture)
        {
            var value      = property.GetValue <IEnumerable <string> >(culture);
            var arrayItems = new List <IEnterspeedProperty>();

            foreach (var item in value)
            {
                arrayItems.Add(new StringEnterspeedProperty(item));
            }

            return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray()));
        }
        /// <summary>
        /// Add linked Node to result list
        /// </summary>
        /// <param name="list">List with already linked Nodes</param>
        /// <param name="node">Content Node to check</param>
        /// <param name="relatedNode">linked Node (if picker contains single item)</param>
        /// <param name="prop">Property to check</param>
        /// <param name="nodePath">Complete node Path</param>
        /// <param name="currentUdi">UDI from current Content Node</param>
        /// <param name="relatedUdi">UDI of linked Node</param>
        /// <returns>List of LinkedNodesDataModel</returns>
        private List <LinkedNodesDataModel> AddRelatedNode(List <LinkedNodesDataModel> list, IPublishedContent node, IPublishedContent relatedNode,
                                                           IPublishedProperty prop, string nodePath, string currentUdi, string relatedUdi = "")
        {
            string nodeUdi = string.Empty;

            if (relatedNode != null)
            {
                if (relatedNode.ItemType == PublishedItemType.Media)
                {
                    nodeUdi = "umb://media/" + relatedNode.Key.ToString().Replace("-", string.Empty);
                }
                else
                {
                    nodeUdi = "umb://document/" + relatedNode.Key.ToString().Replace("-", string.Empty);
                }
            }

            if ((relatedNode != null && nodeUdi == currentUdi) || relatedUdi == currentUdi)
            {
                LinkedNodesDataModel result;

                if (_listWithProperties)
                {
                    // if Property Alias is used in Content App overview table
                    // Prevent duplicate property aliases
                    result = list.FirstOrDefault(x => x.Id == node.Id && x.PropertyAlias == prop.Alias);
                }
                else
                {
                    // Prevent duplicate nodes
                    result = list.FirstOrDefault(x => x.Id == node.Id);
                }

                if (result == null)
                {
                    // Add new linked Node if not exist in list
                    list.Add(new LinkedNodesDataModel()
                    {
                        Id                  = node.Id,
                        Name                = node.Name,
                        PropertyAlias       = prop.Alias,
                        Path                = nodePath,
                        RelLinkCountPerProp = 1
                    });
                }
                else
                {
                    // Add not linked Node, but add 1 to existed linked Node counter (using by badge in content app overview table)
                    result.RelLinkCountPerProp = result.RelLinkCountPerProp + 1;
                }
            }
            return(list);
        }
        /// <summary>
        /// Gets the HTML for the Grid model based on the specified <code>framework</code>.
        /// </summary>
        /// <param name="html">The instance of <code>HtmlHelper</code>.</param>
        /// <param name="property">The property holding the Grid model.</param>
        /// <param name="framework">The framework used to render the Grid.</param>
        public static HtmlString GetTypedGridHtml(this HtmlHelper html, IPublishedProperty property, string framework = DefaultFramework) {

            // Get the property value
            GridDataModel value = property.Value as GridDataModel;
            if (value == null) return new HtmlString(String.Empty);

            // Load the partial view based on the specified framework
            return html.Partial("TypedGrid/" + framework, property.Value);
        
        }
 void IPublishedContentExtended.AddProperty(IPublishedProperty property)
 {
     if (_properties == null)
         _properties = new Collection<IPublishedProperty>();
     _properties.Add(property);
 }
 public object Convert(IPublishedProperty property, IPublishedContent owner)
 {
     var htmlString = property.Value as HtmlString;
     return htmlString != null ? htmlString.ToHtmlString() : string.Empty;
 }
 public object Convert(IPublishedProperty property, IPublishedContent owner)
 {
     return ContentSerializer.Instance.Serialize(new UmbracoHelper(UmbracoContext.Current).TypedContent(property.Value));
 }
예제 #38
0
 private static IProperty ConvertToNodeProperty(IPublishedProperty prop)
 {
     return new ConvertedProperty(prop);
 }
        private object ConvertProperty(IPublishedProperty property, IPublishedContent owner, PublishedContentType contentType)
        {
            string editorAlias = contentType.GetPropertyType(property.PropertyTypeAlias).PropertyEditorAlias;
            
            // Property converter exist
            if (PropertyConverters.ContainsKey(editorAlias))
            {
                return PropertyConverters[editorAlias].Convert(property, owner);
            }

            return property.Value;
        }
예제 #40
0
 public ConvertedProperty(IPublishedProperty prop)
 {
     _prop = prop;
 }