示例#1
0
        private string GetUploadFieldAlias(IContentBase node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var uploadFields = GetUploadFieldAliases().ToList();

            if (!uploadFields.Any(f => !string.IsNullOrEmpty(f) && node.HasProperty(f)))
            {
                throw new Exception(string.Format("Could not determine uploadField alias for node with id: {0}", node.Id));
            }

            return(uploadFields.First(f => !string.IsNullOrEmpty(f) && node.HasProperty(f)));
        }
示例#2
0
        private string GetUploadFieldAlias(IContentBase node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var uploadFieldNodes = umbraco.UmbracoSettings._umbracoSettings.SelectNodes("/content/imaging/autoFillImageProperties/uploadField");

            if (uploadFieldNodes == null)
            {
                throw new ConfigurationErrorsException("Expected /content/imaging/autoFillImageProperties/uploadField element");
            }

            foreach (XmlNode uploadFieldNode in uploadFieldNodes)
            {
                if (uploadFieldNode.Attributes != null && uploadFieldNode.Attributes["alias"] != null)
                {
                    var alias = uploadFieldNode.Attributes["alias"].Value;
                    if (node.HasProperty(alias))
                    {
                        return(uploadFieldNode.Attributes["alias"].Value);
                    }
                }
            }

            throw new Exception(string.Format("Could not determine uploadField alias for node with id: {0}. Either something went wrong with the Conveyor export/import or the uploadField alias could not be determined from the umbracoSettings.config", node.Id));
        }
 private static string GetUrlSegmentSource(IContentBase content)
 {
     string source = null;
     if (content.HasProperty(Constants.Conventions.Content.UrlName))
         source = (content.GetValue<string>(Constants.Conventions.Content.UrlName) ?? string.Empty).Trim();
     if (string.IsNullOrWhiteSpace(source))
         source = content.Name;
     return source;
 }
        /// <summary>
        /// Finds the property alias of the property where files are uploaded
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private string GetUploadFieldAlias(IContentBase node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var uploadFields = UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties.ToList();

            if (uploadFields == null || uploadFields.All(f => string.IsNullOrEmpty(f.Alias)))
            {
                throw new ConfigurationErrorsException("Expected /content/imaging/autoFillImageProperties/uploadField alias attribute");
            }

            if (!uploadFields.Any(f => !string.IsNullOrEmpty(f.Alias) && node.HasProperty(f.Alias)))
            {
                throw new Exception(string.Format("Could not determine uploadField alias for node with id: {0}", node.Id));
            }

            return(uploadFields.First(f => !string.IsNullOrEmpty(f.Alias) && node.HasProperty(f.Alias)).Alias);
        }
示例#5
0
        private static string GetUrlSegmentSource(IContentBase content, string culture)
        {
            string source = null;

            if (content.HasProperty(Constants.Conventions.Content.UrlName))
            {
                source = (content.GetValue <string>(Constants.Conventions.Content.UrlName, culture) ?? string.Empty).Trim();
            }
            if (string.IsNullOrWhiteSpace(source))
            {
                source = content.GetCultureName(culture);
            }
            return(source);
        }
        protected override IDictionary <string, object> ResolveCore(IContentBase content)
        {
            var d = new Dictionary <string, object>();

            foreach (var propertyType in content.PropertyTypes)
            {
                var prop = content.HasProperty(propertyType.Alias) ? content.Properties[propertyType.Alias] : null;
                if (prop != null)
                {
                    d.Add(propertyType.Alias, prop.Value);
                }
            }
            return(d);
        }
        public string GetUrlSegment(IContentBase content)
        {
            if (!content.HasProperty(PropertyName)) return null;

            try
            {
                var metadata = JsonConvert.DeserializeObject<SeoMetadata>(content.GetValue<string>(PropertyName));
                if (metadata == null || String.IsNullOrWhiteSpace(metadata.UrlName)) return null;
                return metadata.UrlName.ToUrlSegment();
            }
            catch
            {
                return null;
            }
        }
 public string GetUrlSegment(IContentBase content)
 {
     if (!content.HasProperty(PropertyName))
     {
         return(null);
     }
     try
     {
         var seoMetadata = JsonConvert.DeserializeObject <SeoMetaData>(content.GetValue <string>(PropertyName));
         return(string.IsNullOrWhiteSpace(seoMetadata?.UrlName) ? null : seoMetadata.UrlName.ToUrlSegment());
     }
     catch
     {
         return(null);
     }
 }
        /// <summary>
        ///  second pass ID update in properties?
        /// </summary>
        /// <param name="node"></param>
        /// <param name="item"></param>
        public void DeserializeMappedIds(T baseItem, XElement node)
        {
            IContentBase item       = (IContentBase)baseItem;
            var          properties = node.Elements().Where(x => x.Attribute("isDoc") == null);

            foreach (var property in properties)
            {
                var propertyTypeAlias = property.Name.LocalName;
                if (item.HasProperty(propertyTypeAlias))
                {
                    var    prop     = item.Properties[propertyTypeAlias];
                    string newValue = GetImportIds(prop.PropertyType, GetImportXml(property));
                    LogHelper.Debug <Events>("#### BASE: Setting property: [{0}] to {1}", () => propertyTypeAlias, () => newValue);
                    item.SetValue(propertyTypeAlias, newValue);
                }
            }
        }
示例#10
0
        private static string GetUrlSegmentSource(IContentBase content, string culture)
        {
            string source = null;

            if (content.HasProperty(Constants.Conventions.Content.UrlName))
            {
                source = (content.GetValue <string>(Constants.Conventions.Content.UrlName, culture) ?? string.Empty).Trim();
            }
            if (string.IsNullOrWhiteSpace(source))
            {
                // If the name of a node has been updated, but it has not been published, the url should use the published name, not the current node name
                // If this node has never been published (GetPublishName is null), use the unpublished name
                source = (content is IContent document) && document.Edited && document.GetPublishName(culture) != null
                    ? document.GetPublishName(culture)
                    : content.GetCultureName(culture);
            }
            return(source);
        }
 private static void SetPropertyValue(IContentBase content, XmlNode uploadFieldConfigNode, string propertyAlias, string propertyValue)
 {
     XmlNode propertyNode = uploadFieldConfigNode.SelectSingleNode(propertyAlias);
     if (propertyNode != null && string.IsNullOrEmpty(propertyNode.FirstChild.Value) == false && content.HasProperty(propertyNode.FirstChild.Value))
     {
         content.SetValue(propertyNode.FirstChild.Value, propertyValue);
     }
 }
示例#12
0
        private static void SetPropertyValue(IContentBase content, XmlNode uploadFieldConfigNode, string propertyAlias, string propertyValue)
        {
            XmlNode propertyNode = uploadFieldConfigNode.SelectSingleNode(propertyAlias);

            if (propertyNode != null && string.IsNullOrEmpty(propertyNode.FirstChild.Value) == false && content.HasProperty(propertyNode.FirstChild.Value))
            {
                content.SetValue(propertyNode.FirstChild.Value, propertyValue);
            }
        }
示例#13
0
        private Document FromUmbracoContentBase(Document c, IContentBase content, SearchField[] searchFields)
        {
            c.Add("ContentTypeId", content.ContentTypeId);
            c.Add("CreateDate", content.CreateDate);
            c.Add("CreatorId", content.CreatorId);

            foreach (var field in searchFields)
            {
                if (!content.HasProperty(field.Name) || content.Properties[field.Name].Value == null)
                {
                    if (field.Type == "collection")
                    {
                        c.Add(field.Name, new List <string>());
                    }

                    if (field.Type == "string")
                    {
                        c.Add(field.Name, string.Empty);
                    }

                    if (field.Type == "int")
                    {
                        c.Add(field.Name, 0);
                    }

                    if (field.Type == "bool")
                    {
                        c.Add(field.Name, false);
                    }
                }
                else
                {
                    var value = content.Properties[field.Name].Value;

                    if (field.Type == "collection")
                    {
                        if (!string.IsNullOrEmpty(value.ToString()))
                        {
                            c.Add(field.Name, value.ToString().Split(','));
                        }
                    }
                    else
                    {
                        if (field.IsGridJson)
                        {
                            // #filth #sorrymarc
                            JObject jObject = JObject.Parse(value.ToString());
                            var     tokens  = jObject.SelectTokens("..value");

                            try
                            {
                                var values = tokens.Where(x => x != null).Select(x => (x as JValue).Value);
                                value = string.Join(" ", values);
                                value = Regex.Replace(value.ToString(), "<.*?>", String.Empty);
                                value = value.ToString().Replace(Environment.NewLine, " ");
                                value = value.ToString().Replace(@"\n", " ");
                            }
                            catch (Exception ex)
                            {
                                value = string.Empty;
                            }
                        }

                        c.Add(field.Name, value);
                    }
                }
            }

            return(c);
        }
示例#14
0
        private Document FromUmbracoContent(IContentBase content, SearchField[] searchFields)
        {
            var c = new Document
            {
                { "Id", content.Id.ToString() },
                { "Name", content.Name },
                { "SortOrder", content.SortOrder },
                { "Level", content.Level },
                { "Path", content.Path.Split(',') },
                { "ParentId", content.ParentId },
                { "UpdateDate", content.UpdateDate },
                { "Trashed", content.Trashed },
                { "Key", content.Key.ToString() }
            };

            bool cancelIndex = AzureSearch.FireContentIndexing(
                new AzureSearchEventArgs()
            {
                Item  = content,
                Entry = c
            });

            if (cancelIndex)
            {
                // cancel was set in an event, so we don't index this item.
                return(null);
            }

            c.Add("ContentTypeId", content.ContentTypeId);
            c.Add("CreateDate", content.CreateDate);
            c.Add("CreatorId", content.CreatorId);

            foreach (var field in searchFields)
            {
                if (!content.HasProperty(field.Name) || content.Properties[field.Name].Value == null)
                {
                    if (field.Type == "collection")
                    {
                        c.Add(field.Name, new List <string>());
                    }

                    if (field.Type == "string")
                    {
                        c.Add(field.Name, string.Empty);
                    }

                    if (field.Type == "int")
                    {
                        c.Add(field.Name, 0);
                    }

                    if (field.Type == "bool")
                    {
                        c.Add(field.Name, false);
                    }
                }
                else
                {
                    var value = content.Properties[field.Name].Value;

                    if (field.Type == "collection")
                    {
                        if (!string.IsNullOrEmpty(value.ToString()))
                        {
                            c.Add(field.Name, value.ToString().Split(','));
                        }
                    }
                    else
                    {
                        if (field.IsGridJson)
                        {
                            // #filth #sorrymarc
                            JObject jObject = JObject.Parse(value.ToString());
                            var     tokens  = jObject.SelectTokens("..value");

                            try
                            {
                                var values = tokens.Where(x => x != null).Select(x => (x as JValue).Value);
                                value = string.Join(" ", values);
                                value = Regex.Replace(value.ToString(), "<.*?>", String.Empty);
                                value = value.ToString().Replace(Environment.NewLine, " ");
                                value = value.ToString().Replace(@"\n", " ");
                            }
                            catch (Exception ex)
                            {
                                value = string.Empty;
                            }
                        }

                        c.Add(field.Name, value);
                    }
                }
            }

            AzureSearch.FireContentIndexed(
                new AzureSearchEventArgs()
            {
                Item  = content,
                Entry = c
            });

            return(c);
        }
示例#15
0
        private Document GetDocumentToIndex(IContentBase content, SearchField[] searchFields)
        {
            try
            {
                var c = new Document();

                var type = content.GetType();

                foreach (var field in GetStandardUmbracoFields())
                {
                    try
                    {
                        object propertyValue = null;

                        // handle special case properties
                        switch (field.Name)
                        {
                        case "SearchablePath":
                            propertyValue = content.Path.TrimStart('-');
                            break;

                        case "Path":
                            propertyValue = content.Path.Split(',');
                            break;

                        case "CreatorName":
                            propertyValue = content.GetCreatorProfile(UmbracoContext.Current.Application.Services.UserService).Name;
                            break;

                        case "ParentID":
                            propertyValue = content.ParentId;
                            break;

                        default:
                            // try get model property
                            PropertyInfo modelProperty;
                            if (!_propertyCache.ContainsKey(type.Name))
                            {
                                _propertyCache[type.Name] = new Dictionary <string, PropertyInfo>();
                            }

                            var cache = _propertyCache[type.Name];

                            if (cache.ContainsKey(field.Name))
                            {
                                modelProperty = cache[field.Name];
                            }
                            else
                            {
                                modelProperty     = type.GetProperty(field.Name);
                                cache[field.Name] = modelProperty;
                            }

                            if (modelProperty != null)
                            {
                                propertyValue = modelProperty.GetValue(content);
                            }
                            else
                            {
                                // try get umbraco property
                                if (content.HasProperty(field.Name))
                                {
                                    propertyValue = content.GetValue(field.Name);
                                }
                            }
                            break;
                        }

                        // handle datatypes
                        switch (field.Type.ToString())
                        {
                        case "Edm.String":
                            propertyValue = propertyValue?.ToString();
                            break;

                        case "Edm.Boolean":
                            bool.TryParse((propertyValue ?? "False").ToString(), out var val);
                            propertyValue = val;
                            break;
                        }

                        if (propertyValue?.ToString().IsNullOrWhiteSpace() == false)
                        {
                            c[field.Name] = propertyValue;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }

                switch (type.Name)
                {
                case "Media":
                    c["IsMedia"] = true;
                    break;

                case "Content":
                    c["IsContent"] = true;
                    break;

                case "Member":
                    c["IsMember"] = true;
                    break;
                }

                bool cancelIndex = AzureSearch.FireContentIndexing(
                    new AzureSearchEventArgs()
                {
                    Item  = content,
                    Entry = c
                });

                if (cancelIndex)
                {
                    // cancel was set in an event, so we don't index this item.
                    return(null);
                }

                var umbracoFields  = searchFields.Where(x => !x.IsComputedField()).ToArray();
                var computedFields = searchFields.Where(x => x.IsComputedField()).ToArray();

                c = FromUmbracoContentBase(c, content, umbracoFields);
                c = FromComputedFields(c, content, computedFields);

                // todo: content isn't actually indexed at this point, consider moving the event to the callback from azure after sending to index
                AzureSearch.FireContentIndexed(
                    new AzureSearchEventArgs()
                {
                    Item  = content,
                    Entry = c
                });

                return(c);
            }
            catch (Exception ex)
            {
                throw;
            }
        }