Exemplo n.º 1
0
        private string GetRecursiveValue(ICmsContent content, string propertyname, IPropertyParser parser)
        {
            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Property {0} is set as recursive, searching ancestors for node {1}", (object)propertyname, (object)content.Name), (Exception)null);
            string str = string.Empty;

            if (content.ParentId < 0)
            {
                return(str);
            }
            for (ICmsContent cmsContent = this.cmsIndexer.GetContentById(content.ParentId); cmsContent != null && cmsContent.Id != this.cmsIndexer.CmsRootId; cmsContent = this.cmsIndexer.GetParent(cmsContent))
            {
                ICmsProperty property = this.cmsIndexer.GetProperty(cmsContent, propertyname);
                if (property != null && !string.IsNullOrEmpty(property.Value as string))
                {
                    str = parser.GetPropertyValue(property.Value);
                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Found recursive value {0} for property {1} on node {2}", (object)str, (object)propertyname, (object)cmsContent.Name), (Exception)null);
                    break;
                }
            }
            return(str);
        }
        public CategorySeedingTask(uint count, ICmsContent cmsContent) : base(count)
        {
            _cmsContent    = cmsContent;
            _faker         = new Faker();
            _categoryFaker = new Faker <UCommerceCategory>()
                             .RuleFor(x => x.Deleted, f => f.Random.Bool(0.001f))
                             .RuleFor(x => x.Guid, f => f.Random.Guid())
                             .RuleFor(x => x.Name, f => $"{f.Commerce.ProductAdjective()} {f.Commerce.ProductMaterial()}")
                             .RuleFor(x => x.CreatedBy, f => f.Name.FullName())
                             .RuleFor(x => x.CreatedOn, f => f.Date.Past())
                             .RuleFor(x => x.ModifiedBy, f => f.Name.FullName())
                             .RuleFor(x => x.DisplayOnSite, f => f.Random.Bool(0.85f))
                             .RuleFor(x => x.ModifiedOn, f => f.Date.Recent());

            _categoryPropertyFaker = new Faker <UCommerceCategoryProperty>()
                                     .RuleFor(x => x.Guid, f => f.Random.Guid());

            _descriptionFaker = new Faker <UCommerceCategoryDescription>()
                                .RuleFor(x => x.Description, f => f.Lorem.Text())
                                .RuleFor(x => x.Guid, f => f.Random.Guid())
                                .RuleFor(x => x.RenderAsContent, f => f.Random.Bool(0.75f));
        }
Exemplo n.º 3
0
 public T GetPropertyValue <T>(ICmsContent cmsNode, string propertyName)
 {
     return(((ContentBase)(cmsNode.NativeNodeObject as Content)).GetValue <T>(propertyName));
 }
Exemplo n.º 4
0
 public IEnumerable <ICmsContent> GetDescendants(ICmsContent node)
 {
     return((IEnumerable <ICmsContent>)EnumerableExtensions.WhereNotNull <ICmsContent>((IEnumerable <ICmsContent>)(node.NativeNodeObject as IContent).GetDescendants().Select <IContent, ICmsContent>(new Func <IContent, ICmsContent>(this.CmsEntityFactory.CreateCmsContent))));
 }
Exemplo n.º 5
0
 public VariantSeedingTask(DatabaseSize databaseSize, ICmsContent cmsContent) : base(databaseSize, cmsContent)
 {
     _cmsContent = cmsContent;
 }
Exemplo n.º 6
0
        private CmsSearchResultItem GetCmsSearchResultItem(ICmsContent node)
        {
            if (node.Id == null)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Node id is null, not recognized object for indexing. Skipping.", (Exception)null);
                return((CmsSearchResultItem)null);
            }
            object propertyValue1 = this.cmsIndexer.GetPropertyValue(node, "solisSearchNoIndex");

            if (propertyValue1 != null)
            {
                try
                {
                    if (Convert.ToBoolean(propertyValue1))
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "solisSearchNoIndex is true, removing it from index if exist and skips node.", (Exception)null);
                        this.DeleteFromIndex((object)node.Id);
                        return((CmsSearchResultItem)null);
                    }
                }
                catch (Exception ex)
                {
                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error checking if node should be indexed.", ex);
                }
            }
            DocType docType = CurrentConfiguration.DocTypes[node.ContentType];

            if (docType != null && docType.Exclude)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("DocType {0} is configured to be excluded from index, skipping", (object)node.ContentType), (Exception)null);
                return((CmsSearchResultItem)null);
            }
            if (docType == null)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Warn, string.Format("Cannot find any configuration for DocType {0}, loading default configuration", (object)node.ContentType), (Exception)null);
                docType = CurrentConfiguration.DocTypes["default"];
            }
            if (docType == null)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Warn, string.Format("Cannot find any configuration for DocType {0}, not even default backup configuration, cannot index content.", (object)node.ContentType), (Exception)null);
                return((CmsSearchResultItem)null);
            }
            CmsSearchResultItem searchResultItem = new CmsSearchResultItem()
            {
                Id           = node.Id,
                Name         = node.Name,
                LinkUrl      = this.cmsIndexer.GetContentUrl(node),
                Created      = node.CreateDate,
                StartPublish = node.StartPublish,
                LastModified = node.UpdateDate,
                EndPublish   = node.EndPublish,
                Breadcrumbs  = this.cmsIndexer.GetBreadcrumbs(node),
                Acl          = this.cmsIndexer.GetNodeAcl(node),
                Languages    = this.cmsIndexer.GetNodeLanguages(node),
                DocTypes     = this.cmsIndexer.GetContentTypes(node)
            };

            try
            {
                object propertyValue2 = this.cmsIndexer.GetPropertyValue(node, "solisSearchCustomUrl");
                if (propertyValue2 != null)
                {
                    if (!string.IsNullOrWhiteSpace(propertyValue2 as string))
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Found custom value for node url, inserting to index {0}", propertyValue2), (Exception)null);
                        searchResultItem.LinkUrl = propertyValue2.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error reading custom url", ex);
            }
            if (docType.AddPageNameToContent)
            {
                searchResultItem.Content.Add(node.Name);
            }
            foreach (Property property1 in docType.DocTypeProperties.Cast <Property>())
            {
                string       propertyName = property1.PropertyName;
                ICmsProperty property2    = this.cmsIndexer.GetProperty(node, propertyName);
                if (property2 == null)
                {
                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Property {0} not found on document, skipping", (object)propertyName), (Exception)null);
                }
                else
                {
                    IPropertyParser parser;
                    if (!string.IsNullOrEmpty(property1.Parser))
                    {
                        Type type = Type.GetType(property1.Parser);
                        if (type == (Type)null)
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, string.Format("Parser was configured as {0}, but parser type is not recognized, will use default parser.", (object)property1.Parser), (Exception)null);
                            parser = (IPropertyParser) new DefaultParser();
                        }
                        else
                        {
                            parser = Activator.CreateInstance(type) as IPropertyParser;
                        }
                    }
                    else
                    {
                        parser = (IPropertyParser) new DefaultParser();
                    }
                    parser.CurrentCmsNode       = node;
                    parser.CurrentCmsProperty   = property2;
                    parser.CurrentSolisProperty = property1;
                    string str1 = property2 != null?parser.GetPropertyValue(property2.Value) : string.Empty;

                    if (property1.Recursive && string.IsNullOrEmpty(str1))
                    {
                        str1 = this.GetRecursiveValue(node, propertyName, parser);
                    }
                    bool   forceMultiValued      = property1.ForceMultiValued;
                    string dynamicFieldExtension = FieldNameHelper.GetDynamicFieldExtension(property1);
                    if (!string.IsNullOrEmpty(str1))
                    {
                        if (property2 != null)
                        {
                            if (searchResultItem.Documents == null)
                            {
                                searchResultItem.Documents = this.ExtractDocumentLinks(str1, property2.Name);
                            }
                            else
                            {
                                searchResultItem.Documents.AddRange((IEnumerable <string>) this.ExtractDocumentLinks(str1, property2.Name));
                            }
                        }
                        if (property1.StripHtml)
                        {
                            str1 = str1.StripHtml();
                        }
                        if (property1.Content)
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Property is set as Content, adding content value from property {0} with value \"{1}\" to indexitem ", (object)propertyName, (object)str1), (Exception)null);
                            searchResultItem.Content.Add(str1);
                        }
                        string key = propertyName + dynamicFieldExtension;
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Adding property {0} with value \"{1}\" to indexitem ", (object)key, (object)str1), (Exception)null);
                        if (forceMultiValued)
                        {
                            char[] trimchars = new char[3]
                            {
                                ' ',
                                '\n',
                                '\r'
                            };
                            IEnumerable <string> strings = ((IEnumerable <string>)Array.ConvertAll <string, string>(str1.Split(new string[1]
                            {
                                property1.SplitChar
                            }, StringSplitOptions.RemoveEmptyEntries), (Converter <string, string>)(s => s.Trim(trimchars)))).AsEnumerable <string>();
                            searchResultItem.CmsProperties.Add(new KeyValuePair <string, object>(key, (object)strings));
                            if (property1.AlphabeticalIndex)
                            {
                                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Multivalued property is set for alphabetical index, adding first letters to alphaindex", (Exception)null);
                                foreach (string str2 in strings)
                                {
                                    string lower = str2.Substring(0, 1).ToLower();
                                    if (!searchResultItem.AlphaIndex.Contains(lower))
                                    {
                                        searchResultItem.AlphaIndex.Add(lower);
                                    }
                                }
                            }
                        }
                        else
                        {
                            searchResultItem.CmsProperties.Add(new KeyValuePair <string, object>(key, (object)str1));
                            if (property1.AlphabeticalIndex)
                            {
                                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Property is set for alphabetical index, adding first letter to alphaindex", (Exception)null);
                                string lower = str1.Substring(0, 1).ToLower();
                                if (!searchResultItem.AlphaIndex.Contains(lower))
                                {
                                    searchResultItem.AlphaIndex.Add(lower);
                                }
                            }
                        }
                    }
                }
            }
            return(searchResultItem);
        }