示例#1
0
        private static string contentReplace(string content, IContentBase entity)
        {
            var    ptypes          = entity.PropertyTypes;
            string contenttypename = ApplicationContext.Current.Services.EntityService.Get(entity.ContentTypeId, true).Name;

            foreach (var ptype in ptypes)
            {
                PreValueCollection coll = ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(ptype.DataTypeDefinitionId);
                if (coll.PreValuesAsDictionary.Count == 0)
                {
                    string value = entity.GetValue <string>(ptype.Alias);

                    content = content.Replace("{{" + contenttypename + "." + ptype.Alias + "}}", entity.GetValue <string>(ptype.Alias));
                }
                else
                {
                    foreach (var item in coll.PreValuesAsDictionary)
                    {
                        var kk = entity.GetValue <int>(ptype.Alias);
                        if (item.Value.Id.Equals(entity.GetValue <int>(ptype.Alias)))
                        {
                            string strval = item.Value.Value;
                            content = content.Replace("{{" + contenttypename + "." + ptype.Alias + "}}", strval);
                        }
                    }
                }
            }
            return(content);
        }
        /// <summary>
        /// Gets the url segment for a specified content and culture.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="culture">The culture.</param>
        /// <returns>
        /// The url segment.
        /// </returns>
        /// <remarks>
        /// This is for when Umbraco is capable of managing more than one url
        /// per content, in 1-to-1 multilingual configurations. Then there would be one
        /// url per culture.
        /// </remarks>
        public string GetUrlSegment(IContentBase content, CultureInfo culture)
        {
            if (content.GetContentType().Alias != "realEstate")
            {
                return(null);
            }

            var segment = _provider.GetUrlSegment(content);

            return($"{content.GetValue("type")}-{content.GetValue<string>("city")}-{segment}".ToUrlSegment());
        }
示例#3
0
        public static IEmailServer EmailService()
        {
            IContentBase home     = Services.ContentService.GetById(Config[EnvKey.HomeId]);
            var          host     = (string)home.GetValue("emailHost");
            var          ports    = G.Int32((string)home.GetValue("emailPort"), 0);
            var          user     = (string)home.GetValue("emailUser");
            var          password = (string)home.GetValue("emailPassword");
            var          ssl      = G.ToBool(home.GetValue("emailSsl"));
            IEmailServer es       = new SPXEmailServer(host, ports, user, password, ssl);

            return(es);
        }
示例#4
0
        internal static void AutoPopulateFileMetaDataProperties(this IContentBase model, string propertyAlias, string relativefilePath = null)
        {
            var mediaFileSystem       = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>();
            var uploadFieldConfigNode =
                UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties
                .FirstOrDefault(x => x.Alias == propertyAlias);

            if (uploadFieldConfigNode != null && model.Properties.Contains(propertyAlias))
            {
                if (relativefilePath == null)
                {
                    relativefilePath = model.GetValue <string>(propertyAlias);
                }

                //now we need to check if there is a path
                if (!string.IsNullOrEmpty(relativefilePath))
                {
                    var fullPath    = mediaFileSystem.GetFullPath(mediaFileSystem.GetRelativePath(relativefilePath));
                    var umbracoFile = new UmbracoMediaFile(fullPath);
                    FillProperties(uploadFieldConfigNode, model, umbracoFile);
                }
                else
                {
                    //for now I'm just resetting this
                    ResetProperties(uploadFieldConfigNode, model);
                }
            }
        }
 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;
 }
示例#6
0
        public string GetUrlSegment(IContentBase content, string culture = null)
        {
            if (content.ContentType.Alias != "productPage")
            {
                return(null);
            }
            var segment    = provider.GetUrlSegment(content, culture);
            var productSku = content.GetValue(propertyTypeAlias: "productSku", culture: culture, segment: null, published: true);

            return(string.Format("{0}-{1}", segment, productSku));
        }
        private async Task ImportFirstImageAsync(IContentBase postNode, BlogMLPost post)
        {
            var imageMimeTypes = new List <string> {
                "image/jpeg", "image/gif", "image/png"
            };

            var attachment = post.Attachments.FirstOrDefault(p => imageMimeTypes.Contains(p.MimeType));

            if (attachment == null)
            {
                return;
            }

            var imageSaved = false;

            if (!attachment.Content.IsNullOrWhiteSpace())
            {
                //the image is base64
                var bytes = Convert.FromBase64String(attachment.Content);
                using (var stream = new MemoryStream(bytes))
                {
                    postNode.SetValue(_contentTypeBaseServiceProvider, "postImage", attachment.Url.OriginalString, stream);
                    imageSaved = true;
                }
            }
            else if (attachment.ExternalUri != null && attachment.ExternalUri.IsAbsoluteUri)
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        using (var stream = await client.GetStreamAsync(attachment.ExternalUri))
                        {
                            postNode.SetValue(_contentTypeBaseServiceProvider, "postImage", Path.GetFileName(attachment.ExternalUri.AbsolutePath), stream);
                            imageSaved = true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    _logger.Error <BlogMlImporter>(exception, "Exception retrieving {AttachmentUrl}; post {PostId}", attachment.Url, post.Id);
                }
            }

            if (imageSaved)
            {
                //this is a work around for the SetValue method to save a file, since it doesn't currently take into account the image cropper
                //which we are using so we need to fix that.

                var propType     = postNode.Properties["postImage"].PropertyType;
                var cropperValue = CreateImageCropperValue(propType, postNode.GetValue("postImage"), _dataTypeService);
                postNode.SetValue("postImage", cropperValue);
            }
        }
示例#8
0
 private void InjectTagsWithoutComma(IndexingNodeDataEventArgs e, IContentBase node)
 {
     foreach (var prop in node.PropertyTypes.Where(p => p.PropertyEditorAlias == Constants.PropertyEditors.TagsAlias))
     {
         var prevalues = prop.GetPrevalues();
         if (prevalues["storageType"].Value.ToLower() == "json")
         {
             dynamic       values    = JsonConvert.DeserializeObject(node.GetValue <string>(prop.Alias));
             StringBuilder newValues = new StringBuilder();
             foreach (var value in values)
             {
                 newValues.AppendLine(value.ToString());
             }
             e.Fields.Add("_" + prop.Alias, newValues.ToString());
         }
         else
         {
             e.Fields.Add("_" + prop.Alias, node.GetValue <string>(prop.Alias).Replace(",", " "));
         }
     }
 }
示例#9
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);
        }
        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 != null)
            {
                var contentType = Services.ContentTypeService.GetContentType(content.ContentTypeId);
                if (contentType != null && contentType.Alias == "Vacancyitem")
                {
                    //This will add the level before the node name.
                    //For example /developer/ becomes /junior-developer/
                    var level = content.GetValue <VacancyLevel>("level");
                    return(level.ToString().ToUrlSegment() + "-" + content.Name.ToUrlSegment());
                }
            }

            return(null);
        }
        public string GetUrlSegment(IContentBase content)
        {
            if (content != null)
            {
                var contentType = Services.ContentTypeService.GetContentType(content.ContentTypeId);
                if (contentType != null && contentType.Alias == "Vacancyitem")
                {
                    //This will add the level before the node name.
                    //For example /developer/ becomes /junior-developer/
                    var level = content.GetValue<VacancyLevel>("level");
                    return level.ToString().ToUrlSegment() + "-" + content.Name.ToUrlSegment();
                }
            }

            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);
     }
 }
示例#14
0
        public string GetUrlSegment(IContentBase content, CultureInfo culture)
        {
            // only for product doctypes
            var productContentType = PublishedContentModels.Product.ModelTypeAlias;

            if (content.GetContentType().Alias != productContentType)
            {
                return(null);
            }

            var segment = _provider.GetUrlSegment(content);

            // Watch the "ToUrlSegment()"
            var productName = content.GetValue <string>("productName")?.ToUrlSegment();

            return($"{segment}-{productName}");
        }
示例#15
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);
        }
示例#16
0
        /// <summary>
        /// Sets the default value.
        /// </summary>
        /// <param name="content">The content to set default values for.</param>
        /// <param name="model">The model.</param>
        private static void SetDefaultValue(IContentBase content, PropertyType model)
        {
            if (!model.HasDefaultValue)
            {
                return;
            }

            var value = content.GetValue(model.Alias);

            if (value != null)
            {
                return;
            }

            if (!CanSetDefaultValue(model.Type, model.DefaultValue))
            {
                return;
            }

            content.SetValue(model.Alias, model.DefaultValue);
        }
示例#17
0
        /// <summary>
        /// Munge the fields into a new one identified by key for searching.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="node"></param>
        /// <param name="key"></param>
        /// <param name="fields"></param>
        private void AggregateFields(IndexingNodeDataEventArgs e, IContentBase node, string key, string[] fields)
        {
            var combinedFields = new StringBuilder();

            foreach (var prop in node.PropertyTypes.Where(p => fields.Contains(p.Alias)))
            {
                switch (prop.PropertyEditorAlias)
                {
                // We want to attempt to retrieve the relevant fields from the properties that return JSON content.
                case Constants.PropertyEditors.NestedContentAlias:
                case "Our.Umbraco.StackedContent":
                {
                    var editor = PropertyEditorResolver.Current.GetByAlias(prop.PropertyEditorAlias).ValueEditor;
                    var scJson = editor.ConvertDbToEditor(node.Properties.Single(p => p.Alias == prop.Alias),
                                                          prop,
                                                          ApplicationContext.Current.Services.DataTypeService) as JToken;
                    combinedFields.AppendLine(IndexNestedJObject(scJson, fields));
                    break;
                }

                case Constants.PropertyEditors.GridAlias:
                {
                    var editor   = PropertyEditorResolver.Current.GetByAlias(prop.PropertyEditorAlias).ValueEditor;
                    var gridJson = editor.ConvertDbToEditor(node.Properties.Single(p => p.Alias == prop.Alias),
                                                            prop,
                                                            ApplicationContext.Current.Services.DataTypeService) as JToken;
                    combinedFields.AppendLine(IndexNestedJObject(gridJson, new[] { "value", "caption" }));
                    break;
                }

                default:
                    combinedFields.AppendLine(node.GetValue <string>(prop.Alias));
                    break;
                }
            }
            e.Fields.Add(key, combinedFields.ToString());
        }
示例#18
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;
            }
        }
        private void CopyPropertyValueToModel(IContentBase content, object objectInstance, PropertyRegistration registration)
        {
            var umbracoStoredValue = content.GetValue(registration.Alias);

            SetPropertyValueOnModel(objectInstance, registration, umbracoStoredValue);
        }
示例#20
0
        private static string contentReplace(string content, IContentBase entity)
        {
            var ptypes = entity.PropertyTypes;
            string contenttypename = ApplicationContext.Current.Services.EntityService.Get(entity.ContentTypeId, true).Name;

            foreach (var ptype in ptypes)
            {
                PreValueCollection coll = ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(ptype.DataTypeDefinitionId);
                if (coll.PreValuesAsDictionary.Count == 0)
                {
                    string value = entity.GetValue<string>(ptype.Alias);

                    content = content.Replace("{{" + contenttypename + "." + ptype.Alias + "}}", entity.GetValue<string>(ptype.Alias));
                }
                else
                {

                    foreach (var item in coll.PreValuesAsDictionary)
                    {
                        var kk = entity.GetValue<int>(ptype.Alias);
                        if (item.Value.Id.Equals(entity.GetValue<int>(ptype.Alias)))
                        {
                            string strval = item.Value.Value;
                            content = content.Replace("{{" + contenttypename + "." + ptype.Alias + "}}", strval);
                        }
                    }
                }

            }
            return content;
        }
示例#21
0
 private void ExtractAuthorData(IndexingNodeDataEventArgs e, IContentBase node)
 {
     // Munge the author for searching.
     foreach (var prop in node.PropertyTypes.Where(p => p.Alias == "author"))
     {
         var authorNode = ApplicationContext.Current.Services.ContentService.GetById(node.GetValue <Guid>(prop.Alias));
         if (authorNode != null)
         {
             StringBuilder authorString = new StringBuilder();
             authorString.AppendLine(authorNode.Name);
             foreach (var authorProp in authorNode.Properties.AsEnumerable())
             {
                 authorString.AppendLine($" {authorProp.Value}");
             }
             e.Fields.Add("_" + prop.Alias, authorString.ToString());
         }
     }
 }